不支持 SSM 安全参考:AWS::EC2::Instance/Metadata

SSM Secure reference is not supported in: AWS::EC2::Instance/Metadata

我试图在云形成模板的元数据部分使用 SecureString,但它引发了以下错误:

SSM Secure reference is not supported in: [AWS::EC2::Instance/Metadata/AWS::CloudFormation::Init/config/files/~/.ssh/content]

这是我的代码:

Resources:
  LinuxEC2Instance:
  Type: AWS::EC2::Instance
    Metadata:
      AWS::CloudFormation::Init:
      config:
        files:
          ~/.ssh: 
            content: !Sub |
              '{{resolve:ssm-secure:/credentials/ansible:1}}'
            mode: "000644"
            owner: "ansible"
            group: "ansible"

为什么这不起作用?我希望安全字符串引用在 Cloud Formation 模板中起作用?

Why does this not work?

它不起作用,因为 ssm-secure 不支持 AWS::EC2::Instance。支持的资源列表是 here,其中包括:

AWS::DirectoryService::MicrosoftAD
AWS::DirectoryService::SimpleAD
AWS::ElastiCache::ReplicationGroup
AWS::IAM::User
AWS::KinesisFirehose::DeliveryStream
AWS::OpsWorks::App
AWS::OpsWorks::Stack
AWS::OpsWorks::Stack
AWS::RDS::DBCluster
AWS::RDS::DBInstance
AWS::Redshift::Cluster