Disable ads (and more) with a membership for a one time $4.99 payment
How can you log events for instances launching or terminating in an Auto Scaling Group?
Create a CloudFormation stack to store logs
Create a Lambda function triggered by CloudWatch Events
Enable logging within the Auto Scaling Group settings
Utilize AWS CloudTrail for logging
The correct answer is: Create a Lambda function triggered by CloudWatch Events
Creating a Lambda function that is triggered by CloudWatch Events is a highly effective method for logging events related to instances launching or terminating in an Auto Scaling Group. When you create an Auto Scaling Group, AWS automatically generates CloudWatch Events for significant actions, such as instance launch and termination. By configuring a Lambda function to listen for these events, you can process and log the information as needed in real-time. This approach allows for greater flexibility and efficiency, as the Lambda function can be designed to log specific attributes of the instance events and integrate with other logging systems, such as writing to Amazon S3, DynamoDB, or sending notifications through AWS SNS. Additionally, it can handle a variety of actions beyond simple logging, such as triggering alerts or performing additional processing as required. In contrast, while AWS CloudTrail does enable logging of API calls, it is more focused on auditing specific API actions rather than real-time event logging as enabled through CloudWatch Events and Lambda. The other options, like creating a CloudFormation stack or utilizing logging settings within the Auto Scaling Group, would not directly provide the event-driven approach required for immediate logging of lifecycle events. Thus, using a Lambda function triggered by CloudWatch Events effectively captures and logs the necessary data in a dynamic and