- Lambda to create user profile. User profile will include user_id, name, email, mobile number, address, company, title
- Lambda to update user profile when the email or mobile number matches in the incoming api request
- Lambda to update user interests including sports, food, media and more. Come up with relevant fields that can be added to user profile and add the same as parameter for the function
- All data should go to AWS Dynamo DB
- Configure AWS API gateway and create relevant APIs for create and update user records. Configure security for the API and configure rate limiting for the APIs
- Use async/await calls in the Node JS functions
- Add relevant code comments and modularise the code properly. Create more than one Lambda wherever required and make inter Lambda calls if required
- Write an automated test for this lambda
DynamoDB is Amazon AWS's NoSQL database. Download a local DynamoDB to Start a local instance https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/DynamoDBLocal.DownloadingAndRunning.html
Start DynamoDB:
java -Djava.library.path=./DynamoDBLocal_lib -jar DynamoDBLocal.jar -sharedDb
For this project, we need a table TB_USER created in DynamoDB. The table schema is available in config/schemas directory
aws dynamodb delete-table --table-name TB_USER --endpoint-url http://localhost:8000
Go to the config/schemas directory and execute the below command:
aws dynamodb create-table --cli-input-json file://indorse_tb_user.json --endpoint-url http://localhost:8000
aws dynamodb list-tables --endpoint-url http://localhost:8000
This is NodeJS REST application which is running under Express Server.
To make a NodeJS Express server, AWS Lambda compatible, we need to make few modification in code base. ClaudiaJS is a awesome tool to convert a Node Express application into a AWS Lambda serverless application.
npm install claudia -g
claudia generate-serverless-express-proxy --express-module index
This will generate a file claudia.json which will have AWS Role, Lamdba Function Name and Region information.
Here index is the main script name without the extension (index.js).
But this index.js will not work in your local development machine. Which is why index.local.js is created and referred in package.json
claudia create --handler lambda.handler --deploy-proxy-api --region ap-southeast-1
This will create a AWS Lambda function, provided that you have AWSCLI installed and configured in local system
This Lambda function require few environment variables to be set:
| Variable Name | Value |
|---|---|
| APP_ENV | production |
| ACCESS_KEY | {ACCESS_KEY} |
| ACCESS_SECRET | {ACCESS_SECRET} |
claudia update
{
"ADDRESS": "Bedok",
"USER_ID": "user456",
"TITLE": "Ms",
"EMAIL": "mariana@dummydomain.com",
"NAME": "Mariana Khan",
"MOBILE": "986798590",
"COMPANY": "CDE",
"INTEREST": [
{
"FOOD": "Tea"
},
{
"SPORTS": "Cricket,Football"
}
]
}
Get all users:
GET https://fjthw9cb9i.execute-api.ap-southeast-1.amazonaws.com/latest/api/user
Get a particular user
GET https://fjthw9cb9i.execute-api.ap-southeast-1.amazonaws.com/latest/api/user/{user_id}
Save an user
POST https://fjthw9cb9i.execute-api.ap-southeast-1.amazonaws.com/latest/api/user
Update an user
PUT https://fjthw9cb9i.execute-api.ap-southeast-1.amazonaws.com/latest/api/{user_id}
Get all users:
Get a particular user
Save an user
Update an user
aws apigateway get-resources --rest-api-id tbi0iswybg --region ap-southeast-1