I need to trigger a lambda when a specific object registers on DynamoDB.
For example:
If I create a
User
with aPOST /my-website/user
and, I store thisUser
onDynamoDB
, I want to trigger myLambda
.I don't want to trigger the
Lambda
if the registered object is different from theUser
.
For the management of my stack, I use Serverless
(with a serverless.yml
file) and CloudFormation
syntax.
With the serverless documentation, I can't figure out how I can trigger my Lambda
only when a specific entry is registered to DynamoDB
( https://www.serverless.com/framework/docs/providers/aws/events/streams ).
Thanks in advance,
EDIT:
Thank you for your answers :)
It's work:
statement:
handler: lambda/statement.php
layers:
- arn:aws:lambda:#{AWS::Region}:<account_id>:layer:php-73:1
iamRoleStatements:
- Effect: Allow
Action:
- dynamodb:ListStreams
- dynamodb:GetItem
events:
- stream:
type: dynamodb
arn: arn:aws:dynamodb:eu-west-3:<account_id>:table/dev-project/stream/2020-11-18T22:34:01.579
maximumRetryAttempts: 1
batchSize: 1
filterPatterns:
- eventName: [INSERT]
dynamodb:
NewImage:
__partitionKey:
S: [myPk]
You have to setup stream filters. The process is explained in: