Adding tags in CFT

0

I am trying to add tags by passing all the tags in key value pair from the parameters. But I am not able to do so because of this error.

Properties validation failed for resource bucket with message: #/Tags: expected type: JSONArray, found: String

Here is my template: { "AWSTemplateFormatVersion": "2010-09-09", "Description": "The template for S3 bucket", "Parameters": { "s3BucketName": { "Type": "String", "Default": "test-bucket" }, "projectName": { "Type": "String", "Default": "test" }, "tag": { "Type": "String", "Default": "[{"Key":"project","Value":"test"},{"Key":"owner","Value":"test"}]" }

}, "Resources": { "bucket": { "Type": "AWS::S3::Bucket", "Properties": { "BucketName": {"Ref": "s3BucketName"}, "PublicAccessBlockConfiguration": { "BlockPublicAcls": false, "BlockPublicPolicy": false, "IgnorePublicAcls": false, "RestrictPublicBuckets": false }, "Tags": {"Fn::Sub": "${tag}"}

  }
}

}, "Outputs": { "arn": { "Description": "The Arn of the S3 bucket.", "Value": {"Fn::GetAtt": ["bucket", "Arn"]} } } }

asked 4 months ago215 views
1 Answer
0

CloudFormation supports adding resource tags directly to the resources that support tagging, for example;

    "Resources": {
        "bucket": {
            "Type": "AWS::S3::Bucket",
            "Properties": {
                "BucketName": {
                    "Ref": "s3BucketName"
                },
                "PublicAccessBlockConfiguration": {
                    "BlockPublicAcls": false,
                    "BlockPublicPolicy": false,
                    "IgnorePublicAcls": false,
                    "RestrictPublicBuckets": false
                },
                "Tags": [
                    {
                        "Key": "keyname1",
                        "Value": "value1"
                    },
                    {
                        "Key": "keyname2",
                        "Value": "value2"
                    }
                ]
            }
        }
    },

CloudFormation does not support adding Tags as a Parameter value within the stack. The following is the list of supported Types. Tags are required to be a List hence the error message returned requesting a JSONArray rather a String. However, CloudFormation currently only supports a List<number> type.

AWS
answered 3 months ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions