-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: event source filtering (#2241)
* feat: add support for event filtering (DDB, Kinesis, SQS) (#90) * Add support for Event Filtering (DDB, Kinesis, SQS) * PR feedback Rename test file. Move to a variable the list of event types that have event filtering. * chore: change a test case that CFN doesn't support (#98) Co-authored-by: Renato Valenzuela <37676028+valerena@users.noreply.github.com>
- Loading branch information
Showing
14 changed files
with
598 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
Resources: | ||
WrongFilterName: | ||
Type: AWS::Serverless::Function | ||
Properties: | ||
CodeUri: s3://sam-demo-bucket/filtered_events.zip | ||
Handler: index.handler | ||
Runtime: nodejs16.x | ||
Events: | ||
DynamoDBStreamEvent: | ||
Type: DynamoDB | ||
Properties: | ||
Stream: !GetAtt DynamoDBTable.StreamArn | ||
StartingPosition: TRIM_HORIZON | ||
FilterCriteria: | ||
FiltersToUse: | ||
- Pattern: '{"name": "value"}' | ||
|
||
NotSupportedPullEvent: | ||
Type: AWS::Serverless::Function | ||
Properties: | ||
CodeUri: s3://sam-demo-bucket/filtered_events.zip | ||
Handler: index.handler | ||
Runtime: nodejs16.x | ||
Events: | ||
KafkaEvent: | ||
Type: MSK | ||
Properties: | ||
StartingPosition: LATEST | ||
Stream: arn:aws:kafka:us-east-1:012345678012:cluster/clusterName/abcdefab-1234-abcd-5678-cdef0123ab01-2 | ||
Topics: | ||
- MyTopic | ||
FilterCriteria: | ||
Filters: | ||
- Pattern: '{"name": "value"}' | ||
|
||
|
||
NotSupportedPushEvent: | ||
Type: AWS::Serverless::Function | ||
Properties: | ||
CodeUri: s3://sam-demo-bucket/filtered_events.zip | ||
Handler: index.handler | ||
Runtime: nodejs16.x | ||
Events: | ||
SNSEvent: | ||
Type: SNS | ||
Properties: | ||
Topic: !GetAtt MySnsTopic.Arn | ||
FilterCriteria: | ||
Filters: | ||
- Pattern: '{"name": "value"}' | ||
|
||
DynamoDBTable: | ||
Type: AWS::DynamoDB::Table | ||
|
||
MySnsTopic: | ||
Type: AWS::SNS::Topic |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
Resources: | ||
FilteredEventsFunction: | ||
Type: AWS::Serverless::Function | ||
Properties: | ||
CodeUri: s3://sam-demo-bucket/filtered_events.zip | ||
Handler: index.handler | ||
Runtime: nodejs16.x | ||
Events: | ||
KinesisStream: | ||
Type: Kinesis | ||
Properties: | ||
Stream: !GetAtt KinesisStream.Arn | ||
StartingPosition: LATEST | ||
FilterCriteria: | ||
Filters: | ||
- Pattern: '{"name": "value"}' | ||
- Pattern: '{"name2": "value2"}' | ||
DynamoDBStreamEvent: | ||
Type: DynamoDB | ||
Properties: | ||
Stream: !GetAtt DynamoDBTable.StreamArn | ||
StartingPosition: TRIM_HORIZON | ||
FilterCriteria: | ||
Filters: | ||
- Pattern: '{ | ||
"dynamodb": { | ||
"NewImage": { | ||
"value": { "S": ["test"] } | ||
} | ||
} | ||
}' | ||
MySqsQueue: | ||
Type: SQS | ||
Properties: | ||
Queue: !GetAtt MySqsQueue.Arn | ||
FilterCriteria: | ||
Filters: | ||
- Pattern: '{"name": "value"}' | ||
|
||
KinesisStream: | ||
Type: AWS::Kinesis::Stream | ||
Properties: | ||
ShardCount: 1 | ||
|
||
DynamoDBTable: | ||
Type: AWS::DynamoDB::Table | ||
|
||
MySqsQueue: | ||
Type: AWS::SQS::Queue |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
140 changes: 140 additions & 0 deletions
140
tests/translator/output/aws-cn/function_with_event_filtering.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
{ | ||
"Resources": { | ||
"KinesisStream": { | ||
"Type": "AWS::Kinesis::Stream", | ||
"Properties": { | ||
"ShardCount": 1 | ||
} | ||
}, | ||
"DynamoDBTable": { | ||
"Type": "AWS::DynamoDB::Table" | ||
}, | ||
"MySqsQueue": { | ||
"Type": "AWS::SQS::Queue" | ||
}, | ||
"FilteredEventsFunction": { | ||
"Type": "AWS::Lambda::Function", | ||
"Properties": { | ||
"Code": { | ||
"S3Bucket": "sam-demo-bucket", | ||
"S3Key": "filtered_events.zip" | ||
}, | ||
"Handler": "index.handler", | ||
"Role": { | ||
"Fn::GetAtt": [ | ||
"FilteredEventsFunctionRole", | ||
"Arn" | ||
] | ||
}, | ||
"Runtime": "nodejs16.x", | ||
"Tags": [ | ||
{ | ||
"Key": "lambda:createdBy", | ||
"Value": "SAM" | ||
} | ||
] | ||
} | ||
}, | ||
"FilteredEventsFunctionRole": { | ||
"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", | ||
"arn:aws-cn:iam::aws:policy/service-role/AWSLambdaDynamoDBExecutionRole", | ||
"arn:aws-cn:iam::aws:policy/service-role/AWSLambdaKinesisExecutionRole", | ||
"arn:aws-cn:iam::aws:policy/service-role/AWSLambdaSQSQueueExecutionRole" | ||
], | ||
"Tags": [ | ||
{ | ||
"Key": "lambda:createdBy", | ||
"Value": "SAM" | ||
} | ||
] | ||
} | ||
}, | ||
"FilteredEventsFunctionDynamoDBStreamEvent": { | ||
"Type": "AWS::Lambda::EventSourceMapping", | ||
"Properties": { | ||
"EventSourceArn": { | ||
"Fn::GetAtt": [ | ||
"DynamoDBTable", | ||
"StreamArn" | ||
] | ||
}, | ||
"FunctionName": { | ||
"Ref": "FilteredEventsFunction" | ||
}, | ||
"StartingPosition": "TRIM_HORIZON", | ||
"FilterCriteria": { | ||
"Filters": [ | ||
{ | ||
"Pattern": "{ \"dynamodb\": { \"NewImage\": { \"value\": { \"S\": [\"test\"] } } } }" | ||
} | ||
] | ||
} | ||
} | ||
}, | ||
"FilteredEventsFunctionKinesisStream": { | ||
"Type": "AWS::Lambda::EventSourceMapping", | ||
"Properties": { | ||
"EventSourceArn": { | ||
"Fn::GetAtt": [ | ||
"KinesisStream", | ||
"Arn" | ||
] | ||
}, | ||
"FunctionName": { | ||
"Ref": "FilteredEventsFunction" | ||
}, | ||
"StartingPosition": "LATEST", | ||
"FilterCriteria": { | ||
"Filters": [ | ||
{ | ||
"Pattern": "{\"name\": \"value\"}" | ||
}, | ||
{ | ||
"Pattern": "{\"name2\": \"value2\"}" | ||
} | ||
] | ||
} | ||
} | ||
}, | ||
"FilteredEventsFunctionMySqsQueue": { | ||
"Type": "AWS::Lambda::EventSourceMapping", | ||
"Properties": { | ||
"EventSourceArn": { | ||
"Fn::GetAtt": [ | ||
"MySqsQueue", | ||
"Arn" | ||
] | ||
}, | ||
"FunctionName": { | ||
"Ref": "FilteredEventsFunction" | ||
}, | ||
"FilterCriteria": { | ||
"Filters": [ | ||
{ | ||
"Pattern": "{\"name\": \"value\"}" | ||
} | ||
] | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.