Step 2: Create Lambda and API Gateway (Nodejs) — AWS Serverless to DynamoDB
Create API Gateway
The “Lambda function” will fill after creating Lambda.
Create Lambda
Role: Create new role from template(s)
Role name: dynamodb_read
Policy templates: Basic Lambda@Edge permissions (for CloudFront trigger)
IAM Setting
- Go back to DynamoDB Service
- Select your table and Get the ARN
The DynamoDB will appear on the Designer section in Lambda.
We use the Nodejs to connect the dynamoDB.
const AWS = require('aws-sdk');
AWS.config.update({ region: 'us-west-2' });
const dynamodb = new AWS.DynamoDB.DocumentClient();exports.handler = async (event, context) => {
return dynamodb.scan({ TableName: "dynamodb" })
.promise()
.then(response => response.Items)
};
Region: the location of the dynamoDB, the region code can find in the ARN.
arn:aws:dynamodb:us-west-2:5029XXXXXXXX:table/DynamoDB_Read
TableName: the table name of the dynamoDB — dynamodb
Remember to “Save”
Remember to “Add” and “Save”
You can give me the response for support if you completed the lab or ask me questions when you face any difficulty.
Check following story to review the lab.