aws lambda - How to get the table name in AWS dynamodb trigger function? -


i new aws , working on creating lambda function on python. function dynamodb table stream , write file in s3. here name of file should name of table. can please tell me how table name if trigger invoking lambda function?

thanks help.

since mentioned new aws, going answer descriptively.

i assuming have set 'stream enabled' setting dynamodb table 'yes', , have set event source lambda function.

this how got table name stream invoked lambda function -

def lambda_handler(event, context):    print(json.dumps(event, indent=2)) # shows what's in event object    record in event['records']:       ddbarn = record['eventsourcearn']       ddbtable = ddbarn.split(':')[5].split('/')[1]       print("dynamodb table name: " + ddbtable)    return 'successfully processed records.' 

basically, event object contains information particular dynamodb stream responsible particular lambda function invoke, contains parameter eventsourcearn. eventsourcearn arn (amazon resource number) uniquely identifies dynamodb table event occurred.

this sample value eventsourcearn -

arn:aws:dynamodb:us-east-1:111111111111:table/test/stream/2020-10-10t08:18:22.385

notice bold text above - test; table name looking for.

in line ddbtable = ddbarn.split(':')[5].split('/')[1] above, have tried split entire arn ':' first, , '/' in order value test. once have value, can call s3 apis write file in s3 same name.

hope helps.


Comments

Popular posts from this blog

java - pagination of xlsx file to XSSFworkbook using apache POI -

Unlimited choices in BASH case statement -

apache - How do I stop my index.php being run twice for every user -