0

I am retrieving a DynamoDB item using Python and AWS Lambda. I am having difficulty parsing the value that the response contains.

For example, this is returned for response['Item']['GUID']

{u'S': u'8898f389-c282-4c4f-952a-87a0fbbb6d70'}

In the end, I just want the actual value without the extraneous information DynamoDB inserts. How do you best handle DynamoDB's JSON formatting using Python 2.7?

1 Answer 1

1

this is an example:

def lambda_handler(event, context):

        print("Received event: " + json.dumps(event, indent=2))

        if 'Records' not in event:
            print ('records not in event')
            return

        for record in event['Records']:
            if record['eventName'] == 'INSERT':
                print 'do something on insert'

            your_integer_hash_key = record['dynamodb']['Keys']['your_hash_key']['N']

            # if all image is stream
            if not 'NewImage' in record['dynamodb']:
                continue

            # get new image    
            new_image = record['dynamodb']['NewImage']
Sign up to request clarification or add additional context in comments.

1 Comment

The tip to use json.dumps lead me to this: dynamo_GUID = json.dumps(response['Item']['GUID']) Everything seems to work how I anticipate now.

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.