I followed the instructions here (SNS Events - Jets Ruby Serverless Framework) to create a subscription to a Lambda for an existing SNS topic. Everything was created perfectly the first time through. Publishing an event through the console and the CLI works fine. The Lambda is triggered and the logs are in CloudWatch.
The problem: The event is always nil. What causes the event to be nil? I’ve made sure the timeout is short, I’m adding the “default” variable, etc.
# first request
2023-09-09 14:59:31 UTC 2023/09/09/[$LATEST]87ae50548e364123865c478b0dd9956a START RequestId: 4f727df5-0684-4f1a-b8f9-1e77375f1fd8 Version: $LATEST
2023-09-09 14:59:31 UTC 2023/09/09/[$LATEST]87ae50548e364123865c478b0dd9956a event {"Records":[{"eventID":"aed79e5ddbbd94df113234e8590b9d5d","eventName":"INSERT","eventVersion":"1.1","eventSource":"aws:dynamodb","awsRegion":"us-west-2","dynamodb":{"ApproximateCreationDateTime":1694271571.0,"Keys":{"id":{"S":"id-1"}},"NewImage":{"id":{"S":"id-1"}},"SequenceNumber":"1200000000045765994168","SizeBytes":12,"StreamViewType":"NEW_AND_OLD_IMAGES"},"eventSourceARN":"arn:aws:dynamodb:us-west-2:112233445566:table/test-table/stream/2023-09-09T14:50:49.988"}]}
2023-09-09 14:59:31 UTC 2023/09/09/[$LATEST]87ae50548e364123865c478b0dd9956a END RequestId: 4f727df5-0684-4f1a-b8f9-1e77375f1fd8
2023-09-09 14:59:31 UTC 2023/09/09/[$LATEST]87ae50548e364123865c478b0dd9956a REPORT RequestId: 4f727df5-0684-4f1a-b8f9-1e77375f1fd8 Duration: 2.98 ms Billed Duration: 3 ms Memory Size: 1536 MB Max Memory Used: 138 MB
# second request
2023-09-09 14:59:42 UTC 2023/09/09/[$LATEST]87ae50548e364123865c478b0dd9956a START RequestId: 586fd3d5-b4ec-4a69-b1fd-d4fff78dec0f Version: $LATEST
2023-09-09 14:59:42 UTC 2023/09/09/[$LATEST]87ae50548e364123865c478b0dd9956a event {"Records":[{"eventID":"5cc3ec73ef40d27e1ea4d8e780d0dc66","eventName":"INSERT","eventVersion":"1.1","eventSource":"aws:dynamodb","awsRegion":"us-west-2","dynamodb":{"ApproximateCreationDateTime":1694271582.0,"Keys":{"id":{"S":"id-2"}},"NewImage":{"id":{"S":"id-2"}},"SequenceNumber":"1200000000045258722137","SizeBytes":12,"StreamViewType":"NEW_AND_OLD_IMAGES"},"eventSourceARN":"arn:aws:dynamodb:us-west-2:112233445566:table/test-table/stream/2023-09-09T14:50:49.988"}]}
2023-09-09 14:59:42 UTC 2023/09/09/[$LATEST]87ae50548e364123865c478b0dd9956a END RequestId: 586fd3d5-b4ec-4a69-b1fd-d4fff78dec0f
2023-09-09 14:59:42 UTC 2023/09/09/[$LATEST]87ae50548e364123865c478b0dd9956a REPORT RequestId: 586fd3d5-b4ec-4a69-b1fd-d4fff78dec0f Duration: 2.23 ms Billed Duration: 3 ms Memory Size: 1536 MB Max Memory Used: 138 MB
Interestingly, notice that a put-item call with the same DynamoDB partition_id will not fire off an event at all unless the item has been modified. Here’s an example of modifying the item.
2023-09-09 15:02:22 UTC 2023/09/09/[$LATEST]87ae50548e364123865c478b0dd9956a START RequestId: 06201a46-b724-4330-b489-7de0b98000a2 Version: $LATEST
2023-09-09 15:02:22 UTC 2023/09/09/[$LATEST]87ae50548e364123865c478b0dd9956a event {"Records":[{"eventID":"451d80a6ac0c682eedc934cb9482a579","eventName":"MODIFY","eventVersion":"1.1","eventSource":"aws:dynamodb","awsRegion":"us-west-2","dynamodb":{"ApproximateCreationDateTime":1694271741.0,"Keys":{"id":{"S":"id-2"}},"NewImage":{"name":{"S":"name-2"},"id":{"S":"id-2"}},"OldImage":{"id":{"S":"id-2"}},"SequenceNumber":"1300000000045258978099","SizeBytes":28,"StreamViewType":"NEW_AND_OLD_IMAGES"},"eventSourceARN":"arn:aws:dynamodb:us-west-2:112233445566:table/test-table/stream/2023-09-09T14:50:49.988"}]}
2023-09-09 15:02:22 UTC 2023/09/09/[$LATEST]87ae50548e364123865c478b0dd9956a END RequestId: 06201a46-b724-4330-b489-7de0b98000a2
2023-09-09 15:02:22 UTC 2023/09/09/[$LATEST]87ae50548e364123865c478b0dd9956a REPORT RequestId: 06201a46-b724-4330-b489-7de0b98000a2 Duration: 2.42 ms Billed Duration: 3 ms Memory Size: 1536 MB Max Memory Used: 138 MB
Followup
Unsure why you’re seeing nil
I wonder if you can try modifying the live lambda function handler at the beginning with the AWS Console. The handler or “entry point” to the lambda function should be in the deployed handlers folder. Here’s an example of how it would look like:
handlers/jobs/hard_job.rb
require "bundler/setup"
require "jets"
Jets.once # runs once in lambda execution context
def dig(event:, context:)
puts "showing event at the very beginning event: #{JSON.dump(event)}" # ADDED THIS LINE
Jets.process(event, context, "handlers/jobs/hard_job.dig")
end
It would be useful to see if the event coming into the handler at the very beginning is nil or not.