AWS Lambda

时间:2016-02-28 17:54:38

标签: python-2.7 amazon-dynamodb aws-lambda

我正在使用Python和AWS Lambda检索DynamoDB项目。我无法解析响应包含的值。

例如,这会返回以回复['项目'] [' GUID']

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

最后,我只想要没有DynamoDB插入的无关信息的实际值。您如何使用Python 2.7最好地处理DynamoDB的JSON格式?

1 个答案:

答案 0 :(得分:1)

这是一个例子:

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']