I am trying to create an AWS stack in CloudFormation having a secret in the JSON.
I don't want the value of the secret displayed in the parameters and I don't want my instance (fargate or ec2) to access the secrets manager. I want CloudFormation to retrieve the value from the secrets manager and inject it in the template during runtime.
This is what I did:
Create a secret
Create a template using Designer
Read the secret and create a resource. In this case I am creating a bucket that has as a tag the secret. I know this is not secure, but the bucket is being used just as a proof of concept.
Validate that the bucket contains a tag with the secret
This is my template:
{
"AWSTemplateFormatVersion": "2010-09-09",
"Description": "create a single S3 bucket",
"Resources": {
"SampleBucket": {
"Type": "AWS::S3::Bucket",
"Properties": {
"BucketName": "asantostestbucket",
"Tags" : [
{
"Key" : "keyname",
"Value" : "{{resolve:secretsmanager:dev/learning:SecretString:hello}}"
}
]
}
}
}
}
Which is giving me the error One or more tags are not valid
.
How can I indicate to CloudFormation that I want it to read the secret, instead of trying to read the tag as text? In other words, replace "{{resolve:secretsmanager:dev/learning:SecretString:hello}}" with the value, instead of reading it as a text.