I am new to AppSync and DynamoDB, sorry if this question is basic. I have an AppSync Resolver for this schema:
type Profile {
name: String!
location: String!
}
input ProfileInput {
name: String!
location: String!
}
type Mutation {
createProfile(profileInput: ProfileInput!): Profile! @aws_cognito_user_pools @aws_api_key
}
The resolvers are:
Request
{
"version" : "2017-02-28",
"operation" : "UpdateItem",
"key" : {
"name" : $util.dynamodb.toDynamoDBJson($ctx.identity.username),
"attribute": $util.dynamodb.toDynamoDBJson("info")
},
"update" : {
"expression" : "SET #p :da",
"expressionNames" : {
"#p" : "data"
},
"expressionValues" : {
":da" : $util.dynamodb.toDynamoDBJson($ctx.args.profileInput)
}
}
}
Response
$util.toJson($ctx.result)
The Request I am sending to Appsync :
mutation CreateProfileMutation {
createProfile(profileInput: {location: "Updated Location", name: "Updated Username"}) {
location
name
}
}
But Dynamodb is throwing this error:
{
"data": null,
"errors": [
{
"path": [
"createProfile"
],
"data": null,
"errorType": "DynamoDB:DynamoDbException",
"errorInfo": null,
"locations": [
{
"line": 12,
"column": 3,
"sourceName": null
}
],
"message": "Invalid UpdateExpression: Syntax error; token: \":da\", near: \"#p :da\" (Service: DynamoDb, Status Code: 400, Request ID: some id, Extended Request ID: null)"
}
]
}
The transformed template is:
{
"version" : "2017-02-28",
"operation" : "UpdateItem",
"key" : {
"name" : {"S":"user#1"},
"attribute": {"S":"info"}
},
"update" : {
"expression" : "SET #p :da",
"expressionNames" : {
"#p" : "data"
},
"expressionValues" : {
":da" : {"M":{"name":{"S":"Updated Username"},"location":{"S":"Updated Location"}}}
}
}
}
It looks like a syntax error, but I couldn't figure out what the error is. Any help is appreciated.
CodePudding user response:
The SET
action in your update expression is missing the =
operand.
It should be "expression" : "SET #p = :da"
instead of "expression" : "SET #p :da"
.