0
votes

I made a Serverless API backend on AWS console which uses API Gateway, DynamoDB, Lambda functions.

Upon creation I can add the data in dynamoDB online by adding a JSON file, which looks like this:

{
  "id": "4",
  "k": "key1",
  "v": "value1"
}

But when I try to add this using "Postman", by adding the above JSON data in the body of POST message, I get a Positive return (i.e. no errors) but only the "id" field is added in the database and not the "k" or "v".

What is missing?

1
The problem is probably in your Lambda function. Can you share the relevant code?Matthew Pope
The most common issue on this setup is that your DynamoDB function is asynchronous and your lambda is terminating before the DynamoDB action can complete. We will need to see your lambda function.F_SO_K
Also, please share the insert/update codeuser3807691

1 Answers

0
votes

I think that you need to check on your Lambda function.

As you are using Postman to do the API calls, received event's body will be as follows:

{'resource':
...
}, 'body': '{\n\t"id": 1,\n\t"name": "ben"\n
}', 'isBase64Encoded': False
}

As you can see:

'body': '{\n\t"id": 1,\n\t"name": "ben"\n}'

For example, I will use Python 3 for this case, what I need to do is to load the body into JSON format then we are able to use it.

result = json.loads(event['body'])
id = result['id']
name = result['name']

Then update them into DynamoDB:

item = table.put_item(
        Item={
        'id': str(id),
        'name': str(name)
        }
    )