amazon-web-services - 过滤要在 cloudformation 中使用的自定义实例 ID (AMI)

标签 amazon-web-services amazon-ec2 aws-cloudformation

我使用打包程序自定义了一个镜像,我可以从该镜像 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/

相关文章:

amazon-web-services - 如何将路由表链接到Azure Bicep中的子网?给出的代码示例

amazon-web-services - 如何使用适用于 Golang 的 AWS 开发工具包清空 S3 存储桶?

amazon-web-services - CodePipeline CloudFormation 资源依赖于资源创建的导出变量

java - 无法从外部浏览器连接到 EC2 Web 应用程序

ubuntu - 巨巨 : error: error parsing environment "amazon": no public ssh keys found

amazon-web-services - 云形成: Assign Elastic IP to Auto Scaling group with one instance

amazon-web-services - AWS CloudFormation 堆栈陷入 UPDATE_ROLLBACK_IN_PROGRESS 状态

python - AWS : Running scheduled Python code to update a static S3 page

javascript - 我在哪里定义要开始的实例 ID?

amazon-web-services - 为什么 Cloudformation 堆栈变更集包含删除 SAM 管道的删除操作?