首页 > 解决方案 > 如何修复与 AWS::CloudFormation::Init 一起创建 EC2 的 cloudformation 模板

问题描述

我正在使用 cloudformation 模板部署堆栈,该模板使用 cloud-init 部分创建 EC2。当我部署它时,我收到以下错误消息:

The following resource(s) failed to create: [EC2Instance]. . The requested configuration is currently not supported. Please check the documentation for supported configurations.

如果我删除“元数据”部分,一切正常并创建一个 EC2。元数据部分可能配置错误,我无法弄清楚是什么。

我将此文档用作参考-> https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-init.html

AWSTemplateFormatVersion: 2010-09-09
Resources:
  EC2Instance:
    Type: 'AWS::EC2::Instance'
    Metadata: 
      AWS::CloudFormation::Init: 
        configSets: 
          config: 
            - "config1"
            - "config2"
        config1: 
          commands: 
            test: 
              command: "echo \"hello from config 1\" > test.txt"
        config2: 
          commands: 
            test: 
              command: "echo \"hello from config 2\" > test.txt"
    Properties:
      InstanceType: "t2.small"
      ImageId: "ami-06b382aba6c5a4f2c"
      SecurityGroupIds:
        - "sg-123456"
      SubnetId: "subnet-123456"
      KeyName: "my-example-key"

我希望创建 EC2 实例,但我收到以下错误消息:

The requested configuration is currently not supported. Please check the documentation for supported configurations. (Service: AmazonEC2; Status Code: 400; Error Code: Unsupported; Request ID: --Redacted--)

标签: amazon-web-servicesamazon-ec2amazon-cloudformation

解决方案


这里使用的 AMI 是 ami-06b382aba6c5a4f2c,用于 64 位 Arm。实例类型族为 t2。ami-06b382aba6c5a4f2c 支持的实例系列是 a1。

如果您想使用 AMZ linux 2,请使用为 64 位 (x86) 架构构建的 AMI ami-0de53d8956e8dcf80。

简而言之,将 ImageId 更改为 'ami-0de53d8956e8dcf80'

希望这可以帮助..


推荐阅读