MemberAugust 13, 2021 at 12:59 pm
A company has an application hosted in an Auto Scaling group of Amazon EC2 instances across multiple Availability Zones behind an Application Load Balancer. There are several occasions where some instances are automatically terminated after failing the HTTPS health checks in the ALB and then purges all the ephemeral logs stored in the instance. A Solutions Architect must implement a solution that collects all of the application and server logs effectively. She should be able to perform a root cause analysis based on the logs, even if the Auto Scaling group immediately terminated the instance.
What is the EASIEST way for the Architect to automate the log collection from the Amazon EC2 instances?
Add a lifecycle hook to your Auto Scaling group to move instances in the Terminating state to the Terminating:Wait state to delay the termination of unhealthy Amazon EC2 instances. Configure a CloudWatch Events rule for the EC2 Instance-terminate Lifecycle Action Auto Scaling Event with an associated Lambda function. Trigger the CloudWatch agent to push the application logs and then resume the instance termination once all the logs are sent to CloudWatch Logs.
The only thing I am not able to understand is, why Lambda is used? Can you guys please check this and clarify me?
AdministratorAugust 14, 2021 at 6:04 am
Thank you for your feedback.
Based on the answers given and the scenario, CloudWatch Events is used to monitor the terminating auto-scaling event. If that event happens, CW will invoke a Lambda function that triggers the CW agent inside the affected instance. The CW agent publishes the logs before terminating the instance.
Carlo @ Tutorials Dojo
Log in to reply.