[PYTHON] The simplest AWS Lambda implementation

Introduction

This article is for people who want to experience AWS Lambda for the time being. There are many articles for beginners such as "In cooperation with S3", There were few people who posted a surprisingly simple implementation, so I tried it this time. You can experience AWS Lambda in about 10 minutes at the earliest. image.png

Configuration diagram of the system created this time ↑
# Overall flow

① Create AWS Lambda function ↓ ② Create API Gateway, connect with AWS Lambda ↓ ③ Test

① Create AWS Lambda function

Create from scratch to create a function named test_func. The runtime can be anything, but this time I'll choose pyhon. image.png

When created, it looks like this ↓. The trigger (input to AWS Lambda) is set when the API Gateway is created, so we will not operate it yet. image.png

② Create API Gateway, connect with AWS Lambda

Build a "REST API" API Gateway. It's hard to understand, but it's not an import. image.png

Set an appropriate "API name". (This time I chose test_api.) image.png

Add a resource (like a vessel to put a method in). Select Create Resource from the Actions tab. Enter the resource name as you like and click "Create Resource". image.png

Add a method. Select Create Method from the Actions tab to add a GET method. Enter the name of the Lambda function you created earlier in "Lambda function". Since the input prediction comes out, you can choose by entering only the first letter. image.png

When you press "Save", you will be asked if you want to grant permission, so select "OK". image.png

Finally, deploy (reflect the build) the API Gateway you have created so far. At this time, you will be asked to enter the stage (the version at the time of deployment), so enter it appropriately. That's all there is to it. image.png

③ Test

Make a request to the API Gatewary created earlier with the GET method. Click "GET" on the stage you just deployed to see the URL. Click here. image.png

If "Hello from Lambda!" Is displayed as shown in the image below, it is successful. image.png

Thank you for your support.

in conclusion

Most aimed at experiencing AWS Lambda? I implemented a simple AWS Lambda. In the future, I would like to create a more complicated system based on this.

Reference site

・ AWS Lambda https://aws.amazon.com/jp/lambda/ AWS official website

· AWS API Gateway to Lambda Tutorial in Python | Build a REST API https://www.youtube.com/watch?v=uFsaiEhr1zs Most of the steps are taken. The English commentary is easier to understand than the Japanese commentary.

Recommended Posts

The simplest AWS Lambda implementation
Understanding from the mechanism Twilio # 3-1 --AWS API Gateway + Lambda implementation Walkthrough (Part 1)
[Introduction to AWS] The first Lambda is Transcribe ♪
Get the region where AWS Lambda is running
Tweet from AWS Lambda
Try AWS Lambda Destinations
[Python] Scraping in AWS Lambda
AWS Lambda with PyTorch [Lambda import]
Web scraping using AWS lambda
Using PhantomJS with AWS Lambda until displaying the html of the website
Summary if using AWS Lambda (Python)
Touch AWS Lambda environment variable support
[AWS] Create API with API Gateway + Lambda
Write AWS Lambda function in Python
Run Python on Schedule on AWS Lambda
Finding the simplest mistakes with OpenCV
Tweet WakaTime Summary using AWS Lambda
[Python] Make the function a lambda function
Try giving AWS Lambda environment variables?
Using Lambda with AWS Amplify with Go
Notify HipChat with AWS Lambda (Python)
AWS Lambda Development My Best Practices
Prepare the environment of Chainer on EC2 spot instance with AWS Lambda