rest api gateway in front of dynamodb, POST mapping template for updateitem format

0

Hello,

I am trying to create a rest api with api gateway in front of a very simple dynamodb table with counters.

The table is just 2 fields: ucgkey01 as string, votecount as number

tested updates with

aws dynamodb update-item \
--table-name $tablename \
--key '{"ucgkey01": { "S": "testname01" }}' \
--update-expression "SET votecount = votecount + :incr" \
--expression-attribute-values '{":incr":{"N":"1"}}' \
--return-values UPDATED_NEW

I have a post method to dynamodb with UpdateItem action. I am trying this mapping template in the POST method of my api gw inspired by this

{
    "operation" : "UpdateItem",
	"TableName": "UGC-test01",
    "key" : {
        "ucgkey01" : { "S": "$input.path('$.ucgkey01')" }
    },
    "update" : {
        "expression" : "SET votecount = votecount + :incr",
        "expressionValues" : {
            ":incr":{"N":"1"}
        }
    }
}

but if I test a POST with

{

        "ucgkey01" : "testname01"
        
}

I get

{
  "__type": "com.amazon.coral.validate#ValidationException",
  "message": "1 validation error detected: Value null at 'key' failed to satisfy constraint: Member must not be null"
}

can someone please point me to a solution?

Thanks

a.

  • this is my latest endpoint request after transformation:

    Endpoint request body after transformations: { "operation" : "UpdateItem", "version" : "2017-02-28", "TableName": "UGC-test01", "key" : { "ucgkey01" : { "S": "testart01" } }, "update" : { "expression" : "SET votecount = votecount + :incr", "expressionValues" : { ":incr":{"N":"1"} } }, "ReturnValues": "UPDATED_NEW"

    }

Keine Antworten

Du bist nicht angemeldet. Anmelden um eine Antwort zu veröffentlichen.

Eine gute Antwort beantwortet die Frage klar, gibt konstruktives Feedback und fördert die berufliche Weiterentwicklung des Fragenstellers.

Richtlinien für die Beantwortung von Fragen