saanny / aws-crud

simple crud with aws serverless and dynamodb,

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Serverless application with AWS

simple serverless application with JWT authentication.

Env

You can find envs in serverless.yaml in environment section.

USER_TABLE name of users table PRODUCT_TABLE name of products table JWT_SECRET secret key for jwt JWT_EXPIRES_IN time of jwt expiration

Local development

  1. Install docker on your machine.

  2. Install DynamoDB Local sls dynamodb install , This package has issue in installing please read this github page

  3. run sls dynamodb start --migrate

  4. run sls offline start

Tests

  1. run sls offline start

  2. run npm run test on another terminal.

Deployment

Install dependencies with:

npm install

and then deploy with:

serverless deploy

After running deploy, you should see output similar to:

Deploying aws-node-express-dynamodb-api-project to stage dev (us-east-1)

✔ Service deployed to stack aws-node-express-dynamodb-api-project-dev (196s)

endpoint: ANY - https://xxxxxxxxxx.execute-api.us-east-1.amazonaws.com
functions:
  api: aws-node-express-dynamodb-api-project-dev-api (766 kB)

Note: In current form, after deployment, your API is public and can be invoked by anyone. For production deployments, you might want to configure an authorizer. For details on how to do that, refer to httpApi event docs. Additionally, in current configuration, the DynamoDB table will be removed when running serverless remove. To retain the DynamoDB table even after removal of the stack, add DeletionPolicy: Retain to its resource definition.

Routes

Register

POST /api/v1/auth/register
Parameter Type Description
first_name string Required.
last_name string Required.
email string Required.
password string Required.

Responses

{
  "status" : number,
  "message" : string,
  "data"    : object | null
  "error"   : object | null
}

Status Codes

Status Code Description
201 CREATED
400 BAD REQUEST
409 CONFLICT

Login

POST /api/v1/auth/login
Parameter Type Description
email string Required.
password string Required.

Responses

{
  "status" : number,
  "message" : string,
  "data"    : object | null
  "error"   : object | null
}

Status Codes

Status Code Description
200 OK
400 BAD REQUEST
401 `Unauthorized

Create Product

POST /api/v1/products
Parameter Type Description
Authorization string Required. provide in header authorization
name string Required.
detail string Required.

Responses

{
  "status" : number,
  "message" : string,
  "data"    : object | null
  "error"   : object | null
}

Status Codes

Status Code Description
201 CREATED
400 BAD REQUEST
401 Unauthorized

Get Product

GET /api/v1/products/:id
Parameter Type Description
Authorization string Required. provide in header authorization
id string Required. provide in query params

Responses

{
  "status" : number,
  "message" : string,
  "data"    : object | null
  "error"   : object | null
}

Status Codes

Status Code Description
200 0K
401 Unauthorized

Get Products

GET /api/v1/products
Parameter Type Description
Authorization string Required. provide in header authorization

Responses

{
  "status" : number,
  "message" : string,
  "data"    : object | null
  "error"   : object | null
}

Status Codes

Status Code Description
200 0K
401 Unauthorized

Update Product

PATCH /api/v1/products/:id
Parameter Type Description
Authorization string Required. provide in header authorization
id string Required. provide in query params
name string Required. provide in body
detail string Required. provide in body

Responses

{
  "status" : number,
  "message" : string,
  "data"    : object | null
  "error"   : object | null
}

Status Codes

Status Code Description
200 0K
404 NOT FOUND
401 Unauthorized

Delete Product

DELETE /api/v1/products/:id
Parameter Type Description
Authorization string Required. provide in header authorization
id string Required. provide in query params

Responses

{
  "status" : number,
  "message" : string,
  "data"    : object | null
  "error"   : object | null
}

Status Codes

Status Code Description
200 0K
404 NOT FOUND
401 Unauthorized

About

simple crud with aws serverless and dynamodb,


Languages

Language:JavaScript 100.0%