Skip to content

Commit dc9a3b7

Browse files
Jaccojlhood
authored andcommitted
feat: Add Condition support to new LayerVersion and Application for aws#142 (aws#707)
1 parent b96e40d commit dc9a3b7

File tree

9 files changed

+120
-6
lines changed

9 files changed

+120
-6
lines changed

samtranslator/model/sam_resources.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -566,7 +566,7 @@ def to_cloudformation(self, **kwargs):
566566
def _construct_nested_stack(self):
567567
"""Constructs a AWS::CloudFormation::Stack resource
568568
"""
569-
nested_stack = NestedStack(self.logical_id, depends_on=self.depends_on)
569+
nested_stack = NestedStack(self.logical_id, depends_on=self.depends_on, attributes=self.get_passthrough_resource_attributes())
570570
nested_stack.Parameters = self.Parameters
571571
nested_stack.NotificationArns = self.NotificationArns
572572
application_tags = self._get_application_tags()
@@ -631,15 +631,16 @@ def _construct_lambda_layer(self, intrinsics_resolver):
631631
"""
632632
retention_policy_value = self._get_retention_policy_value(intrinsics_resolver)
633633

634-
retention_policy = {
635-
'DeletionPolicy': retention_policy_value
636-
}
634+
attributes = self.get_passthrough_resource_attributes()
635+
if attributes is None:
636+
attributes = {}
637+
attributes['DeletionPolicy'] = retention_policy_value
637638

638639
old_logical_id = self.logical_id
639640
new_logical_id = logical_id_generator.LogicalIdGenerator(old_logical_id, self.to_dict()).gen()
640641
self.logical_id = new_logical_id
641642

642-
lambda_layer = LambdaLayerVersion(self.logical_id, depends_on=self.depends_on, attributes=retention_policy)
643+
lambda_layer = LambdaLayerVersion(self.logical_id, depends_on=self.depends_on, attributes=attributes)
643644

644645
# Changing the LayerName property: when a layer is published, it is given an Arn
645646
# example: arn:aws:lambda:us-west-2:123456789012:layer:MyLayer:1

tests/translator/input/basic_application.yaml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,12 @@ Resources:
2525
Properties:
2626
Location: https://s3-us-east-1.amazonaws.com/demo-bucket/template.yaml
2727
Tags:
28-
TagName2: TagValue2
28+
TagName2: TagValue2
29+
30+
ApplicationWithCondition:
31+
Type: 'AWS::Serverless::Application'
32+
Condition: "this is a test"
33+
Properties:
34+
Location:
35+
ApplicationId: arn:aws:serverlessrepo:us-east-1:123456789012:applications/hello-world
36+
SemanticVersion: 1.0.2

tests/translator/input/basic_layer.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,9 @@ Resources:
2424
- python2.7
2525
LicenseInfo: "License information"
2626
RetentionPolicy: Retain
27+
28+
LayerWithCondition:
29+
Type: 'AWS::Serverless::LayerVersion'
30+
Condition: "this is a test"
31+
Properties:
32+
ContentUri: s3://sam-demo-bucket/layer.zip

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,27 @@
6868
}
6969
]
7070
}
71+
},
72+
"ApplicationWithCondition": {
73+
"Type": "AWS::CloudFormation::Stack",
74+
"Properties": {
75+
"TemplateURL": "https://awsserverlessrepo-changesets-xxx.s3.amazonaws.com/signed-url",
76+
"Tags": [
77+
{
78+
"Value": "SAM",
79+
"Key": "lambda:createdBy"
80+
},
81+
{
82+
"Value": "arn:aws:serverlessrepo:us-east-1:123456789012:applications/hello-world",
83+
"Key": "serverlessrepo:applicationId"
84+
},
85+
{
86+
"Value": "1.0.2",
87+
"Key": "serverlessrepo:semanticVersion"
88+
}
89+
]
90+
},
91+
"Condition": "this is a test"
7192
}
7293
}
7394
}

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,18 @@
3939
"S3ObjectVersion": 1
4040
}
4141
}
42+
},
43+
"LayerWithCondition93cfa80b64": {
44+
"DeletionPolicy": "Retain",
45+
"Type": "AWS::Lambda::LayerVersion",
46+
"Properties": {
47+
"Content": {
48+
"S3Bucket": "sam-demo-bucket",
49+
"S3Key": "layer.zip"
50+
},
51+
"LayerName": "LayerWithCondition"
52+
},
53+
"Condition": "this is a test"
4254
}
4355
}
4456
}

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,27 @@
6868
}
6969
]
7070
}
71+
},
72+
"ApplicationWithCondition": {
73+
"Type": "AWS::CloudFormation::Stack",
74+
"Properties": {
75+
"TemplateURL": "https://awsserverlessrepo-changesets-xxx.s3.amazonaws.com/signed-url",
76+
"Tags": [
77+
{
78+
"Value": "SAM",
79+
"Key": "lambda:createdBy"
80+
},
81+
{
82+
"Value": "arn:aws:serverlessrepo:us-east-1:123456789012:applications/hello-world",
83+
"Key": "serverlessrepo:applicationId"
84+
},
85+
{
86+
"Value": "1.0.2",
87+
"Key": "serverlessrepo:semanticVersion"
88+
}
89+
]
90+
},
91+
"Condition": "this is a test"
7192
}
7293
}
7394
}

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,18 @@
3939
"S3ObjectVersion": 1
4040
}
4141
}
42+
},
43+
"LayerWithCondition93cfa80b64": {
44+
"DeletionPolicy": "Retain",
45+
"Type": "AWS::Lambda::LayerVersion",
46+
"Properties": {
47+
"Content": {
48+
"S3Bucket": "sam-demo-bucket",
49+
"S3Key": "layer.zip"
50+
},
51+
"LayerName": "LayerWithCondition"
52+
},
53+
"Condition": "this is a test"
4254
}
4355
}
4456
}

tests/translator/output/basic_application.json

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,27 @@
6868
}
6969
]
7070
}
71+
},
72+
"ApplicationWithCondition": {
73+
"Type": "AWS::CloudFormation::Stack",
74+
"Properties": {
75+
"TemplateURL": "https://awsserverlessrepo-changesets-xxx.s3.amazonaws.com/signed-url",
76+
"Tags": [
77+
{
78+
"Value": "SAM",
79+
"Key": "lambda:createdBy"
80+
},
81+
{
82+
"Value": "arn:aws:serverlessrepo:us-east-1:123456789012:applications/hello-world",
83+
"Key": "serverlessrepo:applicationId"
84+
},
85+
{
86+
"Value": "1.0.2",
87+
"Key": "serverlessrepo:semanticVersion"
88+
}
89+
]
90+
},
91+
"Condition": "this is a test"
7192
}
7293
}
7394
}

tests/translator/output/basic_layer.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,18 @@
3939
"S3ObjectVersion": 1
4040
}
4141
}
42+
},
43+
"LayerWithCondition93cfa80b64": {
44+
"DeletionPolicy": "Retain",
45+
"Type": "AWS::Lambda::LayerVersion",
46+
"Properties": {
47+
"Content": {
48+
"S3Bucket": "sam-demo-bucket",
49+
"S3Key": "layer.zip"
50+
},
51+
"LayerName": "LayerWithCondition"
52+
},
53+
"Condition": "this is a test"
4254
}
4355
}
4456
}

0 commit comments

Comments
 (0)