Skip to content

yuanfux/aws-lambda-user

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

aws-lambda-user

The example shows how to use Lambda, API Gateway and DynamoDB from AWS to create a simple "Serverless" Web Service that can create user, login & access both auth-required and no-auth-required methods.

Setup

npm install

Deploy

serverless deploy

Before running serverless deploy, you have to make sure you've installed serverless and set up your credentials provider

Usage

You can sign up for a new user, login & access public / private method.

1. Sign up

request

curl -X POST https://xxxxxx.execute-api.us-west-2.amazonaws.com/dev/api/user/signup --data '{ "username": "new_user", "password": "12345678" }'

response

{
  "message": "success"
}

2. Login

request

curl -X GET 'https://xxxxxx.execute-api.us-west-2.amazonaws.com/dev/api/user/login?username=new_user&password=12345678'

response

# user the returned token to access private method
{
  "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6Im5ld191c2VyIiwiaWF0IjoxNTYxODI1NTgyfQ.Iv0ulooGayulxf_MkkpBO1xEw1gilThT62ysuz-rQE0",
  "username": "new_user"
}

3. Public method

request

curl -X GET https://xxxxxx.execute-api.us-west-2.amazonaws.com/dev/api/public

response

{
  "message": "Anyone can read this message."
}

4. Private method

request

# use the token from login
curl -X GET -H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6Im5ld191c2VyIiwiaWF0IjoxNTYxODI1NTgyfQ.Iv0ulooGayulxf_MkkpBO1xEw1gilThT62ysuz-rQE0" https://xxxxxx.execute-api.us-west-2.amazonaws.com/dev/api/private

response

{
  "message": "Hello new_user! You are allowed to read this message."
}

License

MIT

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published