With AWS Lambda, you simply write code in its format, publish it to AWS, and it runs without a server, hosted entirely by Amazon. They charge per run, and they’re super cheap. That way, there is no need to purchase EC2 up front. Lambda takes care of everything needed to run and extend high availability code. Code can be set to trigger from S3, Kinesis, or directly invoked from any Web or mobile application.

In fact, this is the concept of serverless

Below, use examples to illustrate how to develop a lambda program

Create a function


1, log in https://console.aws.amazon.com/lambda/home?region=us-east-1#/functions to manage the background

2. An easy way to start is to select a blueprint. Select an example template, type “S3” in the search box, and select s3-get-object-python

3. Fill in name and role name

4. Select S3 buckets to listen to

5. Create successfully, as shown in the following figure

Lambda provides three ways to edit code. When the code is simpler, it can be edited directly using its online editor. When the project is large and needs to rely on many third-party packages, it is necessary to upload compressed packages

7, S3 trigger switch, when our program is ready, turn this switch on. Then remember to click the save button in the upper right corner

Run the function


1, upload a file named lambda-test. TXT to S3

2. Go back to the lambda background and click Monitoring to open the monitoring page. You can see that the lambda function is called once, running in about 200 milliseconds. Click on any “jump to Log” to go to the next page to see the specific log

3. Select the log for the last 5 minutes and you will see the output of “CONTENT TYPE”, which is the output of the print statement in the Python code

conclusion

A simple lambda program is now complete, but more and more functions need to be learned in order to get the most out of lambda