【问题标题】:EB Custom Platform without default VPC fails没有默认 VPC 的 EB 自定义平台失败
【发布时间】:2017-12-07 19:18:59
【问题描述】:

我正在构建一个自定义平台来运行我们的应用程序。我们删除了默认 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,但是打包程序没有考虑到这一点。 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 和子网。

【问题讨论】:

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


    【解决方案1】:

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

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

    【讨论】:

      【解决方案2】:

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

      Packer 失败并出现错误:'--> HVM AMI builder: VPCIdNotSpecified: No default VPC for this user status code: 400, request id: xyx-yxyx-xyx'

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

      ▸ vpc_id ▸ 子网_id

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2023-01-08
        • 2013-04-30
        • 2015-12-14
        • 2018-09-01
        • 2022-09-30
        • 2010-11-12
        • 2020-01-06
        • 2018-09-18
        相关资源
        最近更新 更多