Skip to content

Commit

Permalink
tests: Adding intrinsic tests for Function S3 Event
Browse files Browse the repository at this point in the history
  • Loading branch information
mgrandis committed Jul 19, 2021
1 parent f313094 commit f1c85c9
Show file tree
Hide file tree
Showing 5 changed files with 431 additions and 0 deletions.
40 changes: 40 additions & 0 deletions tests/translator/input/s3_intrinsics.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
Parameters:
EventsParam:
Type: String
Default: s3:ObjectCreated:*

Conditions:
MyCondition:
Fn::Equals:
- true
- false

Resources:
ThumbnailFunction:
Type: AWS::Serverless::Function
Properties:
CodeUri: s3://sam-demo-bucket/thumbnails.zip
Handler: index.generate_thumbails
Runtime: nodejs12.x
Events:
ImageBucket:
Type: S3
Properties:
Bucket:
Ref: Images
Events:
- s3:ObjectCreated:*
Filter:
Fn::If:
- MyCondition
- S3Key:
Rules:
- Name: Rule1Prefix
Value: Rule1Value
- S3Key:
Rules:
- Name: Rule2Prefix
Value: Rule2Value

Images:
Type: AWS::S3::Bucket
130 changes: 130 additions & 0 deletions tests/translator/output/aws-cn/s3_intrinsics.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
{
"Conditions": {
"MyCondition": {
"Fn::Equals": [
true,
false
]
}
},
"Parameters": {
"EventsParam": {
"Default": "s3:ObjectCreated:*",
"Type": "String"
}
},
"Resources": {
"Images": {
"Type": "AWS::S3::Bucket",
"Properties": {
"NotificationConfiguration": {
"LambdaConfigurations": [
{
"Function": {
"Fn::GetAtt": [
"ThumbnailFunction",
"Arn"
]
},
"Filter": {
"Fn::If": [
"MyCondition",
{
"S3Key": {
"Rules": [
{
"Name": "Rule1Prefix",
"Value": "Rule1Value"
}
]
}
},
{
"S3Key": {
"Rules": [
{
"Name": "Rule2Prefix",
"Value": "Rule2Value"
}
]
}
}
]
},
"Event": "s3:ObjectCreated:*"
}
]
}
},
"DependsOn": [
"ThumbnailFunctionImageBucketPermission"
]
},
"ThumbnailFunctionRole": {
"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": [
{
"Value": "SAM",
"Key": "lambda:createdBy"
}
]
}
},
"ThumbnailFunctionImageBucketPermission": {
"Type": "AWS::Lambda::Permission",
"Properties": {
"Action": "lambda:InvokeFunction",
"SourceAccount": {
"Ref": "AWS::AccountId"
},
"FunctionName": {
"Ref": "ThumbnailFunction"
},
"Principal": "s3.amazonaws.com"
}
},
"ThumbnailFunction": {
"Type": "AWS::Lambda::Function",
"Properties": {
"Handler": "index.generate_thumbails",
"Code": {
"S3Bucket": "sam-demo-bucket",
"S3Key": "thumbnails.zip"
},
"Role": {
"Fn::GetAtt": [
"ThumbnailFunctionRole",
"Arn"
]
},
"Runtime": "nodejs12.x",
"Tags": [
{
"Value": "SAM",
"Key": "lambda:createdBy"
}
]
}
}
}
}
130 changes: 130 additions & 0 deletions tests/translator/output/aws-us-gov/s3_intrinsics.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
{
"Conditions": {
"MyCondition": {
"Fn::Equals": [
true,
false
]
}
},
"Parameters": {
"EventsParam": {
"Default": "s3:ObjectCreated:*",
"Type": "String"
}
},
"Resources": {
"Images": {
"Type": "AWS::S3::Bucket",
"Properties": {
"NotificationConfiguration": {
"LambdaConfigurations": [
{
"Function": {
"Fn::GetAtt": [
"ThumbnailFunction",
"Arn"
]
},
"Filter": {
"Fn::If": [
"MyCondition",
{
"S3Key": {
"Rules": [
{
"Name": "Rule1Prefix",
"Value": "Rule1Value"
}
]
}
},
{
"S3Key": {
"Rules": [
{
"Name": "Rule2Prefix",
"Value": "Rule2Value"
}
]
}
}
]
},
"Event": "s3:ObjectCreated:*"
}
]
}
},
"DependsOn": [
"ThumbnailFunctionImageBucketPermission"
]
},
"ThumbnailFunctionRole": {
"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": [
{
"Value": "SAM",
"Key": "lambda:createdBy"
}
]
}
},
"ThumbnailFunctionImageBucketPermission": {
"Type": "AWS::Lambda::Permission",
"Properties": {
"Action": "lambda:InvokeFunction",
"SourceAccount": {
"Ref": "AWS::AccountId"
},
"FunctionName": {
"Ref": "ThumbnailFunction"
},
"Principal": "s3.amazonaws.com"
}
},
"ThumbnailFunction": {
"Type": "AWS::Lambda::Function",
"Properties": {
"Handler": "index.generate_thumbails",
"Code": {
"S3Bucket": "sam-demo-bucket",
"S3Key": "thumbnails.zip"
},
"Role": {
"Fn::GetAtt": [
"ThumbnailFunctionRole",
"Arn"
]
},
"Runtime": "nodejs12.x",
"Tags": [
{
"Value": "SAM",
"Key": "lambda:createdBy"
}
]
}
}
}
}
Loading

0 comments on commit f1c85c9

Please sign in to comment.