Code Monkey home page Code Monkey logo

eon-demo-backend's Introduction

E-ON serverless backend for AWS

For REST API

Serverless

Install serverless CLI

$ npm i -g serverless

AWS

Install AWS CLI

$ pip3 install awscli --upgrade --user

Create serverless node starter project:

serverless install --url https://github.com/AnomalyInnovations/serverless-nodejs-starter --name my-project

Alternatively use a serverless template

$ serverless create --template aws-nodejs --path serverless-aws-nodejs

See Serverless Framework: Deploy an HTTP endpoint using NodeJS, Lambda on AWS

See Deploy a REST API using Serverless, Express and Node.js

Services

See Serverless services

Cognito user

Create User

First, we will use AWS CLI to sign up a user with their email and password.

$ aws cognito-idp sign-up \
  --region YOUR_COGNITO_REGION \
  --client-id YOUR_COGNITO_APP_CLIENT_ID \
  --username [email protected] \
  --password Passw0rd!

Now, the user is created in Cognito User Pool.

Verify user

Before the user can authenticate with the User Pool, the account needs to be verified. Let’s quickly verify the user using an administrator command.

In your terminal, run.

$ aws cognito-idp admin-confirm-sign-up \
 --region YOUR_COGNITO_REGION \
 --user-pool-id YOUR_COGNITO_USER_POOL_ID \
 --username [email protected]

Now our test user is ready.

Install and Run

Installing API dependencies

npm i

Test locally

Unit tests

See Unit Tests in Serverless

Create a New AWS Profile

See Multiple AWS profiles

Follow the steps outlined in the Create an IAM User chapter to create an IAM user in another AWS account and take a note of the Access key ID and Secret access key.

To configure the new profile in your AWS CLI use:

$ aws configure --profile newAccount

Create note

Invoke locally

$ serverless invoke local --function create --path mocks/create-event.json

If you have multiple profiles for your AWS SDK credentials, you will need to explicitly pick one.

$ AWS_PROFILE=myProfile serverless invoke local --function create --path mocks/create-event.json

Get note

Invoke locally

$ serverless invoke local --function get --path mocks/get-event.json

Update note

Invoke locally

$ serverless invoke local --function update --path mocks/update-event.json

Deployment

This is using the serverless framework. Deploys to dev stage.

serverless deploy --aws-profile <AWS_PROFILE>

Serverless will auto-generate endpoints on an API Gateway following REST conventions

Service Information
service: notes-app-api
stage: prod
region: us-east-1
api keys:
  None
endpoints:
  POST - https://ly55wbovq4.execute-api.us-east-1.amazonaws.com/prod/notes
  GET - https://ly55wbovq4.execute-api.us-east-1.amazonaws.com/prod/notes/{id}
  GET - https://ly55wbovq4.execute-api.us-east-1.amazonaws.com/prod/notes
  PUT - https://ly55wbovq4.execute-api.us-east-1.amazonaws.com/prod/notes/{id}
  DELETE - https://ly55wbovq4.execute-api.us-east-1.amazonaws.com/prod/notes/{id}
  POST - https://ly55wbovq4.execute-api.us-east-1.amazonaws.com/prod/billing
functions:
  create: notes-app-api-prod-create
  get: notes-app-api-prod-get
  list: notes-app-api-prod-list
  update: notes-app-api-prod-update

In our case, us-east-1 is our API Gateway Region and ly55wbovq4 is our API Gateway ID.

Environments

Serverless doesn’t change how you setup long lived stages. You still have the usual dev stage, prod stage. You also have the intermediate stages such as staging, qa, preprod, etc.

eon-demo-backend's People

Contributors

kristianmandrup avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.