I tried using AWS Chalice

Overview

It is a framework that can automatically deploy AWS Gateway settings and IAM roles starting from AWS Lambda.

: thought_balloon: I tried to find a framework that can create a web application using Lambda at explosive speed.

I tried using it

1. 1. Installation

$ pip install chalice

2. Set up AWS credentials

You need to configure ~ / .aws / config`` ~ / .aws / credentials. (Please refer to other articles)

3. 3. Create a new project

$ chalice new-project handson
$ cd handson

4. Confirmation of created project

$ ls -1a
./
../
.chalice/
.gitignore
app.py
requirements.txt

app.py is the main program.

from chalice import Chalice

app = Chalice(app_name='handson')

@app.route('/')
def index():
    return {'hello': 'world'}

A decoder is attached to the method, and the path set in the argument becomes the API Gateway setting.

@app.route('/XXX')

5. Local launch


$ chalice local
Serving on http://127.0.0.1:8000
Restarting local dev server.
Serving on http://127.0.0.1:8000

In another terminal, when you send a request, the string set in return of app.py will be returned.

$ curl http://127.0.0.1:8000/     
{"hello":"world"}

6. Deploy to AWS

$ chalice deploy
Creating deployment package.
Creating IAM role: handson-dev
Creating lambda function: handson-dev
Creating Rest API
Resources deployed:
  - Lambda ARN: arn:aws:lambda:ap-northeast-1:012345678900:function:handson-dev
  - Rest API URL: https://xxxxxxxxx.execute-api.ap-northeast-1.amazonaws.com/api/

When deployed, (1) IAM role (2) lambda (3) API Gateway will be created and attached.

If you want to change the stage setting, you need to add it to .chalice / config.json

.chalice/config.json


{
  "version": "2.0",
  "app_name": "chalicehandson",
  "stages": {
    "dev": {
      "api_gateway_stage": "api"
    },
    "prod": {
      "api_gateway_stage": "api-prod"
    }
  }
}

Deploy by specifying stage

$ chalice deploy --stage prod
Creating deployment package.
Reusing existing deployment package.
Creating IAM role: handson-prod
Creating lambda function: handson-prod
Creating Rest API
Resources deployed:
  - Lambda ARN: arn:aws:lambda:ap-northeast-1:01234567890000:function:handson-prod
  - Rest API URL: https://xxxxxxxxxx.execute-api.ap-northeast-1.amazonaws.com/api-prod/

7. Delete the deployed one

$ chalice delete
$ chalice delete --stage prod

Delete the one created by deployment (in this case, these three IAM roles, lambda, API Gateway)

Since Stage deploys both dev and prod, I am executing the command to delete the two.

Impressions

In the case of aws + python, it's very convenient. I'm looking forward to seeing more and more services available. After that, there are various methods of chalice and they are rounded, so it seems that the learning cost is lower than the serverless framework.

Points of concern

--When you start local, it will restart automatically when you save it. --Unlike serverless framework, you can't create a cloudformation stack. --Even if you set Stage, API Gateway will be created with a different URL --The API Gateway path is cut, but there is only one lambda to connect

reference

https://qiita.com/takeh/items/e52ad1c541a435e2b2e3 https://programmagick.com/blogs/aws_chalice_intro/ https://www.youtube.com/watch?v=u4LKbQZawaQ https://aws.github.io/chalice/index.html

Recommended Posts

I tried using AWS Chalice
I tried using parameterized
I tried using mimesis
I tried using anytree
I tried using aiomysql
I tried using Summpy
I tried using coturn
I tried using Pipenv
I tried using matplotlib
I tried using "Anvil".
I tried using Hubot
I tried using ESPCN
I tried using openpyxl
I tried AWS CDK!
I tried using Ipython
I tried using PyCaret
I tried using cron
I tried using ngrok
I tried using face_recognition
I tried using Jupyter
I tried using Heapq
I tried using doctest
I tried using folium
I tried using jinja2
I tried AWS Iot
I touched AWS Chalice
I tried using folium
I tried using time-window
I tried using AWS Rekognition's Detect Labels API
I tried using easydict (memo).
I tried face recognition using Face ++
I tried using Random Forest
I tried using BigQuery ML
I tried using Amazon Glacier
I tried using git inspector
[Python] I tried using OpenPose
I tried using magenta / TensorFlow
I tried using Slack emojinator
I tried to get an AMI using AWS Lambda
I tried using Rotrics Dex Arm # 2
I tried using Rotrics Dex Arm
I tried using GrabCut of OpenCV
I tried using Thonny (Python / IDE)
I tried reinforcement learning using PyBrain
I tried deep learning using Theano
Somehow I tried using jupyter notebook
[Kaggle] I tried undersampling using imbalanced-learn
I tried using the checkio API
[Python] I tried using YOLO v3
I tried asynchronous processing using asyncio
[AWS] I tried using EC2, RDS, Django. Environment construction from 1
I tried using Amazon SQS with django-celery
I tried using Azure Speech to Text.
I tried using Twitter api and Line api
I tried scraping
I tried playing a ○ ✕ game using TensorFlow
I tried using YOUTUBE Data API V3
I tried using Selenium with Headless chrome
I tried drawing a line using turtle
[Kaggle] I tried ensemble learning using LightGBM
I tried using PyEZ and JSNAPy. Part 2: I tried using PyEZ