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.
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 | |
Choice | |
Shuffle | |
Weather | |
News |
The news was originally taken from the RSS of Yahoo NEWS, but Google NEWS was replaced because some thumbnail images could be taken.
-[] 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.
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.
--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