CloudFormation 堆栈 yaml 语法?

Put*_*nik 1 syntax amazon-web-services amazon-cloudformation yaml

我正在尝试创建一个 SecurityGroup,它的标签类似于Name: SG-StackName. 此代码在 json 中完美运行:

"Resources": {
    "SecurityGroup": {
        "Type": "AWS::EC2::SecurityGroup",
        "Properties": {
            ...
            "Tags": [{
                    "Key": "Name",
                    "Value": {
                        "Fn::Join" : [ "", [
                            "SG-",
                            {   "Ref" : "AWS::StackName"    }
                        ]]
                    }
                }
            ]
        }
    },
Run Code Online (Sandbox Code Playgroud)

现在我正在尝试将其转换为 yaml:

Resources: 
  SecurityGroup: 
    Type: AWS::EC2::SecurityGroup
    Properties: 
      ...
      Tags: 
        - Key: Name
        - Value: !Join
          - ''
          - - 'SG-'
            - Ref: AWS::StackName
Run Code Online (Sandbox Code Playgroud)

堆栈构建失败并显示错误“在标签属性中找不到密钥”。模板中的错误在哪里?

小智 5

标签定义中有一个额外的“-”字符。它应该类似于下面的代码片段(我不确定 Join 语法,我个人通常使用 Sub):

Tags: 
    - Key: Name
      Value: !Sub "SG-${AWS::StackName}"
Run Code Online (Sandbox Code Playgroud)