Reputation: 321
Stack :
Serverless, version:
Framework Core: 2.71.0 (local)
Plugin: 5.5.4
SDK: 4.3.2
Components: 3.18.2
Php 7.2
A DynamoDB stream with specific criteria should trigger a lambda, my serverless function works:
createStatementFiles:
handler: lambda/statement.php
timeout: 899 # 14min 59s
layers:
- arn:aws:lambda:#{AWS::Region}:<account_id>:layer:php-73:1
role: CreateStatementFilesRole
reservedConcurrency: 10
events:
- stream:
type: dynamodb
arn: arn:aws:dynamodb:eu-west-3:<account_id>:table/<table_name>/stream/<stream_id>
filterPatterns:
- eventName: [INSERT]
dynamodb:
NewImage:
__partitionKey:
S: [statementBalance]
What I absolutely want is for the DynamoDB stream to trigger the lambda if and only if the date of statementBalance = the last day of the month from the month of statementBalance, example:
$currentDate = '2022-10-25';
$statementBalance->getDate() = '2022-02-10';
$lastDayOfTheMonth = '2022-02-28', not equal last day of the month of $currentDate (2022-10-31)
Here is a diagram of what I would like to have:
If you have other solutions for my need which prevents the triggering of the lambda each time there is an INSERT of statementBalance, I am interested.
In advance, thank you very much for your help,
Upvotes: 2
Views: 835
Reputation: 321
I add a new attribute for the StatementBalance
object; "(bool) lastDayOfMonth
"
This attribute will trigger the Lambda if and only if lastDayOfMonth = true
createStatementFiles:
handler: lambda/statement.php
timeout: 899 # 14min 59s
layers:
- arn:aws:lambda:#{AWS::Region}:<account_id>:layer:php-73:1
role: CreateStatementFilesRole
reservedConcurrency: 10
events:
- stream:
type: dynamodb
arn: ${fetchStreamARN:${opt:stage}-${opt:client}-Project}
filterPatterns:
- eventName: [INSERT]
dynamodb:
NewImage:
__partitionKey:
S: [statementBalance]
lastDayOfMonth:
N: [1]
Thank's to @jarmod !
Upvotes: 1