-
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
Description
Is there an existing issue for this?
- I have searched the existing issues
Current Behavior
While using Lambda event source mappings with Dynamodb Streams there appears to be a bug surrounding filter criteria. It appears that the comparison operator exists doesn't work as intended when it's false. It seems to work as intended when set to true, but when false and the property doesn't exist in the item it doesn't seem to trigger.
There's another bug as well with event source mappings where it doesn't appear that SAM deploy will update the filter criteria in the event source mapping when there's a change. We can easily test this by making a change to the FilterCriteria in the SAM template and then redeploying. When we view the event source mappings it'll still have the old value. Interestingly awslocal lambda update-event-source-mapping does seem to update it while SAM will not.
Expected Behavior
-
When filter criteria includes
"exists": falseand the item added in does not include that property it should trigger the lambda. -
After updating the filter criteria and running a sam deploy it should modify the filter criteria which should be visible when running
list-event-source-mappings
How are you starting LocalStack?
With a docker-compose file
Steps To Reproduce
How are you starting localstack (e.g., bin/localstack command, arguments, or docker-compose.yml)
docker-compose up
template.yaml
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: >
localstack-dynamostream-helloworld
Sample SAM Template for localstack-dynamostream-helloworld
# More info about Globals: https://github.com/awslabs/serverless-application-model/blob/master/docs/globals.rst
Globals:
Function:
Timeout: 3
MemorySize: 128
Resources:
StreamsSampleDDBTable:
Type: AWS::DynamoDB::Table
Properties:
TableName: localstack-dynamostream-helloworld
AttributeDefinitions:
- AttributeName: "PK"
AttributeType: "S"
- AttributeName: "SK"
AttributeType: "S"
KeySchema:
- AttributeName: "PK"
KeyType: "HASH"
- AttributeName: "SK"
KeyType: "RANGE"
StreamSpecification:
StreamViewType: "NEW_AND_OLD_IMAGES"
ProvisionedThroughput:
ReadCapacityUnits: 5
WriteCapacityUnits: 5
LambdaExecutionRole:
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: Allow
Principal:
Service:
- lambda.amazonaws.com
Action:
- sts:AssumeRole
Path: "/"
Policies:
- PolicyName: root
PolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: Allow
Action:
- logs:CreateLogGroup
- logs:CreateLogStream
- logs:PutLogEvents
Resource: arn:aws:logs:*:*:*
- Effect: Allow
Action:
- dynamodb:DescribeStream
- dynamodb:GetRecords
- dynamodb:GetShardIterator
- dynamodb:ListStreams
Resource: !GetAtt StreamsSampleDDBTable.StreamArn
DBEventStreamProcessor:
Type: AWS::Serverless::Function
Properties:
FunctionName: localstack-dynamostream-helloworld
Runtime: python3.7
Timeout: 300
Role: !GetAtt LambdaExecutionRole.Arn
CodeUri: src/
Handler: helloworld.lambda_handler
Runtime: python3.8
Architectures:
- x86_64
Events:
DBProfileEventStream:
Type: DynamoDB
Properties:
Stream: !GetAtt StreamsSampleDDBTable.StreamArn
ParallelizationFactor: 10
FunctionResponseTypes:
- ReportBatchItemFailures
StartingPosition: LATEST
BatchSize: 5
FilterCriteria:
Filters:
- Pattern: |
{
"dynamodb": {
"NewImage": {
"homemade": {
"S": [
{
"exists": false
}
]
}
}
}
}
Enabled: true
Client commands (e.g., AWS SDK code snippet, or sequence of "awslocal" commands)
samlocal build --config-file samconfig.toml --template-file template.yaml
samlocal deploy --stack-name localstack-dynamostream-helloworld-1
awslocal dynamodb put-item --table-name "localstack-dynamostream-helloworld" --item file://test.json
Environment
- OS: OSX 14
- LocalStack: Localstack pro latest
- SAM 1.110.0Anything else?
Based the template off of https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Streams.Lambda.Tutorial2.html