gpt4 book ai didi

python - boto3 dynamodb put_item() 错误只接受关键字参数

转载 作者:行者123 更新时间:2023-12-04 16:39:38 24 4
gpt4 key购买 nike

我在 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": {}
}
我的 table 上有 email (所有字符都是小写)作为分区键。

最佳答案

put_item只需要关键字参数。这意味着,在您的情况下,而不是:

response = table.put_item(Item)
应该有
response = table.put_item(Item=Item)

关于python - boto3 dynamodb put_item() 错误只接受关键字参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63615560/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com