GithubHelp home page GithubHelp logo

hayago / serverless-application Goto Github PK

View Code? Open in Web Editor NEW

This project forked from alisproject/serverless-application

0.0 2.0 0.0 1.96 MB

🍤 ALIS Media - Serverless Application

Home Page: https://alis.to

Dockerfile 0.02% Shell 0.58% Python 99.40%

serverless-application's Introduction

Serverless Application

CircleCI

This is a serverless application using AWS SAM.

Prerequisite

  • pyenv
  • aws-cli
  • docker
  • direnv

Installation

git clone https://github.com/AlisProject/serverless-application.git
cd serverless-application
pyenv install

# libraries
python -m venv venv
. venv/bin/activate
pip install -r requirements.txt
pip install -r requirements_test.txt

Environment valuables

# Create .envrc to suit your environment.
cp -pr .envrc.sample .envrc
vi .envrc # edit

# allow
direnv allow

Test

Set up dynamoDB local

Download and unzip the dynamoDB local zip in any directory

For example

$ curl -O https://s3-ap-northeast-1.amazonaws.com/dynamodb-local-tokyo/dynamodb_local_latest.tar.gz
$ tar xf ./dynamodb_local_latest.tar.gz
$ rm ./dynamodb_local_latest.tar.gz

Execute Test

# Start dynamoDB local
java -Djava.library.path=./DynamoDBLocal_lib -jar DynamoDBLocal.jar -sharedDb

# lunch docker for localstack(for MAC OS)
TMPDIR=/private$TMPDIR docker-compose up -d

# lunch docker for elasticsearch
docker run -p 9200:9200 -p 9300:9300 -e "discovery.type=single-node" docker.elastic.co/elasticsearch/elasticsearch:6.2.0

# exec
python exec_test.py

Set SSM valuables

You have to specify SSM valuables as can as possible.

Deployment via AWS Cloud Formation

Create S3 bucket

aws s3api create-bucket --bucket ${ALIS_APP_ID}-serverless-deploy-bucket \
  --create-bucket-configuration LocationConstraint=$AWS_DEFAULT_REGION

Packaging and deployment

Packaging

./packaging.sh

DynamoDB

./deploy.sh database

# Show all tables.
aws dynamodb list-tables |grep ${ALIS_APP_ID}database |sort |tr -d ' ",'

And add all of generated table names to SSM.

Master Data

Add master data to DynamoDB.

./add_master_data.sh

Cognito

./deploy.sh cognito

Specify generated Cognito User Pool ARN to SSM.

Lambda & API Gateway

You have to add SNS authentication params to SMS.

./deploy.sh function && ./deploy.sh api

You have to add RestApiArn, ApiLambdaRole and ElasticSearchEndpoint to SMS.

./deploy.sh permission 

You have to update Cognito pre authentication trigger.

# Use this script with your Cognito User Pool ID
./update_cognito_pre_auth.sh ap-northeast-XXXXXXXXXX

Specify generated ApiLambdaRole to SSM.

FYI:

Lambda & API Gateway are bunch of CloudFormation stacks. You can use the script from next time.

./deploy_api.sh

Fix API settings via a script

# Show generated Rest API ID
aws apigateway  get-rest-apis | jq '.items[] | if .name == "'${ALIS_APP_ID}'api" then .id else empty end'

# Set SERVERLESS_REST_API_ID to .envrc
direnv edit

./fix_api.sh

ElasticSearch

# Notice: This is only for production env. Unnecessary for dev env.
./deploy.sh elasticsearch

# show ElasticSearch Endpoint
aws es describe-elasticsearch-domain --domain-name ${ALIS_APP_ID}api | jq '.DomainStatus.Endpoint'

And add ElasticSearch Endpoint to SSM.

Add Your local IP to ES access policy.

python elasticsearch-setup.py $(curl https://checkip.amazonaws.com/)

Single API Lambda Function

You can deploy single function on api-template.yaml with using deploy_api_function.py script. Following example is that ArticlesRecent function is deployed.

python make_deploy_zip.py && ./deploy_api_function.py ArticlesRecent

CloudWatch Alarm

For production and staging, you should enable alarms.

./deploy.sh apialarms

serverless-application's People

Contributors

hayago avatar horike37 avatar ippei-fukamatsu avatar keillera avatar matsumatsu20 avatar narisada014 avatar sot528 avatar y-temp4 avatar yaasita avatar

Watchers

 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.