diff --git a/tests/translator/input/cloudwatchevent_intrinsics.yaml b/tests/translator/input/cloudwatchevent_intrinsics.yaml new file mode 100644 index 000000000..57d0c5893 --- /dev/null +++ b/tests/translator/input/cloudwatchevent_intrinsics.yaml @@ -0,0 +1,31 @@ +Parameters: + PathA: + Type: String + Default: "SomeInputPath" + PathB: + Type: String + Default: "AnotherInputPath" + +Conditions: + PathCondition: + Fn::Equals: + - true + - true + +Resources: + LambdaFunction: + Type: 'AWS::Serverless::Function' + Properties: + CodeUri: s3://sam-demo-bucket/hello.zip + Handler: hello.handler + Runtime: python2.7 + Events: + OnTerminate: + Type: CloudWatchEvent + Properties: + EventBusName: !Join [ "", [ "Event", "Bus", "Name" ] ] + Input: !Join [ ":", [ "{ Key", "Value }" ] ] + InputPath: !If [ PathCondition, !Ref PathA, !Ref PathB ] + Pattern: + detail: + state: !Split [ "," , "terminated,stopped" ] \ No newline at end of file diff --git a/tests/translator/output/aws-cn/cloudwatchevent_intrinsics.json b/tests/translator/output/aws-cn/cloudwatchevent_intrinsics.json new file mode 100644 index 000000000..d761fc5e0 --- /dev/null +++ b/tests/translator/output/aws-cn/cloudwatchevent_intrinsics.json @@ -0,0 +1,147 @@ +{ + "Parameters": { + "PathA": { + "Type": "String", + "Default": "SomeInputPath" + }, + "PathB": { + "Type": "String", + "Default": "AnotherInputPath" + } + }, + "Conditions": { + "PathCondition": { + "Fn::Equals": [ + true, + true + ] + } + }, + "Resources": { + "LambdaFunction": { + "Type": "AWS::Lambda::Function", + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" + }, + "Handler": "hello.handler", + "Role": { + "Fn::GetAtt": [ + "LambdaFunctionRole", + "Arn" + ] + }, + "Runtime": "python2.7", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + } + }, + "LambdaFunctionRole": { + "Type": "AWS::IAM::Role", + "Properties": { + "AssumeRolePolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ] + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + } + }, + "LambdaFunctionOnTerminate": { + "Type": "AWS::Events::Rule", + "Properties": { + "EventBusName": { + "Fn::Join": [ + "", + [ + "Event", + "Bus", + "Name" + ] + ] + }, + "EventPattern": { + "detail": { + "state": { + "Fn::Split": [ + ",", + "terminated,stopped" + ] + } + } + }, + "Targets": [ + { + "Arn": { + "Fn::GetAtt": [ + "LambdaFunction", + "Arn" + ] + }, + "Id": "LambdaFunctionOnTerminateLambdaTarget", + "Input": { + "Fn::Join": [ + ":", + [ + "{ Key", + "Value }" + ] + ] + }, + "InputPath": { + "Fn::If": [ + "PathCondition", + { + "Ref": "PathA" + }, + { + "Ref": "PathB" + } + ] + } + } + ] + } + }, + "LambdaFunctionOnTerminatePermission": { + "Type": "AWS::Lambda::Permission", + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "LambdaFunction" + }, + "Principal": "events.amazonaws.com", + "SourceArn": { + "Fn::GetAtt": [ + "LambdaFunctionOnTerminate", + "Arn" + ] + } + } + } + } +} \ No newline at end of file diff --git a/tests/translator/output/aws-us-gov/cloudwatchevent_intrinsics.json b/tests/translator/output/aws-us-gov/cloudwatchevent_intrinsics.json new file mode 100644 index 000000000..c8d97aea6 --- /dev/null +++ b/tests/translator/output/aws-us-gov/cloudwatchevent_intrinsics.json @@ -0,0 +1,147 @@ +{ + "Parameters": { + "PathA": { + "Type": "String", + "Default": "SomeInputPath" + }, + "PathB": { + "Type": "String", + "Default": "AnotherInputPath" + } + }, + "Conditions": { + "PathCondition": { + "Fn::Equals": [ + true, + true + ] + } + }, + "Resources": { + "LambdaFunction": { + "Type": "AWS::Lambda::Function", + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" + }, + "Handler": "hello.handler", + "Role": { + "Fn::GetAtt": [ + "LambdaFunctionRole", + "Arn" + ] + }, + "Runtime": "python2.7", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + } + }, + "LambdaFunctionRole": { + "Type": "AWS::IAM::Role", + "Properties": { + "AssumeRolePolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ] + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + } + }, + "LambdaFunctionOnTerminate": { + "Type": "AWS::Events::Rule", + "Properties": { + "EventBusName": { + "Fn::Join": [ + "", + [ + "Event", + "Bus", + "Name" + ] + ] + }, + "EventPattern": { + "detail": { + "state": { + "Fn::Split": [ + ",", + "terminated,stopped" + ] + } + } + }, + "Targets": [ + { + "Arn": { + "Fn::GetAtt": [ + "LambdaFunction", + "Arn" + ] + }, + "Id": "LambdaFunctionOnTerminateLambdaTarget", + "Input": { + "Fn::Join": [ + ":", + [ + "{ Key", + "Value }" + ] + ] + }, + "InputPath": { + "Fn::If": [ + "PathCondition", + { + "Ref": "PathA" + }, + { + "Ref": "PathB" + } + ] + } + } + ] + } + }, + "LambdaFunctionOnTerminatePermission": { + "Type": "AWS::Lambda::Permission", + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "LambdaFunction" + }, + "Principal": "events.amazonaws.com", + "SourceArn": { + "Fn::GetAtt": [ + "LambdaFunctionOnTerminate", + "Arn" + ] + } + } + } + } +} \ No newline at end of file diff --git a/tests/translator/output/cloudwatchevent_intrinsics.json b/tests/translator/output/cloudwatchevent_intrinsics.json new file mode 100644 index 000000000..1a12bb785 --- /dev/null +++ b/tests/translator/output/cloudwatchevent_intrinsics.json @@ -0,0 +1,147 @@ +{ + "Parameters": { + "PathA": { + "Type": "String", + "Default": "SomeInputPath" + }, + "PathB": { + "Type": "String", + "Default": "AnotherInputPath" + } + }, + "Conditions": { + "PathCondition": { + "Fn::Equals": [ + true, + true + ] + } + }, + "Resources": { + "LambdaFunction": { + "Type": "AWS::Lambda::Function", + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" + }, + "Handler": "hello.handler", + "Role": { + "Fn::GetAtt": [ + "LambdaFunctionRole", + "Arn" + ] + }, + "Runtime": "python2.7", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + } + }, + "LambdaFunctionRole": { + "Type": "AWS::IAM::Role", + "Properties": { + "AssumeRolePolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ] + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + } + }, + "LambdaFunctionOnTerminate": { + "Type": "AWS::Events::Rule", + "Properties": { + "EventBusName": { + "Fn::Join": [ + "", + [ + "Event", + "Bus", + "Name" + ] + ] + }, + "EventPattern": { + "detail": { + "state": { + "Fn::Split": [ + ",", + "terminated,stopped" + ] + } + } + }, + "Targets": [ + { + "Arn": { + "Fn::GetAtt": [ + "LambdaFunction", + "Arn" + ] + }, + "Id": "LambdaFunctionOnTerminateLambdaTarget", + "Input": { + "Fn::Join": [ + ":", + [ + "{ Key", + "Value }" + ] + ] + }, + "InputPath": { + "Fn::If": [ + "PathCondition", + { + "Ref": "PathA" + }, + { + "Ref": "PathB" + } + ] + } + } + ] + } + }, + "LambdaFunctionOnTerminatePermission": { + "Type": "AWS::Lambda::Permission", + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "LambdaFunction" + }, + "Principal": "events.amazonaws.com", + "SourceArn": { + "Fn::GetAtt": [ + "LambdaFunctionOnTerminate", + "Arn" + ] + } + } + } + } +} \ No newline at end of file diff --git a/tests/translator/test_translator.py b/tests/translator/test_translator.py index e22bff999..0db19f45a 100644 --- a/tests/translator/test_translator.py +++ b/tests/translator/test_translator.py @@ -267,6 +267,7 @@ class TestTranslatorEndToEnd(AbstractTestTranslator): "application_with_intrinsics", "basic_layer", "cloudwatchevent", + "cloudwatchevent_intrinsics", "eventbridgerule", "eventbridgerule_with_dlq", "eventbridgerule_with_retry_policy",