Packer 无法将 aws 映像打包到 VPC 中

Dar*_*l B 5 amazon-web-services packer

我正在尝试制作打包机映像,但在我们的亚马逊帐户中,我们没有默认 VPC。它已被移除。并且在尝试打包图像时出现此错误:

==> amazon-instance: Inspecting the source AMI...
==> amazon-instance: Creating temporary keypair: packer 54cfd9c9-61ef-5f8f-4091-d27e731a8a4d
==> amazon-instance: Creating temporary security group for this instance...
==> amazon-instance: No default VPC for this user (VPCIdNotSpecified)
==> amazon-instance: Deleting temporary keypair...
Build 'amazon-instance' finished.
Run Code Online (Sandbox Code Playgroud)

因此我应该指定一个默认的 VPC id 或子网 id。

我两个都试过了

{
  "variables": {
    "vpc_id ": "vpc-962438f4",
    "subnet_id": "subnet-1c5d5c68"
    },
  "builders": [{
    "type": "amazon-instance",
    "access_key": "somekey"
    "secret_key": "somekey"
    "account_id": "AccountIDNUMBER"
    "region": "ap-southeast-2",
    "source_ami": "ami-b7eb9e8d",
    "s3_bucket": "layer2amis",
    "x509_cert_path": "packer/cert-x509.pem",
    "x509_key_path": "packer/key-x509.pem",
    "instance_type": "t2.medium",
    "ssh_username": "ubuntu",
    "ssh_timeout": "5m",
    "ami_virtualization_type": "hvm",
    "ami_name": "layer2_stagingserver_{{timestamp}}",
    "bundle_vol_command": "sudo -n /usr/local/ec2/ec2-ami-tools-1.5.3/bin/ec2-bundle-vol -k {{.KeyPath}} -u {{.AccountId}} -c {{.CertPath}} -r {{.Architecture}} -e {{.PrivatePath}}/* -d {{.Destination}} -p {{.Prefix}} --batch --no-filter",
    "bundle_upload_command": "sudo -n /usr/local/ec2/ec2-ami-tools-1.5.3/bin/ec2-upload-bundle -b {{.BucketName}} -m {{.ManifestPath}} -a {{.AccessKey}} -s {{.SecretKey}} -d {{.BundleDirectory}} --region ap-southeast-2 --batch --retry"
  }],
}
Run Code Online (Sandbox Code Playgroud)

Packer 的 web 文档只是说 vpc_id (string) - 如果启动到 VPC 子网,Packer 需要 VPC ID 以便在 VPC 内创建临时安全组。

Baz*_*zze 6

正如您所说,在 amazon-ebs buildervpc_id文档中指出了一个选项。您已将此选项添加到您的 Packer JSON 文件中,但是,您将其添加到了错误的位置。

vpc_id选项应该添加到您的构建器对象中,而不是添加到变量对象中。所以它应该看起来像这样:

{
    "variables": {},
    "builders": [{
        "vpc_id": "vpc-12345678",
        "subnet_id": "subnet-1c5d5c68",
        "type": "amazon-instance",
        "access_key": "somekey",
        "secret_key": "somekey",
        "account_id": "AccountIDNUMBER",

        [...]
    }],
}
Run Code Online (Sandbox Code Playgroud)