1

I'm trying to create a SecurityGroup which has a tag like Name: SG-StackName. This code works perfect in json:

"Resources": {
    "SecurityGroup": {
        "Type": "AWS::EC2::SecurityGroup",
        "Properties": {
            ...
            "Tags": [{
                    "Key": "Name",
                    "Value": {
                        "Fn::Join" : [ "", [
                            "SG-",
                            {   "Ref" : "AWS::StackName"    }
                        ]]
                    }
                }
            ]
        }
    },

Now I'm trying to convert it to yaml:

Resources: 
  SecurityGroup: 
    Type: AWS::EC2::SecurityGroup
    Properties: 
      ...
      Tags: 
        - Key: Name
        - Value: !Join
          - ''
          - - 'SG-'
            - Ref: AWS::StackName

The stack build fails with error "Key not found in Tags property". Where is the error in the template?

Putnik
  • 2,217
  • 4
  • 27
  • 43

1 Answers1

5

You have an extra '-' character in the Tags definition. It should look something like the snippet below (I'm not sure of the Join syntax, personally I use Sub normally):

Tags: 
    - Key: Name
      Value: !Sub "SG-${AWS::StackName}"
David Hutchison
  • 238
  • 1
  • 2
  • 7