I recently completed work on an AWS Serverless Application Model (SAM) application that runs in Lambda and stores data in DynamoDB. I also wanted to tag resources created by SAM with metadata required by the application. Fortunately, SAM provides a
Global block that includes a parameter for
Tags. Tag information is supplied using a map of strings.
Below is an example of using global tags in a SAM template:
AWSTemplateFormatVersion: "2010-09-09" Transform: AWS::Serverless-2016-10-31 Description: "Gets data from the xxxxx API." Globals: Function: Timeout: 3 Tags: InterestingTag1: "Interesting Answer 1" InterestingTag2: "Interesting Answer 2" InterestingTag3: "Interesting Answer 3" InterestingTag4: "Interesting Answer 4"
In most situations, using a global tag parameter results in supplying tag metadata to all resources deployed by SAM. However, I noticed that the deployment process was not tagging the DynamoDB table, although the deployment process encountered no errors.
I’m guessing this behavior is caused by DynamoDB requiring a list of key-value pairs. Providing tags directly to the resource works.
MyTable: Type: AWS::DynamoDB::Table Description: "Stores the data." Properties: <---snip---> Tags: - Value: "Interesting Tag 1" Key: "InterestingTag1" - Value: "Interesting Tag 2" Key: "InterestingTag2" - Value: "Interesting Tag 3" Key: "InterestingTag3" - Value: "Interesting Tag 4" Key: "InterestingTag4"
I suppose this is just a quirk to using SAM as an abstraction layer and one that I’d probably forget if it wasn’t documented here.