LocalStack Serverless API examples that actually work
- install LocalStack
- install LocalStack Serverless
- got to first directory
cd 1 - minimal example
- install loacalstack serverless node package
npm i
- in one terminal spin up container
docker-compose up
\ - in another terminal deploy the serverless stack
serverless deploy --stage local
- To see if the api is up and running
awslocal apigateway get-rest-apis
should return 1 item - Going to this URL in the brower with the correct restAPIid from the previous step
http://localhost:4566/restapis/--RestApiId--/local/_user_request_/myendpointpath
will yeld a json result with{ "message": "Go Serverless v1.0! Your function executed successfully!".....
- Try this curl command
curl http://localhost:4566/restapis/--RestApiId--/local/_user_request_/myendpointpath
cd 2 - api gateway with dynamoDB
Repeat steps 4-6- Try this curl command
curl -X get http://localhost:4566/restapis/3t34ugy0cj/local/_user_request_/animals
- Or this one
curl -X post http://localhost:4566/restapis/3t34ugy0cj/local/_user_request_/animals -H "Content-Type: application/json" -d '{"name": "bob", "age": 100, "family": "dahl"}'
cd 3 - auth
Repeat steps 4-6- Try this curl command
curl -X post --user admin:secret http://localhost:4566/restapis/--RestApiId--/local/_user_request_/basicAuth
- list lambdas
awslocal lambda list-functions
- list iam roles
awslocal iam list-roles
- get policy
awslocal lambda get-policy --function-name apidynamo-local-getAnimals