GithubHelp home page GithubHelp logo

arturgrigio / serverless-aws-lambda-apigateway-vue Goto Github PK

View Code? Open in Web Editor NEW
2.0 2.0 2.0 4.01 MB

A quick demonstration of lambda + rds + API Gateway + Vue.js

JavaScript 8.90% HTML 0.11% Vue 5.16% Python 85.54% Shell 0.29%

serverless-aws-lambda-apigateway-vue's Introduction

BACKEND SETUP

1) Setting up the RDS using aws-cli

aws rds create-db-instance \
    --db-instance-identifier serverless \
    --db-instance-class db.t2.micro \
    --engine MySQL \
    --allocated-storage 5 \
    --no-publicly-accessible \
    --db-name serverless \
    --master-username serverless \
    --master-user-password YOUR_PASSWORD_HERE \
    --backup-retention-period 1

2) Create an execution role like described here:

https://docs.aws.amazon.com/lambda/latest/dg/vpc-rds-create-iam-role.html Save the ARN ID for the role

3) Update your env variables and install pymysql

  • Navigate to /setup/rds_config.example.py and update your credentials.
  • Rename the file to rds_config.example.py
  • Install pymysql: pip install pymysql -t /PATH/TO/DIRECTORY/

  • zip the YOUR_FUNCTION/app.py and rds_config.py into app.zip
    • you can use this command too cd INTO/SETUP/DIRECTORY && zip -r app.zip app.py rds_config.py pymysql

4) Setting up the Lambda using aws-cli

aws lambda create-function \
--region us-east-1 \
--function-name   serverless-get-employees  \
--zip-file fileb://YOUR_PATH_TO/app.zip \
--role execution-role-arn \
--handler app.handler \
--runtime python3.6 \
--vpc-config SubnetIds=comma-separated-subnet-ids,SecurityGroupIds=default-vpc-security-group-id \
--profile adminuser

Testing

aws lambda invoke \
--function-name serverless-get-employees  \
--region us-west-1 \
--profile YOUR_USER \
output.txt  

Repeat step 4 for each one of your lambda functions

Creating the API Gateway endpoints

Create the API gateway:

aws apigateway create-rest-api \
--name serverless \
--region us-west-1 \
--profile profile

Create a resource on the gateway:

aws apigateway create-resource \
--rest-api-id api-id \
--parent-id root-id \
--path-part employee

Create a method:

aws apigateway put-method \
--rest-api-id api-id \
--resource-id resource-id \
--http-method POST \
--authorization-type NONE

FRONTEND SETUP

1) Create the vue project

vue init webpack serverless && cd serverless && npm install

2) Build the dist for deployment

npm run build

3) Deploy on heroku instance

cd INTO YOUR YOUR/PATH/setup/frontend/setup
npm run build
git add .
git commit -a -m "Adding files."
git push heroku master

API endpoints

Host: https://iaeoli1xlg.execute-api.us-west-1.amazonaws.com/prod/

employee/get - GET

employee/add - POST

required params:

first, last, email

employee/update - POST

required params:

id, first, last, email

employee/delete - POST

required params:

id

TODO

  • Data validation in Vue using vee-validate
  • Date validation in lambda
  • Refactor Frontend
  • Deploy on S3 to solve:
    • Cold boot issue with Heroku where the api call will fail silently

serverless-aws-lambda-apigateway-vue's People

Contributors

arturgrigio avatar

Stargazers

 avatar Alexis Aceves avatar

Watchers

James Cloos 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.