Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/amazon-web-services/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x 从DynamoDB获取数据_Python 3.x_Amazon Web Services_Amazon Dynamodb_Boto3_Api Gateway - Fatal编程技术网

Python 3.x 从DynamoDB获取数据

Python 3.x 从DynamoDB获取数据,python-3.x,amazon-web-services,amazon-dynamodb,boto3,api-gateway,Python 3.x,Amazon Web Services,Amazon Dynamodb,Boto3,Api Gateway,我想使用python使用主键从Dynamo Db表中获取数据。 我的表名是“CustomerDetails”,主键是“Email id”。 我将从API网关触发这个Lambda函数 import boto3 from boto3.dynamodb.conditions import Key, Attr dynamodb = boto3.resource('dynamodb') table = dynamodb.Table('CustomerDeta

我想使用python使用主键从Dynamo Db表中获取数据。 我的表名是“CustomerDetails”,主键是“Email id”。 我将从API网关触发这个Lambda函数

      import boto3
      from boto3.dynamodb.conditions import Key, Attr
      dynamodb = boto3.resource('dynamodb')
      table = dynamodb.Table('CustomerDetails')
      def lambda_handler(event, context):
           response = table.get_item(key={'Email-id':event})
           #response = table.query(KeyConditionExpression=Key('Email-id').eq(event))

上面的代码不起作用。我做错了什么?

您必须将
get\u项(key=
更改为
get\u项(key=
),我想您可能会通知适当的位置从事件中检索电子邮件id

以下是一个例子:

import boto3
from boto3.dynamodb.conditions import Key

def lambda_handler(event, context):
      dynamodb = boto3.resource('dynamodb')
      table = dynamodb.Table('CustomerDetails')
      email_id = event['xxx']['xxxx'] # where your email id is in the event dict

      response = table.get_item(Key={'Email-id': email_id}).get('Item')

      ...

删除了我的答案,因为正如Mark B所指出的,我正在查看dynamodb客户端,而不是dynamodb.Table。那么,您能否提供Table.get_item()调用的响应?