Which solution achieves these goals MOST efficiently?
Use a scheduled AWS Lambda function and run a script remotely on all EC2 instances to send data to the audit system.
Use EC2 Auto Scaling lifecycle hooks to run a custom script to send data to the audit system when instances are launched and terminated.
Use an EC2 Auto Scaling launch configuration to run a custom script through user data to send data to the audit system when instances are launched and terminated.
Run a custom script on the instance operating system to send data to the audit system. Configure the script to be invoked by the EC2 Auto Scaling group when the instance starts and is terminated.
Explanations:
Using a scheduled AWS Lambda function would not provide immediate reporting upon instance launch and termination, as it relies on a scheduled run instead of being event-driven. Additionally, it involves remote script execution, which can introduce complexity and potential delays.
EC2 Auto Scaling lifecycle hooks allow for the execution of a custom script when instances are launched or terminated. This ensures that data is sent to the auditing system immediately, making it efficient and tightly integrated with the lifecycle of the instances.
While user data can run a script at instance launch, it does not handle instance termination reporting effectively, as user data is only executed during the launch phase. This option does not fulfill the requirement of sending data upon termination.
Running a custom script on the instance operating system can be done, but configuring it to trigger automatically upon both instance start and termination is not straightforward. It requires additional configuration and may not integrate seamlessly with the Auto Scaling lifecycle.