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"]} } } }

gefragt vor 5 Monaten224 Aufrufe
1 Antwort
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
beantwortet vor 4 Monaten

Du bist nicht angemeldet. Anmelden um eine Antwort zu veröffentlichen.

Eine gute Antwort beantwortet die Frage klar, gibt konstruktives Feedback und fördert die berufliche Weiterentwicklung des Fragenstellers.

Richtlinien für die Beantwortung von Fragen