Since you mentioned that you are new to AWS, I am going to answer descriptively.
I assume that you set the "With Stream Enabled" parameter for the DynamoDB table to "Yes" and configured this as the event source for your lambda function.
This is how I got the table name from the thread that called my lambda function -
def lambda_handler(event, context): print(json.dumps(event, indent=2)) # Shows what in the event object for record in event['Records']: ddbARN = record['eventSourceARN'] ddbTable = ddbARN.split(':')[5].split('/')[1] print("DynamoDB table name: " + ddbTable) return 'Successfully processed records.'
In principle, the event object, which contains all the information about a particular DynamoDB thread that was responsible for this special function of the lambda function, contains the eventSourceARN parameter. This eventSourceARN is the ARN (Amazon Resource Number) that uniquely identifies your DynamoDB table from which the event came.
This is an example value for eventSourceARN -
ARN: AWS: dynamodb: us-east-1: 111111111111: table / test /stream/2020-10-10T08:18:22.385
Pay attention to the bold text above - test ; This is the name of the table you are looking for.
In the line ddbTable = ddbARN.split(':')[5].split('/')[1] above, I tried to split the entire ARN into ':' first and then to '/' to get the test value. Once you get this value, you can call the S3 API to write to the file in S3 with the same name.
Hope this helps.
source share