如何解决boto3 dynamodb put_item错误仅接受关键字参数
我在lambda函数中使用boto3将信息写入dynamodb表中。
我收到错误put_item() only accepts keyword arguments
。
在网上搜索时,我发现此错误可能意味着我与dynamodb分区键不匹配,但是在我看来,我所做的一切都正确。
有人可以帮助我找到错误吗?对不起,但这是我第一次使用aws。
这是我的lambda函数
import json,boto3
def updateDynamo(Item):
dynamodb = boto3.resource('dynamodb',region_name = 'eu-central-1')
table = dynamodb.Table('userInformations')
response = table.put_item(Item)
return response
def lambda_handler(event,context):
userAttributes = event["request"]["userAttributes"]
email = userAttributes["email"]
name = userAttributes["name"]
Item = {
"email": email,"name" : name
}
response = updateDynamo(Item)
print(email,name)
return {
'statusCode': 200,'body': json.dumps('Hello from Lambda!')
}
这是我正在使用的测试事件:
{
"version": "string","triggerSource": "string","region": "AWSRegion","userPoolId": "string","userName": "string","callerContext": {
"awsSdkVersion": "string","clientId": "string"
},"request": {
"userAttributes": {
"email": "testemail@gmail.com","name": "test user"
}
},"response": {}
}
我的表具有email
(所有字符均为小写)作为分区键。
解决方法
put_item需要仅关键字参数。这意味着,根据您的情况,而不是:
response = table.put_item(Item)
应该有
response = table.put_item(Item=Item)
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。