0
votes

I've set a DynamoDB stream to trigger a simple Lambda function, which works to trigger the function but returns an empty event object. I'm expecting the usual response with Keys, Oldimage, Newimage etc...

The event is passed correctly when I test the function manually in the console as well as when I trigger it with API Gateway. My Execution role has admin access. I even replicated the aws stream/lambda tutorial with the same issue. This should be really simple to do and it's driving me crazy!

My function couldn't be any simpler:

def get_event(event, context):
    print(event)
    return {
        'statusCode': 200,
        'body': event
    }

And here is my CloudWatch Log with the empty event:

"StatusCode": 200,
"LogResult": START RequestId: 48ec33f4-8707-4d16-9f53-4c7fcf7413d1       Version: $LATEST
{}
END RequestId: 48ec33f4-8707-4d16-9f53-4c7fcf7413d1
REPORT RequestId: 48ec33f4-8707-4d16-9f53-4c7fcf7413d1  Duration:      7.74 ms  Billed Duration: 100 ms     Memory Size: 128 MB Max Memory     Used: 71 MB

In case it's useful, my Event source mapping for my function

{
    "EventSourceMappings": [
        {
            "UUID": "ce6d850*********************",
            "BatchSize": 100,
            "EventSourceArn": "arn:aws:dynamodb:us-east-   1:**********:table/EventsDatabase/stream/2019-06-24T14:02:23.578",
            "FunctionArn": "arn:aws:lambda:us-east-1:***********:function:email_sender",
            "LastModified": 1561872060.0,
            "LastProcessingResult": "OK",
            "State": "Enabled",
            "StateTransitionReason": "User action"
        }
    ]
}
1
Completely empty event doesn't seam like the Function was invoked from the DynamoDB Stream. It looks more like you called your function manually expecting it to read from stream. Try to change/add some items in the DynamoDB and see if your function is invoked (and with what payload). Otherwise could you please show the configuration of the DynamoDB Stream itself.Nikolay Grischenko
Thanks for answering! But no the function was definitely invoked through DynamoDB Streams. As far as configuration I set it up in the console just by adding a trigger, default settings (batch size=100, starting position=Latest.) Any other info I could provide?Peter Sorbo
1) Just to confirm: your function handler is configured to your_file_name.get_event? 2) What is ViewType configured for your stream? Check these settings from the DynamoDB side. Probably you have OLD_IMAGE and for creating new items it doesn't include anything (only for modifications). 3) Also try for testing to change the batch_size of stream from 100 to 1. Although if you have your Lambda invoked - this means you reach this batch size somehow.Nikolay Grischenko

1 Answers

0
votes

I’m unable replicate the issue from my side. Maybe your lambda container is out of date. Have you tried forcing a new lambda container to start, or even deleting the whole lambda and starting again might work? See Force Discard AWS Lambda Container. I tried something like this and it worked for me (I’m using Python 3.7):

import json


def lambda_handler(event, context):
    print(event)
    # print("got event: " + json.dumps(event))

    get_event(event, context)

    return {
        'statusCode': 200,
        'body': json.dumps('Hello from Lambda!')
    }

def get_event(event, context):
    print(event)