没有默认VPC的EB Custom Platform失败

时间:2017-12-07 19:19:00

标签: amazon-web-services amazon-elastic-beanstalk

我正在建立一个自定义平台来运行我们的应用程序。我们删除了默认的VPC,因此根据文档我必须在几乎所有地方指定VPC和子网ID。所以我为ebp运行的命令如下所示:

ebp create -v --vpc.id vpc-xxxxxxx --vpc.subnets subnet-xxxxxx --vpc.publicip{code}

以上旋转了pcakcer环境没有任何问题,但是当打包器开始构建实例时,我收到以下错误:

2017-12-07 18:07:05 UTC+0100    ERROR   [Instance: i-00f376be9fc2fea34] Command failed on instance. Return code: 1 Output: 'packer build' failed, the build log has been saved to '/var/log/packer-builder/XXX1.0.19-builder.log'. Hook /opt/elasticbeanstalk/hooks/packerbuild/build.rb failed. For more detail, check /var/log/eb-activity.log using console or EB CLI.
2017-12-07 18:06:55 UTC+0100    ERROR   'packer build' failed, the build log has been saved to '/var/log/packer-builder/XXX:1.0.19-builder.log'
2017-12-07 18:06:55 UTC+0100    ERROR   Packer failed with error: '--> HVM AMI builder: VPCIdNotSpecified: No default VPC for this user status code: 400, request id: 28d94e8c-e24d-440f-9c64-88826e042e9d'{code}

模板和platform.yaml都指定了vpc_id和子网ID,但是packer不会考虑这一点。 platform.yaml

version: "1.0"

provisioner:
  type: packer
  template: tomcat_platform.json
  flavor: ubuntu1604

metadata:
  maintainer: <Enter your contact details here>
  description: Ubuntu running Tomcat
  operating_system_name: Ubuntu Server
  operating_system_version: 16.04 LTS
  programming_language_name: Java
  programming_language_version: 8
  framework_name: Tomcat
  framework_version: 7
  app_server_name: "none"
  app_server_version: "none"

option_definitions:
  - namespace: "aws:elasticbeanstalk:container:custom:application"
    option_name: "TOMCAT_START"
    description: "Default application startup command"
    default_value: ""

option_settings:
  - namespace: "aws:ec2:vpc"
    option_name: "VPCId"
    value: "vpc-xxxxxxx"
  - namespace: "aws:ec2:vpc"
    option_name: "Subnets"
    value: "subnet-xxxxxxx"
  - namespace: "aws:elb:listener:80"
    option_name: "InstancePort"
    value: "8080"
  - namespace: "aws:elasticbeanstalk:application"
    option_name: "Application Healthcheck URL"
    value: "TCP:8080"

tomcat_platform.json

{
  "variables": {
    "platform_name": "{{env `AWS_EB_PLATFORM_NAME`}}",
    "platform_version": "{{env `AWS_EB_PLATFORM_VERSION`}}",
    "platform_arn": "{{env `AWS_EB_PLATFORM_ARN`}}"

  },
  "builders": [
    {
      "type": "amazon-ebs",
      "region": "eu-west-1",
      "source_ami": "ami-8fd760f6",
      "instance_type": "t2.micro",
      "ami_virtualization_type": "hvm",
      "ssh_username": "admin",
      "ami_name": "Tomcat running on Ubuntu Server 16.04 LTS (built on {{isotime \"20060102150405\"}})",
      "ami_description": "Tomcat running on Ubuntu Server 16.04 LTS (built on {{isotime \"20060102150405\"}})",
      "vpc_id": "vpc-xxxxxx",
      "subnet_id": "subnet-xxxxxx",
      "associate_public_ip_address": "true",
      "tags": {
        "eb_platform_name": "{{user `platform_name`}}",
        "eb_platform_version": "{{user `platform_version`}}",
        "eb_platform_arn": "{{user `platform_arn`}}"
      }
    }
  ],
  "provisioners": [
    {
      "type": "file",
      "source": "builder",
      "destination": "/tmp/"
    },
    {
      "type": "shell",
      "execute_command": "chmod +x {{ .Path }}; {{ .Vars }} sudo {{ .Path     }}",
      "scripts": [
        "builder/builder.sh"
      ]
    }
  ]
}

欣赏如何使这项工作符合预期的任何想法。我发现了Packer的几个问题,但似乎已经解决了,所以文档只是说模板必须指定目标VPC和子网。

2 个答案:

答案 0 :(得分:0)

在这种情况下,AWS文档有点误导。您需要默认的VPC才能创建自定义平台。从我所看到的,这是因为您传递给ebp create命令的VPC标志不会传递给实际构建平台的打包程序进程。

要解决此错误,您只需创建一个刚用于自定义平台创建的新默认VPC。

答案 1 :(得分:0)

Packer在创建构建自定义平台所需的资源(包括启动EC2实例,创建安全组等)时会查找默认VPC(Packer的默认行为)。但是,如果默认VPC不存在于其中,区域(例如,如果已删除),则Packer Build Task将失败,并显示以下错误:

打包器失败,错误:'-> HVM AMI构建器:VPCIdNotSpecified:此用户状态码:400,请求ID:xyx-yxyx-xyx没有默认VPC'

要解决此错误,请在“ template.json”文件的“ builders”部分中使用以下attributes,以便打包程序在创建资源时使用自定义VPC和子网:

▸vpc_id ▸subnet_id