简体   繁体   中英

AWS Python: can't get data from a dynamodb in a lambda with get_item

I was expecting to get my data. Instead I get this:

{'ResponseMetadata': {'RequestId': 'XXXXXXXXXXXXXXXXXXXXX', 'HTTPStatusCode': 200, 'HTTPHeaders': {'server': 'Server', 'date': 'Mon, 28 Feb 2022 01:19:00 GMT', 'content-type': 'application/x-amz-json-1.0', 'content-length': '2', 'connection': 'keep-alive', 'x-amzn-requestid': 'XXXXXXXXXXXXXXXXXX', 'x-amz-crc32': 'XXXXXXXXX'}, 'RetryAttempts': 0}}

I mean, there are useful informations but, where is the data in this response??? I only see metadata...

Here is my code:

import json
import boto3
import botocore

dynamodb = boto3.client("dynamodb")

def get_dict(primary_key):
    print("primary_key:",primary_key)
    dynamodb = boto3.resource("dynamodb", region_name="eu-west-3")
    table = dynamodb.Table("mydynamoname")
    response = table.get_item(Key={"creation_file_date": primary_key})
    print(response)
    return response

def lambda_handler(event, context):
    form_dict = get_dict(event["report_id"])
    print(form_dict)
    return {
        'statusCode': 200,
        'body': json.dumps(form_dict)
    }

Sorry for the bother, I just put the wrong id !!!

(was loading an old one id and trying to get a new one that I was creating but not already created ^^). Strange that I don't get an error for that... But I'm fine now ! (and maybe others will be knowing that !

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM