Giter Club home page Giter Club logo

http-crud-leads-function's Introduction

AWS Lambda/Gateway Auto Deploy Repository

The repository serves to manage the files that are deployed on AWS lambda using github actions.

‼️ This is under construction! See the todo list at the end for more details.

Table of contents

How it works.

How the AWS server works.

Within AWS we have the following components:

  • AWS DynamoDB which serves as a key pair table.
  • AWS Lambda connecting our API Gateway with DynamoDB.
  • AWS Gateway that manages access to our routes.

How does Github actions work.

The github action uploads the index.js file into AWS Lambda using the following steps:

  • Inside the .github\workflows we have the main.yml file that builds a VM inside Github, starting a ubuntu server that make the deploy.
  • The file index.js passes through NCC for unification.
  • The output dist is ziped.
  • Finnaly the ziped file is passed to AWS lambda server.

AWS access management is done using an automated IAM user to access server acess keys.

Acess to the server

Inside our API Gateway, we have the link https://g0deojz10k.execute-api.us-east-2.amazonaws.com, were we make the request to our routes.

On the DynamoDB we are going to use the following columns structure:

  • email: This is our primary key, when the put method is called it passes trought a basic validation.
  • name: The name of the user.
  • fone: It have to be numeric.
  • createdAt: When the rows was created, is automatically generated, in Epoch with ms.
  • status: Have to be "prospect" or "client". It is set do default "prospoct".
  • lastUpdatedAt: When the rows was last updated, is automatically generated, in Epoch with ms.
  • customerAt: When the status "propspect" was changed to "customer", in Epoch with ms.

‼️ Everytime the status is changed from "prospect" to "customer" the customerAt is updated.

Our api have the following routes:

GET /leads - All items

  GET /leads

Returns the items list with the following structure:

{
  "Items": [
    {
      "status": ...,
      "createdAt": ...,
      "lastUpdatedAt": ...,
      "customerAt": ...,
      "email": ...,
      "name": ...,
      "fone": ...
    }
  ],
  "Count": 1,
  "ScannedCount": 1
}

Status codes

200

PUT /leads - New item

  PUT /leads

The item must be send with the following structure:

{
  "email": ...,
  "name": ...,
  "fone": ...,
  "status": ... (optional)
}

Remembering that as dynamo uses key pair. Returns:

{
  "email": ...,
  "name": ...,
  "fone": ...,
  "createdAt": ...,
  "status": ...,
  "lastUpdatedAt": ...,
  "customerAt": ...
}

Status codes

  • 201.
  • 409, when the email is alread on DynamoDB.

GET /lead/{email} - Specific item

  GET /lead/{email}

Where email is the email of the item without the brackets. Returns the item in Dynamo with the following structure:

{
  "Item": {
    "status": ...,
    "createdAt": ...,
    "lastUpdatedAt": ...,
    "customerAt": ...,
    "email": ...,
    "name": ...,
    "fone": ...
  }
}

Status codes

DELETE /lead/{email} - Delete item

  DELETE /lead/{email}

Where email is the email of the item without the brackets.

Status codes

PATCH /lead/{email} - Update on specific columns

  PATCH /lead/{email}

On the Json body, columns can be send to update the item. It keeps all the other columns as it is on DynamoDB.

Example:

{
	"name": "much name! such easy! wow!"
}

It returns the full item:

{
  "status": ...,
  "createdAt": ...,
  "lastUpdatedAt": ...,
  "customerAt": ...,
  "email": ...,
  "name": ...,
  "fone": ...
}

Status codes

Todo

  • Put the email as id.
  • Validate email.
  • Create the created at column.
  • Create the last update at column.
  • Create status column.
  • Create an http patch method.
  • Add correct http status to each method.
  • Create Search Methods Using Parameters.

Changelog

1.2.1 28/08/2021

  • Updated readme

1.2.0 27/08/2021

  • Changed routes from item/items to lead/leads
  • Added functions to handle Dynamo
  • Added the customerAt column
  • Removed the Post method
  • Changed project structure

1.1.0 26/08/2021

  • Email now is the primary key
  • The methods now have their http status
  • Added new columns

1.0.1 25/08/2021

  • Changed the language of the project.

1.0.0 24/08/2021

  • First version of the project with basic functionality.

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.