2

I am using dynamodb trigger for my lambda.So i am considering two conditions, whenever my table 1 gets updated lambda should be triggered and based on condition expression table 2 should be updated just like the changes i have applied in table 2. Since i am going to use boto 3 resource need sample logic regrading the same. I am new to handling events with dynamodb triggers. Any help will be highly appreciated.

2 Answers 2

1

Generally you would setup event source mapping between table 1 and your lambda function.

The lambda function would process the records from table 1, e.g. filter them out based on some condition, and then the remaining records would be written to the table 2.

For writing to table 2, boto3 provides interface to dynamodb.

Sign up to request clarification or add additional context in comments.

2 Comments

Do you have any boto3 logic for reading the stream data for insert operation for table 1
You don't have to read it yourself. That's why you use event source mapping. It will invoke your function automatically and pass the records from the stream. I recommend reading more on how event source mapping works.
1

Table-1 ~~~~~~~~> AWS Lambda --------->Table2

Event received by AWS Lambda will look something like this. What you need to do is based on event name process the values present and store it in Table-2.

def lambda_handler(event, context):
    dynamodb = boto3.resource('dynamodb', region_name='eu-west-1')
    table2 = dynamodb.Table('Table-2')

    # Read the records in the event
    for record in event['Records']:
        # process record and prepare required object for Table-2
        table_2_obj = process_record(record)
        put_item_response = table2.put_item(table_2_obj)
        # Verify the response if required
        print(put_item_response)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.