Python 3.x 从DynamoDB获取数据
我想使用python使用主键从Dynamo Db表中获取数据。 我的表名是“CustomerDetails”,主键是“Email id”。 我将从API网关触发这个Lambda函数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
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()调用的响应?