Skip to content
No description, website, or topics provided.
JavaScript
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
user
.gitignore
README.md
package-lock.json
package.json
secret.json
serverless.yml

README.md

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

You can’t perform that action at this time.