Skip to content

e14-io/demo-serverless

Repository files navigation

Demo Serverless (REST API)

Get started

Install dependencies

  • Nodejs v6.5.0 or later
  • Serverless CLI v1.9.0 or later (npm i -g serverless)
  • Choose your computer provider (AWS on my case) Give serverless access to our cloud provider account so that it can create and manage resources on our behalf. For this we need to create a policy with the appropriate permissions and a user to assign those.

Create Policy

Create User

  • AWS Services -> IAM -> Users -> Create User
  • Add name and enable programmatic access
  • Link permissions to the previously created policy
  • Download the credentials csv

Setup Credentials

sls config credentials --provider aws --key key --secret secret --profile profile

Create config.yml

dev:
  DYNAMODB_LOCAL_PORT: 9200
  CRYPTO_SECRET_KEY: CRYPTO_SECRET_KEY
  JWT_SECRET: JWT_SECRET
  PROFILE: PROFILE

Generate secret using Node.js Crypto

require('crypto').randomBytes(20, (err, buffer) => {
  if (!err) {
    const token = buffer.toString('hex')
    console.log(token)
  }
})

Deploy

sls deploy

Remove

sls remove

Note: when using DeletionPolicy: Retain on the db tables as on this case, after remove, we need to clean up the tables also. Otherwise we would see an error when trying to deploy again.

Logs

  sls logs --function functionName

Local environment configuration

sls dynamodb install
sls dynamodb start
sls offline

Postman collection

https://www.getpostman.com/collections/61f4f550292769ccc83a

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published