Using serverless framework: Very good blog with examples
emailUsersWhenJobComplete:
handler: src/emailUsersWhenJobComplete.handler
events:
- stream:
type: dynamodb
arn: ${construct:batchJobs.tableStreamArn}
filterPatterns:
- eventName: [INSERT]
dynamodb:
NewImage:
jobState:
S: [DONE]
- eventName: [MODIFY]
dynamodb:
NewImage:
jobState:
S: [DONE]
OldImage:
jobState:
S:
- anything-but: [DONE]
structureCheck:
handler: src/structureCheck.handler
events:
- stream:
type: dynamodb
arn: ${construct:structures.tableStreamArn}
filterPatterns:
- eventName: [INSERT]
dynamodb:
NewImage:
type:
S: [piping]
radius_cm:
N:
- numeric: [>, 5]
length_m:
N:
- numeric: [>, 10]
material:
S:
- prefix: [PVC]
events:
- stream:
type: dynamodb
arn: stream_arn
filterPatterns:
- eventName: 'INSERT' # [INSERT|MODIFY|REMOVE]
dynamodb:
Keys: # NewImage|OldImage|Keys
temperature: # name of field
S: [{"prefix":"celsius"}] # S for String, N for number, etc.
Worked for “or” condiftion using serverless framework
- stream:
type: dynamodb
arn: streamArn
bisectBatchOnFunctionError: true
destinations:
onFailure:
arn:
Fn::GetAtt:
- DLQName
- Arn
type: sqs
filterPatterns:
- eventName: [REMOVE]
- eventName: [INSERT, MODIFY]
dynamodb:
NewImage:
SourceId:
S: [{"prefix":"start"}]
- eventName: [INSERT, MODIFY]
dynamodb:
NewImage:
Id:
S: ["AAA", "BBB", "CCC"]
AWS tutorial <–this one does not use the serverless framework notation
You can specify up to 5 event filtering patterns for a Lambda function. Notice that each one of those 5 events will be evaluated as a logical OR. So if you configure two filters named Filter_One and Filter_Two, the Lambda function will execute Filter_One OR Filter_Two.
SampleEventSourceMapping:
Type: AWS::Lambda::EventSourceMapping
Properties:
FilterCriteria:
Filters:
- Pattern: "{\"dynamodb\":{\"NewImage\":{\"Id\": {\"S\": [\"C1\",\"C2\",\"C3\"]}}}}"
- Pattern: "{\"eventName\": [\"REMOVE\"]}"