Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion samtranslator/model/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class Resource(object):
property_types = None
_keywords = ['logical_id', 'relative_id', "depends_on", "resource_attributes"]

_supported_resource_attributes = ["DeletionPolicy", "UpdatePolicy"]
_supported_resource_attributes = ["DeletionPolicy", "UpdatePolicy", "Condition"]

# Runtime attributes that can be qureied resource. They are CloudFormation attributes like ARN, Name etc that
# will be resolvable at runtime. This map will be implemented by sub-classes to express list of attributes they
Expand Down
2 changes: 1 addition & 1 deletion samtranslator/model/sam_resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ def _construct_lambda_function(self):
:returns: a list containing the Lambda function and execution role resources
:rtype: list
"""
lambda_function = LambdaFunction(self.logical_id, depends_on=self.depends_on)
lambda_function = LambdaFunction(self.logical_id, depends_on=self.depends_on, attributes=self.resource_attributes)

if self.FunctionName:
lambda_function.FunctionName = self.FunctionName
Expand Down
8 changes: 8 additions & 0 deletions tests/translator/input/function_with_condition.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Resources:
ConditionFunction:
Type: 'AWS::Serverless::Function'
Condition: "this is a test"
Properties:
CodeUri: s3://sam-demo-bucket/hello.zip
Handler: hello.handler
Runtime: python2.7
52 changes: 52 additions & 0 deletions tests/translator/output/aws-cn/function_with_condition.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
{
"Resources": {
"ConditionFunction": {
"Type": "AWS::Lambda::Function",
"Condition": "this is a test",
"Properties": {
"Code": {
"S3Bucket": "sam-demo-bucket",
"S3Key": "hello.zip"
},
"Handler": "hello.handler",
"Role": {
"Fn::GetAtt": [
"ConditionFunctionRole",
"Arn"
]
},
"Runtime": "python2.7",
"Tags": [
{
"Value": "SAM",
"Key": "lambda:createdBy"
}
]
}
},
"ConditionFunctionRole": {
"Type": "AWS::IAM::Role",
"Properties": {
"ManagedPolicyArns": [
"arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole"
],
"AssumeRolePolicyDocument": {
"Version": "2012-10-17",
"Statement": [
{
"Action": [
"sts:AssumeRole"
],
"Effect": "Allow",
"Principal": {
"Service": [
"lambda.amazonaws.com"
]
}
}
]
}
}
}
}
}
52 changes: 52 additions & 0 deletions tests/translator/output/aws-us-gov/function_with_condition.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
{
"Resources": {
"ConditionFunction": {
"Type": "AWS::Lambda::Function",
"Condition": "this is a test",
"Properties": {
"Code": {
"S3Bucket": "sam-demo-bucket",
"S3Key": "hello.zip"
},
"Handler": "hello.handler",
"Role": {
"Fn::GetAtt": [
"ConditionFunctionRole",
"Arn"
]
},
"Runtime": "python2.7",
"Tags": [
{
"Value": "SAM",
"Key": "lambda:createdBy"
}
]
}
},
"ConditionFunctionRole": {
"Type": "AWS::IAM::Role",
"Properties": {
"ManagedPolicyArns": [
"arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole"
],
"AssumeRolePolicyDocument": {
"Version": "2012-10-17",
"Statement": [
{
"Action": [
"sts:AssumeRole"
],
"Effect": "Allow",
"Principal": {
"Service": [
"lambda.amazonaws.com"
]
}
}
]
}
}
}
}
}
52 changes: 52 additions & 0 deletions tests/translator/output/function_with_condition.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
{
"Resources": {
"ConditionFunction": {
"Type": "AWS::Lambda::Function",
"Condition": "this is a test",
"Properties": {
"Code": {
"S3Bucket": "sam-demo-bucket",
"S3Key": "hello.zip"
},
"Handler": "hello.handler",
"Role": {
"Fn::GetAtt": [
"ConditionFunctionRole",
"Arn"
]
},
"Runtime": "python2.7",
"Tags": [
{
"Value": "SAM",
"Key": "lambda:createdBy"
}
]
}
},
"ConditionFunctionRole": {
"Type": "AWS::IAM::Role",
"Properties": {
"ManagedPolicyArns": [
"arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole"
],
"AssumeRolePolicyDocument": {
"Version": "2012-10-17",
"Statement": [
{
"Action": [
"sts:AssumeRole"
],
"Effect": "Allow",
"Principal": {
"Service": [
"lambda.amazonaws.com"
]
}
}
]
}
}
}
}
}
1 change: 1 addition & 0 deletions tests/translator/test_translator.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ class TestTranslatorEndToEnd(TestCase):

@parameterized.expand(
itertools.product([
'function_with_condition',
'basic_function',
'cloudwatchevent',
'cloudwatch_logs_with_ref',
Expand Down