Serverless Stack is a free comprehensive guide to creating full-stack serverless applications. We create a note taking app from scratch.
We rewrote the api in python.
To use this repo locally you need to have the Serverless framework installed.
$ npm install serverless -gClone this repo and install the NPM packages.
$ git clone
$ npm installRun a single API on local.
$ serverless invoke local --function list --path mocks/getEvent.jsonWhere, event.json contains the request event info and looks something like this.
{
"requestContext": {
"authorizer": {
"claims": {
"sub": "USER-SUB-1234"
}
}
}
}Finally, run this to deploy to your AWS account.
$ serverless deployThis API uses AWS Cognito for authentication. To test each endpoint you will need to create a Cognito user first:
$ aws cognito-idp sign-up \
--region YOUR_COGNITO_REGION \
--client-id YOUR_COGNITO_APP_CLIENT_ID \
--username admin@example.com \
--password Passw0rd!Veriy the newly created user:
$ aws cognito-idp admin-confirm-sign-up \
--region YOUR_COGNITO_REGION \
--user-pool-id YOUR_COGNITO_USER_POOL_ID \
--username admin@example.comNow we can hit the endpoints with the new user.
We use AWS API Gateway Test CLI to do so.
$ npx aws-api-gateway-cli-test \
--username='admin@example.com' \
--password='Passw0rd!' \
--user-pool-id='YOUR_COGNITO_USER_POOL_ID' \
--app-client-id='YOUR_COGNITO_APP_CLIENT_ID' \
--cognito-region='YOUR_COGNITO_REGION' \
--identity-pool-id='YOUR_IDENTITY_POOL_ID' \
--invoke-url='YOUR_API_GATEWAY_URL' \
--api-gateway-region='YOUR_API_GATEWAY_REGION' \
--path-template='/notes' \
--method='POST' \
--body='{"content":"hello world","attachment":"hello.jpg"}'