This is an example of a Serverless congifuration for PUT and GET AWS lambda functions, API Gateway DynamoDB which all deploys through CloudFormation in AWS. There is also local commands to run it all locally to test before deploying.
-
npm install
-
serverless offline start --stage dev
. This will deploy the services locally (no cost or AWS used. Useful to test locally before deploying to AWS for real). -
npm run list-tables
. This should return a "dev" table in DynamoDB local. -
npm run deploy
. This will deploy the formation and all the services to AWS (you need to be logged into AWS CLI locally to do this). -
npm run delete
. This will remove all the deployed services that you deployed in step 4.
-
You will need to run
aws configure
with your AWS details. -
GET
curl http://localhost:3000/dev/todos
. Should return an empty array before any post. -
POST
curl -X POST http://localhost:3000/dev/todos -H "Content-Type: application/json" -d '{"text": "Example text"}'
.
To get around this issue make the following changes:
-
Change
/todos-example/node_modules/dynamodb-localhost/dynamodb/config.json
download_url
value to usehttps
. -
Change all references of
http
in here:/home/harry/projects/aws-serverless-example/todos-example/node_modules/dynamodb-localhost/dynamodb/installer.js
to behttps
. -
Then you should be able to successfully run
npx sls dynamodb install
. -
You will also need to install the Java Rumtime > v6. I used:
sudo apt install openjdk-11-jre-headless
.