Opt*_*mus 7 python amazon-dynamodb boto3
我目前有一个 python 脚本,如下所示:
import boto3
...
response = dynamodb.get_item(
TableName = dynamodb_table_name,
Key = {
"snippet_id": {
"S": snippet_id
}
}
)
if "Item" in response:
item = response["Item"]
print(json.dumps(item, indent=4, cls=DecimalEncoder))
Run Code Online (Sandbox Code Playgroud)
这会打印类似于以下内容的内容:
{
"var_1": {
"BOOL": false
},
"var_2": {
"S": "Text"
},
"snippet_id": {
"S": "3a97e45c-ffed-4c76-8bb4-b2a32f49a5d2"
}
}
Run Code Online (Sandbox Code Playgroud)
知道如何进行类型检测并返回:
{
"var_1": False,
"var_2": "Text",
"snippet_id": "3a97e45c-ffed-4c76-8bb4-b2a32f49a5d2"
}
Run Code Online (Sandbox Code Playgroud)
另外,这也可以用于查询吗?
使用resource代替client。
本质上,您可以调用boto3.client()或boto3.resource()。
客户端返回dynamoDB 语法,如下所示:
'var_1' : {'S':"string"}
Run Code Online (Sandbox Code Playgroud)
Resource返回正常语法,如下所示:
'var_1' : "string"
Run Code Online (Sandbox Code Playgroud)
从本质上讲,Boto3 所做的就是代表您调用 AWS API。对于大多数 AWS 服务,Boto3 提供了两种不同的方式来访问这些抽象的 API:
| 归档时间: |
|
| 查看次数: |
1529 次 |
| 最近记录: |