Skip to content

Commit 281bd2d

Browse files
committed
fix: fix make_conditional and bucket tagging
1 parent f3c4f96 commit 281bd2d

File tree

7 files changed

+22
-40
lines changed

7 files changed

+22
-40
lines changed

samtranslator/model/eventsources/push.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ def _depend_on_lambda_permissions_using_tag(self, bucket, permission):
269269
270270
See https://stackoverflow.com/questions/34607476/cloudformation-apply-condition-on-dependson
271271
272-
It is done by using Fn:GetAtt wrapped in a conditional Fn:If. Using Fn:GetAtt implies a
272+
It is done by using Ref wrapped in a conditional Fn::If. Using Ref implies a
273273
dependency, so CloudFormation will automatically wait once it reaches that function, the same
274274
as if you were using a DependsOn.
275275
"""
@@ -283,9 +283,9 @@ def _depend_on_lambda_permissions_using_tag(self, bucket, permission):
283283
properties['Tags'] = tags
284284
dep_tag = {
285285
'sam:ConditionalDependsOn:' + permission.logical_id: {
286-
'Fn:If': [
286+
'Fn::If': [
287287
permission.resource_attributes['Condition'],
288-
fnGetAtt(permission.logical_id, 'Arn'),
288+
ref(permission.logical_id),
289289
'no dependency'
290290
]
291291
}
@@ -311,7 +311,7 @@ def _inject_notification_configuration(self, function, bucket):
311311
lambda_event = copy.deepcopy(base_event_mapping)
312312
lambda_event['Event'] = event_type
313313
if 'Condition' in function.resource_attributes:
314-
lambda_event = make_conditional(lambda_event, function.resource_attributes['Condition'])
314+
lambda_event = make_conditional(function.resource_attributes['Condition'], lambda_event)
315315
event_mappings.append(lambda_event)
316316

317317
properties = bucket.get('Properties', None)

tests/translator/output/aws-cn/function_event_conditions.json

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -368,13 +368,13 @@
368368
"LambdaConfigurations": [
369369
{
370370
"Fn::If": [
371+
"MyCondition",
371372
{
372373
"Function": {
373374
"Ref": "MyAwesomeFunctionAliasLive"
374375
},
375376
"Event": "s3:ObjectCreated:*"
376377
},
377-
"MyCondition",
378378
{
379379
"Ref": "AWS::NoValue"
380380
}
@@ -395,13 +395,10 @@
395395
{
396396
"Key": "sam:ConditionalDependsOn:MyAwesomeFunctionS3TriggerPermission",
397397
"Value": {
398-
"Fn:If": [
398+
"Fn::If": [
399399
"MyCondition",
400400
{
401-
"Fn::GetAtt": [
402-
"MyAwesomeFunctionS3TriggerPermission",
403-
"Arn"
404-
]
401+
"Ref": "MyAwesomeFunctionS3TriggerPermission"
405402
},
406403
"no dependency"
407404
]

tests/translator/output/aws-cn/s3_with_condition.json

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"LambdaConfigurations": [
88
{
99
"Fn::If": [
10+
"MyCondition",
1011
{
1112
"Function": {
1213
"Fn::GetAtt": [
@@ -16,7 +17,6 @@
1617
},
1718
"Event": "s3:ObjectCreated:*"
1819
},
19-
"MyCondition",
2020
{
2121
"Ref": "AWS::NoValue"
2222
}
@@ -27,13 +27,10 @@
2727
"Tags": [
2828
{
2929
"Value": {
30-
"Fn:If": [
30+
"Fn::If": [
3131
"MyCondition",
3232
{
33-
"Fn::GetAtt": [
34-
"ThumbnailFunctionImageBucketPermission",
35-
"Arn"
36-
]
33+
"Ref": "ThumbnailFunctionImageBucketPermission"
3734
},
3835
"no dependency"
3936
]

tests/translator/output/aws-us-gov/function_event_conditions.json

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -368,13 +368,13 @@
368368
"LambdaConfigurations": [
369369
{
370370
"Fn::If": [
371+
"MyCondition",
371372
{
372373
"Function": {
373374
"Ref": "MyAwesomeFunctionAliasLive"
374375
},
375376
"Event": "s3:ObjectCreated:*"
376377
},
377-
"MyCondition",
378378
{
379379
"Ref": "AWS::NoValue"
380380
}
@@ -395,13 +395,10 @@
395395
{
396396
"Key": "sam:ConditionalDependsOn:MyAwesomeFunctionS3TriggerPermission",
397397
"Value": {
398-
"Fn:If": [
398+
"Fn::If": [
399399
"MyCondition",
400400
{
401-
"Fn::GetAtt": [
402-
"MyAwesomeFunctionS3TriggerPermission",
403-
"Arn"
404-
]
401+
"Ref": "MyAwesomeFunctionS3TriggerPermission"
405402
},
406403
"no dependency"
407404
]

tests/translator/output/aws-us-gov/s3_with_condition.json

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"LambdaConfigurations": [
88
{
99
"Fn::If": [
10+
"MyCondition",
1011
{
1112
"Function": {
1213
"Fn::GetAtt": [
@@ -16,7 +17,6 @@
1617
},
1718
"Event": "s3:ObjectCreated:*"
1819
},
19-
"MyCondition",
2020
{
2121
"Ref": "AWS::NoValue"
2222
}
@@ -27,13 +27,10 @@
2727
"Tags": [
2828
{
2929
"Value": {
30-
"Fn:If": [
30+
"Fn::If": [
3131
"MyCondition",
3232
{
33-
"Fn::GetAtt": [
34-
"ThumbnailFunctionImageBucketPermission",
35-
"Arn"
36-
]
33+
"Ref": "ThumbnailFunctionImageBucketPermission"
3734
},
3835
"no dependency"
3936
]

tests/translator/output/function_event_conditions.json

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -368,13 +368,13 @@
368368
"LambdaConfigurations": [
369369
{
370370
"Fn::If": [
371+
"MyCondition",
371372
{
372373
"Function": {
373374
"Ref": "MyAwesomeFunctionAliasLive"
374375
},
375376
"Event": "s3:ObjectCreated:*"
376377
},
377-
"MyCondition",
378378
{
379379
"Ref": "AWS::NoValue"
380380
}
@@ -395,13 +395,10 @@
395395
{
396396
"Key": "sam:ConditionalDependsOn:MyAwesomeFunctionS3TriggerPermission",
397397
"Value": {
398-
"Fn:If": [
398+
"Fn::If": [
399399
"MyCondition",
400400
{
401-
"Fn::GetAtt": [
402-
"MyAwesomeFunctionS3TriggerPermission",
403-
"Arn"
404-
]
401+
"Ref": "MyAwesomeFunctionS3TriggerPermission"
405402
},
406403
"no dependency"
407404
]

tests/translator/output/s3_with_condition.json

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"LambdaConfigurations": [
88
{
99
"Fn::If": [
10+
"MyCondition",
1011
{
1112
"Function": {
1213
"Fn::GetAtt": [
@@ -16,7 +17,6 @@
1617
},
1718
"Event": "s3:ObjectCreated:*"
1819
},
19-
"MyCondition",
2020
{
2121
"Ref": "AWS::NoValue"
2222
}
@@ -27,13 +27,10 @@
2727
"Tags": [
2828
{
2929
"Value": {
30-
"Fn:If": [
30+
"Fn::If": [
3131
"MyCondition",
3232
{
33-
"Fn::GetAtt": [
34-
"ThumbnailFunctionImageBucketPermission",
35-
"Arn"
36-
]
33+
"Ref": "ThumbnailFunctionImageBucketPermission"
3734
},
3835
"no dependency"
3936
]

0 commit comments

Comments
 (0)