I'm using serverless framework to code AWS lambda function. I need to get a form data from a HTML page and save it to Dynamodb using AWS lambda. So i have written the code in nodejs and API endpoints as well. Finally i deployed the application to AWS. So when i'm trying to post data using both CURL and Postman, it shows an "Internal Server Error"
Following are the relevant code snippets.
handler.js
const params = {
TableName: process.env.DYNAMODB_TABLE,
Item: {
id: uuid.v1(),
name: data.name,
phone: data.phone,
checked: false,
createdAt: timestamp,
updatedAt: timestamp,
},
};
serverless.yml
provider:
name: aws
runtime: nodejs6.10
environment:
DYNAMODB_TABLE: ${self:service}-${opt:stage, self:provider.stage}
iamRoleStatements:
- Effect: Allow
Action:
- dynamodb:Query
- dynamodb:Scan
- dynamodb:GetItem
- dynamodb:PutItem
- dynamodb:UpdateItem
- dynamodb:DeleteItem
Resource: "arn:aws:dynamodb:${opt:region, self:provider.region}:*:table/${self:provider.environment.DYNAMODB_TABLE}"
I'm not sure where to define the Dynamo table name and whether it is created by while running the code by automatically? And i followed this github repo - https://github.com/serverless/examples/tree/master/aws-node-rest-api-with-dynamodb