amazon-web-services - 如何在 cloudformation 模板中获取 docker 主机的实例 ID
问题描述
我有一个使用模板创建的简单 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 的方法。
解决方案
推荐阅读
- c# - 有没有办法更好地优化 ProgressBars 的 WPF 逻辑
- angular - 使用 Angular 8 将下拉列表值和文本字段值添加到动态
- c++ - R CMD CHECK 与 BH 相关的警告
- javascript - 单击输入框时,我需要显示我的段落。我的 p 数组如何不循环通过我的段落变量?
- facebook-graph-api - 如果用户使用 facebook SDK 共享按钮成功共享帖子,则执行任务
- python - 导入 tflearn - 没有名为“tensorflow.contrib.framework”的模块
- ruby - 什么是 Liquid Exception '证书验证失败'?
- visual-studio-code - VS Code 的设置 css.lint.hexColorLength 何时触发?
- node.js - 连接来自服务器的拒绝响应时出错
- jenkins - 通过 Jenkins 运行 Appium 代码时出错,但在本地运行良好