LINE BOT with Python + AWS Lambda + API Gateway

title.png

Introduced because I made a LINE BOT to play with API Gateway + AWS Lambda. I will omit how to make LINE BOT because the official documentation and Python SDK are extensive.

The source code is published on Github, so please refer to it if you like.

List of Functions

Implemented features

The news and weather commands seem to be good for the story, and it seems that acquaintances are actually using them in groups. Surprisingly, the choice command is also used quite a bit.

function State
Greeting greeting.png
Choice choice.png
Shuffle shuffle.png
Weather weather.png
News news.png

The news was originally taken from the RSS of Yahoo NEWS, but Google NEWS was replaced because some thumbnail images could be taken.

What i want to do

-[] It might be interesting to record and visualize the number of times it was called. -[] I want to manage daily reports on LINE ――It can be opened more quickly from a smartphone than Slack ――I hope you can see this somewhere

If there is such a thing, if there is something useful, I am waiting for comments.

Python Serverless Framework

From here on, it's a little technical story. With Lambda alone, you can easily handle it from the AWS CLI without using a framework, but API Gateway is quite difficult to operate with the AWS CLI. I still had the impression that it would be easier to open the AWS website in a browser and operate it manually. As the number of endpoints increases, it is difficult without a framework that can configure API Gateway well.

If you look it up, there are two popular Serverless Frameworks in Python.

Zappa

At first I looked at Zappa's code, but it's converting the Event passed from API Gateway to Lambda to WSGI Environ, and it works with WSGI frameworks like Flask and Django. After that, it seems that the file for AWS CloudFormation is generated from the URL definition of each framework at the time of deployment and the API Gateway is set.

Chalice

Unlike Zappa, Chalice does not convert to WSGI and specializes in API Gateway. The source code is easy to understand because it's not wasted. In the case of Zappa, you have to think about whether Flask's functions really work through API Gateway, but there is a sense of security that the functions described in the chalice documentation will work properly.

I tried to use Chalice this time, but the code is simple and quite easy to handle.

Summary

--I tried to make LINE BOT ――Please comment on the functions of LINE BOT, if you find it useful. --chalice very good --API Gateway can also be created quickly if it is a JSON Web API --Since the payload of request and response is limited to 10MB, please be careful if you want to upload files / images.

end

Recommended Posts

LINE BOT with Python + AWS Lambda + API Gateway
LINE BOT (Messaging API) development with API Gateway and Lambda (Python) [Part 2]
[AWS] Create API with API Gateway + Lambda
Try implementing a Cisco Spark bot with AWS Lambda + Amazon API Gateway (Python)
Create API with Python, lambda, API Gateway quickly using AWS SAM
[AWS SAM] Create API with DynamoDB + Lambda + API Gateway
[AWS] Try tracing API Gateway + Lambda with X-Ray
Amazon API Gateway and AWS Lambda Python version
AWS CDK-Lambda + API Gateway (Python)
Made "Unofficial Apple Refurbished Product Introduction" BOT with LINE Messaging API (v2) + API Gateway + lambda (python)
Python calling Google Cloud Vision API from LINE BOT via AWS Lambda
I tried to make "Sakurai-san" a LINE BOT with API Gateway + Lambda
[LINE Messaging API] Create parrot return BOT with Python
Notify HipChat with AWS Lambda (Python)
AWS Amplify + API Gateway + Lambda + Python returns a normal response
[AWS] Using ini files with Lambda [Python]
Connect to s3 with AWS Lambda Python
Easy REST API with API Gateway / Lambda / DynamoDB
Python + Selenium + Headless Chromium with aws lambda
Send images taken with ESP32-WROOM-32 to AWS (API Gateway → Lambda → S3)
[LINE Messaging API] Create a BOT that connects with someone with Python
I tried ChatOps with Slack x API Gateway x Lambda (Python) x RDS
[Python] I wrote a REST API using AWS API Gateway and Lambda.
View images on S3 with API Gateway + Lambda
Create a LINE BOT with Minette for Python
Serverless application with AWS SAM! (APIGATEWAY + Lambda (Python))
AWS CDK with Python
[AWS] I made a reminder BOT with LINE WORKS
[Python] Using Line API [1st Creation of Beauty Bot]
I made a LINE BOT with Python and Heroku
Deploy Python3 function with Serverless Framework on AWS Lambda
Create a Layer for AWS Lambda Python with Docker
I want to AWS Lambda with Python on Mac!
Procedure for creating a Line Bot on AWS Lambda
Make ordinary tweets fleet-like with AWS Lambda and Python
[Super easy] Let's make a LINE BOT with Python.
How to operate Discord API with Python (bot registration)
Use Trello API with python
Operate TwitterBot with Lambda, Python
[Python] Scraping in AWS Lambda
Use Twitter API with Python
Web API with Python + Falcon
AWS Lambda with PyTorch [Lambda import]
Play RocketChat with API / Python
Call the API with python3.
Use subsonic API with python3
[AWS] Try adding Python library to Layer with SAM + Lambda (Python)
Site monitoring and alert notification with AWS Lambda + Python + Slack
[AWS] I made a reminder BOT with LINE WORKS (implementation)
I wrote a script to create a Twitter Bot development environment quickly with AWS Lambda + Python 2.7
[Python] Make your own LINE bot
Create Awaitable with Python / C API
Get reviews with python googlemap api
Run Rotrics DexArm with python API
Text extraction with AWS Textract (Python3.6)
Face detection with Lambda (Python) + Rekognition
Print with python3 without line breaks
Write AWS Lambda function in Python
Run Python on Schedule on AWS Lambda
Hit the Etherpad-lite API with Python
[python] Read information with Redmine API