How to use AWS Lambda

AWS Lambda is a serverless computing service provided by Amazon web services (AWS). Lambda allows you to run code in response to events and pay only for the compute time consumed.

canvasAnimation-image
1 of 6

How to use AWS Lambda

  1. Sign in to your AWS console. Search for AWS Lambda and open it. Click on the "Create a function" button.

AWS Lambda window
AWS Lambda window

  1. There you will have three options to choose from.

  • Create from scratch: This option allows you to start from the start and write your code directly in the lambda console or upload a deployment package.

  • Use a blueprint: This provides you with pre-built templates for common use cases. It includes sample codes which you can change accordingly.

  • Container image: This allows you to run functions using container images. You can package your entire application into a container image.

Creating a lambda function
Creating a lambda function
  1. Let's choose the "Use a blueprint" option. Search hello world in the blueprint name tab. Select hello world with Python 3.7. Give your function a name. Choose the roles for your function.

Creating a lambda function
Creating a lambda function
  1. Scroll down to view the default code written already. Click on create function.

Creating a lambda function
Creating a lambda function
  1. Your function will be created successfully. Let's test the function. Click directly on the test or select actions and choose a test from the drop-down menu. You can also view the code of the function.

Testing the lambda function
Testing the lambda function
  1. On clicking the test button, the following window opens. Give this event a name and click on test.

Testing the lambda function
Testing the lambda function
  1. The test was successful. You can view the details of the test by selecting details.

View results for a successful execution of lambda function
View results for a successful execution of lambda function
  1. You can view the logs on the CloudWatch console.

Viewing logs on CloudWatch
Viewing logs on CloudWatch
  1. Let's try changing the code and testing it. Comment line 11 and uncomment line 12. When done with changes, click deploy to save the changes. Then test it.

Applying changes in code and saving it
Applying changes in code and saving it
  1. The execution will be unsuccessful. You can view the details by selecting details.

Results of a failed lamda function test
Results of a failed lamda function test

Free Resources

Copyright ©2024 Educative, Inc. All rights reserved