[英]How to update a nested item in AWS DynamoDB with CLI
In one of my AWS DynamoDB tables I have several items that require an update within in a pipeline.在我的一个 AWS DynamoDB 表中,我有几个项目需要在管道中进行更新。 The following json shows an item in the AWS DynamoDB table:以下 json 显示了 AWS DynamoDB 表中的一个项目:
{
"DeploymentConfigs": {
"L": [
{
"M": {
"Config": {
"M": {
"Name": {
"S": "batch-komo"
},
"Replicas": {
"N": "3"
}
}
}
}
},
{
"M": {
"Config": {
"M": {
"Name": {
"S": "online-komo"
},
"Replicas": {
"N": "3"
}
}
}
}
}
]
},
"environment": {
"S": "komo-claimcenter"
}
}
How can update an object in DeploymentConfigs
?如何在DeploymentConfigs
中更新 object ? Primary partition key is environment
.主分区键是environment
。
Eg the object例如 object
{
"M": {
"Config": {
"M": {
"Name": {
"S": "batch-komo"
},
"Replicas": {
"N": "3"
}
}
}
}
}
shall be updated to应更新为
{
"M": {
"Config": {
"M": {
"Name": {
"S": "batch-komo"
},
"Replicas": {
"N": "5"
}
}
}
}
}
I do not know to achieve in the AWS CLI.我不知道在 AWS CLI 中实现。
To update a nested part inside an item, you use an UpdateExpression
with an attribute path.要更新项目内的嵌套部分,请使用带有属性路径的UpdateExpression
。 For example, SET DeploymentConfigs[0].Config.Replicas =:val
.例如, SET DeploymentConfigs[0].Config.Replicas =:val
。
The problem, however, is that your top-level attribute DeploymentConfigs
is a list, so to modify one of its items, you need to know in index (in this example 0).但是,问题在于您的顶级属性DeploymentConfigs
是一个列表,因此要修改其中的一项,您需要在索引中知道(在此示例中为 0)。 If you don't know the index you have a problem - there is no way to "modify the list item which has name='batch-komo'" or something like that... If you need to do something like this, you have to read the entire top-level attribute, modify it in the client, and write it (or just the small change, now that you know the index) back.如果你不知道你有问题的索引 - 没有办法“修改具有 name='batch-komo' 的列表项”或类似的东西......如果你需要做这样的事情,你必须读取整个顶级属性,在客户端对其进行修改,然后将其写回(或者只是小的更改,现在您知道索引了)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.