我使用打包程序自定义了一个镜像,我可以从该镜像 ID 启动一个实例。如果我按原样使用该图像 ID,那么我可以部署一个小堆栈。那里没有问题。但我不断根据反馈旋转新图像,因此新图像具有新图像 ID。有没有一种方法可以过滤新的图像 ID 并使用我在 cloudformation 堆栈中使用 Packer 构建的最新图像 ID?我查看了其他帖子,但我的问题略有不同,因为我正在构建当我使用“我拥有”而不是来自市场进行过滤时显示在 AMI 中的图像。任何建议/帮助将不胜感激。
WIN-APP-01
Type: AWS::EC2::Instance
Properties:
AvailabilityZone: !Ref WinAvailabilityZone
EbsOptimized: True
IamInstanceProfile: !Ref WinInstanceProfile
ImageId: ???
InstanceType: T2.Micro
UserData:
'Fn::Base64': !Sub |
#!/bin/bash
yum install -y httpd
最佳答案
你可以写一个CloudFormation Custom Resource由 AWS Lambda 函数提供支持,该函数可以:
- 使用
owner=self
调用DescribeImages()
- 过滤出感兴趣的图像(例如通过描述中的内容)
- 按日期排序
- 返回最新的 AMI
这类似于:Walkthrough: Looking Up Amazon Machine Image IDs - AWS CloudFormation
该演练旨在帮助人们使用最新的 Windows 或 Amazon Linux AMI。此方法现已被 using the Parameter Store 取代检索 AMI。但是,此方法仅使用 AWS 提供的预编码 AMI。
关于amazon-web-services - 过滤要在 cloudformation 中使用的自定义实例 ID (AMI),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56554039/