6 Automating operational tasks with Lambda

 

This chapter covers

  • Creating a Lambda function to perform periodic health checks of a website
  • Triggering a Lambda function with EventBridge events to automate DevOps tasks
  • Searching through your Lambda function’s logs with CloudWatch
  • Monitoring Lambda functions with CloudWatch alarms
  • Configuring IAM roles so Lambda functions can access other services

This chapter is about adding a new tool to your toolbox. The tool we’re talking about, AWS Lambda, is as flexible as a Swiss Army knife. You don’t need a virtual machine to run your own code anymore, because AWS Lambda offers execution environments for C#/.NET Core, Go, Java, JavaScript/Node.js, Python, and Ruby. All you have to do is implement a function, upload your code, and configure the execution environment. Afterward, your code is executed within a fully managed computing environment. AWS Lambda is well integrated with all parts of AWS, enabling you to easily automate operations tasks within your infrastructure. We use AWS to automate our infrastructure regularly, such as to add and remove instances to a container cluster based on a custom algorithm and to process and analyze log files.

6.1 Executing your code with AWS Lambda

6.1.1 What is serverless?

6.1.2 Running your code on AWS Lambda

6.1.3 Comparing AWS Lambda with virtual machines (Amazon EC2)

6.2 Building a website health check with AWS Lambda

6.2.1 Creating a Lambda function

6.2.2 Use CloudWatch to search through your Lambda function’s logs

6.2.3 Monitoring a Lambda function with CloudWatch metrics and alarms

6.2.4 Accessing endpoints within a VPC

6.3 Adding a tag containing the owner of an EC2 instance automatically

6.3.1 Event-driven: Subscribing to EventBridge events

6.3.2 Implementing the Lambda function in Python

6.3.3 Setting up a Lambda function with the Serverless Application Model (SAM)

6.3.5 Deploying a Lambda function with SAM