Skip to content

Mario-SO/Serverless_api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

34 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Serverless Stack Demo API

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.

Usage

To use this repo locally you need to have the Serverless framework installed.

$ npm install serverless -g

Clone this repo and install the NPM packages.

$ git clone 
$ npm install

Run a single API on local.

$ serverless invoke local --function list --path mocks/getEvent.json

Where, 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 deploy

Testing endpoints

This 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.com

Now 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"}'

About

Simple serverless api. Could be use as a boilerplate for bigger projects

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages