Amazon web services 如何使用嵌套数据配置UpdateExpression
我有一个AWSAPI网关,它将数据存储在DynamoDB实例中。我的表结构如下所示:Amazon web services 如何使用嵌套数据配置UpdateExpression,amazon-web-services,aws-api-gateway,Amazon Web Services,Aws Api Gateway,我有一个AWSAPI网关,它将数据存储在DynamoDB实例中。我的表结构如下所示: { "TableName": "stuff", "Item": { "stuffId": { "S": "02b4e004-1132-4b87-a855-20e7d1bd1840" }, "clients": { "M": { "company_inc": { "M": { "prod": {
{
"TableName": "stuff",
"Item": {
"stuffId": {
"S": "02b4e004-1132-4b87-a855-20e7d1bd1840"
},
"clients": {
"M": {
"company_inc": {
"M": {
"prod": {
"S": "null"
},
"qa": {
"S": "null"
},
"stage": {
"S": "null"
}
}
}
}
}
}
}
{
"TableName": "stuff",
"Item": {
"stuffId": {
"S": "02b4e004-1132-4b87-a855-20e7d1bd1840"
},
"clients": {
"M": {
"company_inc": {
"M": {
"prod": {
"S": "true"
},
"qa": {
"S": "null"
},
"stage": {
"S": "null"
}
}
}
}
}
}
}
我正在试图弄清楚如何配置我的身体映射模板,以便在收到HTTP补丁请求后,我可以更新company_inc.prod
。例如给定此查询字符串:
?stuffId=02b4e004-1132-4b87-a855-20e7d1bd1840&client=company_inc&location=prod&locationIsSet=true
我会将记录更新为如下所示:
{
"TableName": "stuff",
"Item": {
"stuffId": {
"S": "02b4e004-1132-4b87-a855-20e7d1bd1840"
},
"clients": {
"M": {
"company_inc": {
"M": {
"prod": {
"S": "null"
},
"qa": {
"S": "null"
},
"stage": {
"S": "null"
}
}
}
}
}
}
}
{
"TableName": "stuff",
"Item": {
"stuffId": {
"S": "02b4e004-1132-4b87-a855-20e7d1bd1840"
},
"clients": {
"M": {
"company_inc": {
"M": {
"prod": {
"S": "true"
},
"qa": {
"S": "null"
},
"stage": {
"S": "null"
}
}
}
}
}
}
}
“UpdateExpression”应该是什么样子的呢?我想我找到了答案。您必须在
公司产品
的路径中使用属性名称,如#client
和#location
{
"TableName": "stuff",
"Key": {
"alterId": {
"S": "$input.params('stuffId')"
}
},
"UpdateExpression": "set clients.#attrClientName.#attrLocation = :locationIsSet",
"ExpressionAttributeNames" : {
"#attrClientName" : "$input.params('client')",
"#attrLocation" : "$input.params('location')"
},
"ExpressionAttributeValues": {
":locationIsSet": {"S": "$input.params('location')"}
}
}