I want to retrieve the latest inserted record in dynamodb so that whenever a new record is inserted it the dynamodb table a lambda will trigger and fetch the record and pass it on to a python script.
I am writing the lambda in Python 2.7
import json
import boto3
from boto3.dynamodb.conditions import Key, Attr
def lambda_handler(event, context):
dynamodb = boto3.resource('dynamodb')
table = dynamodb.Table("html_contents")
try:
if (record.eventName == "INSERT") {
#How to Retrieve the latest record
}
except Exception, e:
print(e)
Have a look at DynamoDB Streams.
Put your Lambda function as the event handler of a DynamoDB stream. It will then get triggered when anyone writes an item to a DynamoDB table.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With