Skip to content

Commit bcd8238

Browse files
author
Connor Robertson
authored
fix: Tags with value of False got evaluated to "" (#3429)
1 parent 09a17d5 commit bcd8238

13 files changed

+839
-1
lines changed

samtranslator/model/tags/resource_tagging.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def get_tag_list(resource_tag_dict: Optional[Dict[str, Any]]) -> List[Dict[str,
3030
return tag_list
3131

3232
for tag_key, tag_value in resource_tag_dict.items():
33-
tag = {_KEY: tag_key, _VALUE: tag_value if tag_value else ""}
33+
tag = {_KEY: tag_key, _VALUE: tag_value if (tag_value is not None) else ""}
3434
tag_list.append(tag)
3535

3636
return tag_list
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
Globals:
2+
Function:
3+
Tags:
4+
TagKey1: TagValue1
5+
TagKey2: ''
6+
TagKey3: false
7+
TagKey4: true
8+
TagKey5: 0
9+
10+
Resources:
11+
MyLambdaFunction:
12+
Type: AWS::Serverless::Function
13+
Properties:
14+
Handler: index.handler
15+
Runtime: nodejs18.x
16+
InlineCode: |
17+
exports.handler = async (event, context, callback) => {
18+
return {
19+
statusCode: 200,
20+
body: 'Success'
21+
}
22+
}
23+
MemorySize: 128
24+
Policies:
25+
- AWSLambdaRole
26+
- AmazonS3ReadOnlyAccess
27+
Metadata:
28+
SamTransformTest: true
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
Resources:
2+
MyLambdaFunction:
3+
Type: AWS::Serverless::Function
4+
Properties:
5+
Handler: index.handler
6+
Runtime: nodejs18.x
7+
InlineCode: |
8+
exports.handler = async (event, context, callback) => {
9+
return {
10+
statusCode: 200,
11+
body: 'Success'
12+
}
13+
}
14+
MemorySize: 128
15+
Policies:
16+
- AWSLambdaRole
17+
- AmazonS3ReadOnlyAccess
18+
Tags:
19+
TagKey1: TagValue1
20+
TagKey2: ''
21+
TagKey3: false
22+
TagKey4: true
23+
Metadata:
24+
SamTransformTest: true
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
Parameters:
2+
TagValueParam:
3+
Type: String
4+
Default: value
5+
6+
Resources:
7+
MinimalTableWithTags:
8+
Type: AWS::Serverless::SimpleTable
9+
Properties:
10+
Tags:
11+
TagKey1: TagValue1
12+
TagKey2: ''
13+
TagKey3:
14+
Ref: TagValueParam
15+
TagKey4: '123'
16+
TagKey5: true
17+
TagKey6: false
18+
TagKey7: 0
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
{
2+
"Metadata": {
3+
"SamTransformTest": true
4+
},
5+
"Resources": {
6+
"MyLambdaFunction": {
7+
"Properties": {
8+
"Code": {
9+
"ZipFile": "exports.handler = async (event, context, callback) => {\n return {\n statusCode: 200,\n body: 'Success'\n }\n}\n"
10+
},
11+
"Handler": "index.handler",
12+
"MemorySize": 128,
13+
"Role": {
14+
"Fn::GetAtt": [
15+
"MyLambdaFunctionRole",
16+
"Arn"
17+
]
18+
},
19+
"Runtime": "nodejs18.x",
20+
"Tags": [
21+
{
22+
"Key": "lambda:createdBy",
23+
"Value": "SAM"
24+
},
25+
{
26+
"Key": "TagKey1",
27+
"Value": "TagValue1"
28+
},
29+
{
30+
"Key": "TagKey2",
31+
"Value": ""
32+
},
33+
{
34+
"Key": "TagKey3",
35+
"Value": false
36+
},
37+
{
38+
"Key": "TagKey4",
39+
"Value": true
40+
},
41+
{
42+
"Key": "TagKey5",
43+
"Value": 0
44+
}
45+
]
46+
},
47+
"Type": "AWS::Lambda::Function"
48+
},
49+
"MyLambdaFunctionRole": {
50+
"Properties": {
51+
"AssumeRolePolicyDocument": {
52+
"Statement": [
53+
{
54+
"Action": [
55+
"sts:AssumeRole"
56+
],
57+
"Effect": "Allow",
58+
"Principal": {
59+
"Service": [
60+
"lambda.amazonaws.com"
61+
]
62+
}
63+
}
64+
],
65+
"Version": "2012-10-17"
66+
},
67+
"ManagedPolicyArns": [
68+
"arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole",
69+
"arn:aws-cn:iam::aws:policy/service-role/AWSLambdaRole",
70+
"arn:aws-cn:iam::aws:policy/AmazonS3ReadOnlyAccess"
71+
],
72+
"Tags": [
73+
{
74+
"Key": "lambda:createdBy",
75+
"Value": "SAM"
76+
},
77+
{
78+
"Key": "TagKey1",
79+
"Value": "TagValue1"
80+
},
81+
{
82+
"Key": "TagKey2",
83+
"Value": ""
84+
},
85+
{
86+
"Key": "TagKey3",
87+
"Value": false
88+
},
89+
{
90+
"Key": "TagKey4",
91+
"Value": true
92+
},
93+
{
94+
"Key": "TagKey5",
95+
"Value": 0
96+
}
97+
]
98+
},
99+
"Type": "AWS::IAM::Role"
100+
}
101+
}
102+
}
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
{
2+
"Metadata": {
3+
"SamTransformTest": true
4+
},
5+
"Resources": {
6+
"MyLambdaFunction": {
7+
"Properties": {
8+
"Code": {
9+
"ZipFile": "exports.handler = async (event, context, callback) => {\n return {\n statusCode: 200,\n body: 'Success'\n }\n}\n"
10+
},
11+
"Handler": "index.handler",
12+
"MemorySize": 128,
13+
"Role": {
14+
"Fn::GetAtt": [
15+
"MyLambdaFunctionRole",
16+
"Arn"
17+
]
18+
},
19+
"Runtime": "nodejs18.x",
20+
"Tags": [
21+
{
22+
"Key": "lambda:createdBy",
23+
"Value": "SAM"
24+
},
25+
{
26+
"Key": "TagKey1",
27+
"Value": "TagValue1"
28+
},
29+
{
30+
"Key": "TagKey2",
31+
"Value": ""
32+
},
33+
{
34+
"Key": "TagKey3",
35+
"Value": false
36+
},
37+
{
38+
"Key": "TagKey4",
39+
"Value": true
40+
}
41+
]
42+
},
43+
"Type": "AWS::Lambda::Function"
44+
},
45+
"MyLambdaFunctionRole": {
46+
"Properties": {
47+
"AssumeRolePolicyDocument": {
48+
"Statement": [
49+
{
50+
"Action": [
51+
"sts:AssumeRole"
52+
],
53+
"Effect": "Allow",
54+
"Principal": {
55+
"Service": [
56+
"lambda.amazonaws.com"
57+
]
58+
}
59+
}
60+
],
61+
"Version": "2012-10-17"
62+
},
63+
"ManagedPolicyArns": [
64+
"arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole",
65+
"arn:aws-cn:iam::aws:policy/service-role/AWSLambdaRole",
66+
"arn:aws-cn:iam::aws:policy/AmazonS3ReadOnlyAccess"
67+
],
68+
"Tags": [
69+
{
70+
"Key": "lambda:createdBy",
71+
"Value": "SAM"
72+
},
73+
{
74+
"Key": "TagKey1",
75+
"Value": "TagValue1"
76+
},
77+
{
78+
"Key": "TagKey2",
79+
"Value": ""
80+
},
81+
{
82+
"Key": "TagKey3",
83+
"Value": false
84+
},
85+
{
86+
"Key": "TagKey4",
87+
"Value": true
88+
}
89+
]
90+
},
91+
"Type": "AWS::IAM::Role"
92+
}
93+
}
94+
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
{
2+
"Parameters": {
3+
"TagValueParam": {
4+
"Default": "value",
5+
"Type": "String"
6+
}
7+
},
8+
"Resources": {
9+
"MinimalTableWithTags": {
10+
"Properties": {
11+
"AttributeDefinitions": [
12+
{
13+
"AttributeName": "id",
14+
"AttributeType": "S"
15+
}
16+
],
17+
"BillingMode": "PAY_PER_REQUEST",
18+
"KeySchema": [
19+
{
20+
"AttributeName": "id",
21+
"KeyType": "HASH"
22+
}
23+
],
24+
"Tags": [
25+
{
26+
"Key": "TagKey1",
27+
"Value": "TagValue1"
28+
},
29+
{
30+
"Key": "TagKey2",
31+
"Value": ""
32+
},
33+
{
34+
"Key": "TagKey3",
35+
"Value": {
36+
"Ref": "TagValueParam"
37+
}
38+
},
39+
{
40+
"Key": "TagKey4",
41+
"Value": "123"
42+
},
43+
{
44+
"Key": "TagKey5",
45+
"Value": true
46+
},
47+
{
48+
"Key": "TagKey6",
49+
"Value": false
50+
},
51+
{
52+
"Key": "TagKey7",
53+
"Value": 0
54+
}
55+
]
56+
},
57+
"Type": "AWS::DynamoDB::Table"
58+
}
59+
}
60+
}

0 commit comments

Comments
 (0)