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

我试图做一个打包者的形象,但在我们的亚马逊帐户,我们没有默认的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. 

因此,我应该指定一个默认的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" }], } 

打包器上的文档只是说vpc_id(string) – 如果启动到VPC子网中,Packer需要VPC ID才能在VPC中创build一个临时安全组。

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

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

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

添加:

  "associate_public_ip_address": "true", "ami_virtualization_type": "hvm", 

清单为我工作。 这是一个示例文件:

 { "variables": { "aws_access_key": "", "aws_secret_key": "" }, "builders": [{ "type": "amazon-ebs", "access_key": "{{user `aws_access_key`}}", "secret_key": "{{user `aws_secret_key`}}", "region": "eu-west-1", "source_ami": "ami-47a23a30", "instance_type": "t2.micro", "associate_public_ip_address": "true", "ami_virtualization_type": "hvm", "ssh_username": "ubuntu", "ami_name": "packer-exaple {{timestamp}}", "ami_description": "An example deployment built with Packer.io", "vpc_id": "vpc-XXXXX", "subnet_id": "subnet-XXXXX", "tags": {"Environment": "test", "name": "packer.io test"} }] }