AWS Lambda
Overview
AWS Lambda is a compute service that lets us run code without provisioning or managing servers. It allows us to run isolated code on high-availability compute infrastructure and performs administration of the compute resources.
How does it work?
AWS Lambda runs code in response to events such as HTTP requests, or IoT events. When an event occurs, AWS Lambda automatically provisions the necessary compute resources to run your code. It then executes your code in a secure and isolated environment.
Lambda automatically scales your functions in response to the incoming request rate. It can handle multiple requests simultaneously, allowing you to run highly scalable applications without worrying about infrastructure management.
How did we develop a Lambda function?
-
Go to the AWS Lambda console and click on “Create function”.
-
Select “Author from scratch” and fill in the following information:
-
Go to the Code tab. Develop source code in the code editor or upload a .zip file containing the code for the Lambda function
-
Go to the Configuration tab and customize the configuration settings if needed
How did we deploy a Lambda function?
- After we had finalized the source code and configuration of the Lambda function, we added the source code to GitHub repository for version control.
cloud-2023
is the GitHub repositorysrc/lambda_functions
is the directory that contains the source code for the Lambda functions, and the correspondingrequirements.txt
file that defines the dependencies for the Lambda functions
- GitHub Actions would then zip the source code, upload it to an S3 bucket, and use CloudFormation to create a new instance of Lambda function with the uploaded source code in the S3 bucket.
.github/workflows/deploy_lambda.yml
is the GitHub Actions workflow that deploys the Lambda function. The name of the Lambda function has to be included innames_of_lambdas_for_deployment
in theDeploy changes of Lambda functions
stepsrc/cloudformation/lambda_function.yml
is the CloudFormation template that defines the configuration settings for the Lambda function- The naming convention of the Lambda function is
yvr-stage-{function_name}
. For example,yvr-stage-calibration-lambda-function
is the name of the Lambda function for calibration. - The configuration settings for the Lambda function were specified in the CloudFormation template, for example environment variables
- The benefit of using CloudFormation to deploy the Lambda function is that it allows us to easily provision and manage instances of the Lambda function, along with other necessary resources such as IAM roles and CloudWatch logs. It also allows us to easily update or rollback the Lambda function if needed.
Current Usage
Lambda Function Name | Description |
---|---|
yvr-stage-calibration | Calibrates the incoming data from device and stores it to Timestream |
yvr-stage-device | Performs CRUD operation of device configuration data in DynamoDB and publishes the device configuration changes to an IoT topic |
yvr-stage-user | Performs CRUD operation of user data in DynamoDB |
yvr-stage-cognito-get-users-info | Uses the AWS Cognito API to get user information |
yvr-stage-cognito-get-role | Uses the AWS Cognito API to get user role |
yvr-stage-cognito-add-update-delete-user | Uses the AWS Cognito API to add, update, or delete a user |