Search code examples
amazon-dynamodbaws-appsync

AppSync BatchDeleteItem not executes properly


I'm working on a React Native application with AppSync, and following is my schema to the problem:

type JoineeDeletedConnection {
    items: [Joinee]
    nextToken: String
}
type Mutation {
    deleteJoinee(ids: [ID!]): [Joinee]
}

In 'request mapping template' to resolver to deleteJoinee, I have following (following the tutorial from https://docs.aws.amazon.com/appsync/latest/devguide/tutorial-dynamodb-batch.html):

#set($ids = [])
#foreach($id in ${ctx.args.ids})
    #set($map = {})
    $util.qr($map.put("id", $util.dynamodb.toString($id)))
    $util.qr($ids.add($map))
#end

{
    "version" : "2018-05-29",
    "operation" : "BatchDeleteItem",
    "tables" : {
        "JoineesTable": $util.toJson($ids)
    }
}

..and in 'response mapping template' to the resolver,

$util.toJson($ctx.result.data.JoineesTable)

The problem is, when I ran the query, I got empty result and nothing deleted to database as well:

// calling the query
mutation DeleteJoinee {
  deleteJoinee(ids: ["xxxx", "xxxx"])
  {
      id
  }
}

// returns
{
  "data": {
    "deleteJoinee": [
      null
    ]
  }
}

Solution

  • I finally able to solve this puzzle, thanks to the answer mentioned here to point me to some direction.

    Although, I noticed that JoineesTable does have trusted entity/role to the IAM 'Roles' section, yet it wasn't working for some reason. Looking into this more, I noticed that the existing policy had following actions as default:

    "Action": [
        "dynamodb:DeleteItem",
        "dynamodb:GetItem",
        "dynamodb:PutItem",
        "dynamodb:Query",
        "dynamodb:Scan",
        "dynamodb:UpdateItem"
    ]
    

    Once I added following two more actions to the list, things have started working:

    "dynamodb:BatchWriteItem",
    "dynamodb:BatchGetItem"
    

    Thanks to @Vasileios Lekakis and @Ionut Trestian on this appSync quest )