Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the latest record inserted in dynamodb

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)
like image 579
Ajinkya Avatar asked Nov 06 '22 20:11

Ajinkya


1 Answers

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.

like image 163
Milan Cermak Avatar answered Nov 25 '22 19:11

Milan Cermak