如何在cloudformation模板中获取docker主机的实例ID

时间:2019-03-20 09:41:53

标签: amazon-web-services amazon-cloudformation

我有一个使用模板创建的简单CloudFormation堆栈。托管一个Docker容器的服务器。

这是创建主机和容器的模板的一部分:

  ContainerHostInstances:
    Type: "AWS::AutoScaling::LaunchConfiguration"
    DependsOn: "AttachGateway"
    Properties:
      AssociatePublicIpAddress: true
      ImageId: "ami-0302f3ec240b9d23c"
      SecurityGroups:
        - Ref: "NginxSecurityGroup"
      InstanceType: "t3.nano"
      IamInstanceProfile: !Ref "ECSHostEC2InstanceProfile"
      KeyName: "test-key-pair"
      UserData:
        Fn::Base64: !Sub |
          #!/bin/bash -xe
          echo ECS_CLUSTER=${MyCluster} >> /etc/ecs/ecs.config
          yum install -y aws-cfn-bootstrap
          /opt/aws/bin/cfn-signal -e $? --stack ${AWS::StackName} --resource ECSAutoScalingGroup --region ${AWS::Region}

...

  MyTask:
    Type: "AWS::ECS::TaskDefinition"
    Properties:
      Family: "my-task-family"
      ContainerDefinitions:
        - Name: "nginx"
          Essential: true
          Image: "image_url/nginx:latest"
          MemoryReservation: 300
          LogConfiguration:
            LogDriver: "awslogs"
            Options:
              awslogs-group: "nginx"
              awslogs-region: !Ref "AWS::Region"
              awslogs-stream-prefix: "prefix"
              awslogs-datetime-format: "%Y-%m-%d %H:%M:%S.%L"
          PortMappings:
            - ContainerPort: 80
              HostPort: 80

我的问题是我无法在模板中关联弹性IP地址。我可以使用控制台来做到这一点,但如果可能的话,我希望将其包含在模板中。

我尝试过这种方式:

  ElasticIPAssoc:
    Type: AWS::EC2::EIPAssociation
    Properties:
      AllocationId: "some_id"
      InstanceId: "HOW CAN I GET THIS VALUE"
      NetworkInterfaceId: "OR THAT VALUE"

我看不到获取instanceId或其对应的NetworkInterfaceId的方法。

0 个答案:

没有答案