我应该在 Boto3 中使用什么方法使用 AWS API 网关作为代理服务在 DynamoDB 中创建条目?

What method should I use in Boto3 to create an entry in DynamoDB using AWS API gateway as a proxy service?

我是编码新手。感谢您的帮助。 我已经创建了 DynamoDB table、API 网关、子资源、子方法 (POST),集成类型:AWS 服务代理。我还创建了一个 IAM 角色以允许访问 DynamoDB putitem。 我尝试用邮递员向 table 添加一些东西,效果很好。但是,现在我想使用 boto3 向 table 添加一个项目,但我发现很难确定我应该使用的方法。

请参阅 AWS 文档 here 以获取使用 Python 创建、读取、更新和删除项目的示例。

dydbsr = boto3.resource('dynamodb')
dbtable = 'myTable'
table = dydbsr.Table(dbtable)

如果您只有一个分区键:

partion key is: mypartitionkey

json_dictionary = {"mypartitionkey": "myvalue"}
table.put_item(Item=json_dictionary)

如果您有分区键和排序键。如果定义了排序键,它必须被包含

partion key is: mypartitionkey
sort key is: mysortkey

json_dictionary = {"mypartitionkey": "myvalue", "mysortkey": "myothervalue"}
table.put_item(Item=json_dictionary)

添加分区键和排序键后,您的属性只是同一个 json 字典中的 key:value 对