使用Packer.io创建基本AWS AMI时遇到问题.SSH超时

Saq*_*Ali 15 packer amazon-web-services

我正在尝试按照这些说明使用Packer.io构建基本的AWS镜像.但这对我不起作用.

这是我的模板文件:

{
  "variables": {
    "aws_access_key": "",
    "aws_secret_key": ""
  },
  "builders": [{
    "type": "amazon-ebs",
    "access_key": "{{user `aws_access_key`}}",
    "secret_key": "{{user `aws_secret_key`}}",
    "region": "us-east-1",
    "source_ami": "ami-146e2a7c",
    "instance_type": "t2.micro",
    "ssh_username": "ubuntu",
    "ami_name": "packer-example {{timestamp}}",

    # The following 2 lines don't appear in the tutorial.
    # But I had to add them because it said this source AMI
    # must be launched inside a VPC.
    "vpc_id": "vpc-98765432",
    "subnet_id": "subnet-12345678"
  }]
}
Run Code Online (Sandbox Code Playgroud)

您会注意到我必须通过在底部添加两条线(对于VPC和子网)来偏离指令.这是因为我不断收到以下错误:

==> amazon-ebs: Error launching source instance: The specified instance type 
                can only be used in a VPC. A subnet ID or network interface
                ID is required to carry out the request. 
                (VPCResourceNotSpecified)
Run Code Online (Sandbox Code Playgroud)

VPC和Subnet是我手动创建的临时版本.但我为什么要这样做呢?为什么打包器不创建那些然后删除它们就像我看到它创建一个临时安全组和密钥对?

此外,即使在我添加这两行之后,它也无法创建AMI,因为它会获得SSH超时.为什么?我在手动SSH连接到此VPC中的其他实例时没有遇到任何问题.临时封隔器实例有InstanceState=Running,StatusChecks=2/2和SecurityGroup允许SSH来自世界各地.

请参阅下面的packer命令的debug输出:

$ packer build -debug -var 'aws_access_key=MY_ACCESS_KEY' -var 'aws_secret_key=MY_SECRET_KEY' packer_config_basic.json
Debug mode enabled. Builds will not be parallelized.
amazon-ebs output will be in this color.

==> amazon-ebs: Inspecting the source AMI...
==> amazon-ebs: Pausing after run of step 'StepSourceAMIInfo'. Press enter to continue.
==> amazon-ebs: Creating temporary keypair: packer 99999999-8888-7777-6666-555555555555
    amazon-ebs: Saving key for debug purposes: ec2_amazon-ebs.pem
==> amazon-ebs: Pausing after run of step 'StepKeyPair'. Press enter to continue.
==> amazon-ebs: Creating temporary security group for this instance...
==> amazon-ebs: Authorizing SSH access on the temporary security group...
==> amazon-ebs: Pausing after run of step 'StepSecurityGroup'. Press enter to continue.
==> amazon-ebs: Launching a source AWS instance...
    amazon-ebs: Instance ID: i-12345678
==> amazon-ebs: Waiting for instance (i-12345678) to become ready...
    amazon-ebs: Private IP: 10.0.2.204
==> amazon-ebs: Pausing after run of step 'StepRunSourceInstance'. Press enter to continue.
==> amazon-ebs: Waiting for SSH to become available...
==> amazon-ebs: Timeout waiting for SSH.
==> amazon-ebs: Pausing before cleanup of step 'StepRunSourceInstance'. Press enter to continue.
==> amazon-ebs: Terminating the source AWS instance...
==> amazon-ebs: Pausing before cleanup of step 'StepSecurityGroup'. Press enter to continue.
==> amazon-ebs: Deleting temporary security group...
==> amazon-ebs: Pausing before cleanup of step 'StepKeyPair'. Press enter to continue.
==> amazon-ebs: Deleting temporary keypair...
==> amazon-ebs: Pausing before cleanup of step 'StepSourceAMIInfo'. Press enter to continue.
Build 'amazon-ebs' errored: Timeout waiting for SSH.

==> Some builds didn't complete successfully and had errors:
--> amazon-ebs: Timeout waiting for SSH.

==> Builds finished but no artifacts were created.
Run Code Online (Sandbox Code Playgroud)

num*_*er5 30

  1. 您正在使用t2.micro实例类型,该实例类型只能在VPC环境中运行(请参阅T2实例).

  2. 由于您使用的是VPC,因此默认情况下所有流量都位于防火墙之后,因此您需要设置安全组以允许您的IP访问该实例上的SSH端口.

更简单的方法是使用m3.medium实例类型,有点贵,但它可以更快地运行所有内容,而您根本不需要设置VPC /安全组.

  • SaqibAli为什么不给@ number5接受的答案? (9认同)
  • 回复:`t2.micro`,为什么打包机会在他们的网站上发布一个非工作教程?我将`t2.micro`改为`m3.medium`.它迫使我输入`ssh_username`.我把它放进了'ubuntu`.现在这是我之后得到的错误:https://gist.github.com/anonymous/125cf22597cce8a73d5b (3认同)
  • @SaqibAli模板中的AMI(ami-146e2a7c)适用于Amazon Linux,默认用户为ec2-user (3认同)