Log Amazon EC2 Auto Scaling API calls with AWS CloudTrail - Amazon EC2 Auto Scaling

Log Amazon EC2 Auto Scaling API calls with AWS CloudTrail

Amazon EC2 Auto Scaling is integrated with AWS CloudTrail, a service that provides a record of actions taken by a user, role, or a service using Amazon EC2 Auto Scaling. CloudTrail captures all API calls for Amazon EC2 Auto Scaling as events. The calls captured include calls from the Amazon EC2 Auto Scaling console and code calls to the Amazon EC2 Auto Scaling API.

If you create a trail, you can enable continuous delivery of CloudTrail events to an Amazon S3 bucket, including events for Amazon EC2 Auto Scaling. If you don't configure a trail, you can still view the most recent events in the CloudTrail console in Event history. Using the information collected by CloudTrail, you can determine the request that was made to Amazon EC2 Auto Scaling, the IP address from which the request was made, who made the request, when it was made, and additional details.

To learn more about CloudTrail, see the AWS CloudTrail User Guide.

Amazon EC2 Auto Scaling information in CloudTrail

CloudTrail is enabled on your Amazon Web Services account when you create the account. When activity occurs in Amazon EC2 Auto Scaling, that activity is recorded in a CloudTrail event along with other Amazon Web Services events in Event history. You can view, search, and download recent events in your Amazon Web Services account. For more information, see Viewing events with CloudTrail event history.

For an ongoing record of events in your Amazon Web Services account, including events for Amazon EC2 Auto Scaling, create a trail. A trail enables CloudTrail to deliver log files to an Amazon S3 bucket. By default, when you create a trail in the console, the trail applies to all Regions. The trail logs events from all Regions in the Amazon Web Services partition and delivers the log files to the Amazon S3 bucket that you specify. Additionally, you can configure other Amazon Web Services to further analyze and act upon the event data collected in CloudTrail logs. For more information, see the following:

All Amazon EC2 Auto Scaling actions are logged by CloudTrail and are documented in the Amazon EC2 Auto Scaling API Reference. For example, calls to the CreateLaunchConfiguration, DescribeAutoScalingGroup, and UpdateAutoScalingGroup actions generate entries in the CloudTrail log files.

Every event or log entry contains information about who generated the request. The identity information helps you determine the following:

  • Whether the request was made with root or AWS Identity and Access Management (IAM) user credentials.

  • Whether the request was made with temporary security credentials for a role or federated user.

  • Whether the request was made by another service.

For more information, see the CloudTrail userIdentity element.

Understand Amazon EC2 Auto Scaling log file entries

A trail is a configuration that enables delivery of events as log files to an Amazon S3 bucket that you specify. CloudTrail log files contain one or more log entries. An event represents a single request from any source and includes information about the requested action, the date and time of the action, request parameters, and so on. CloudTrail log files aren't an ordered stack trace of the public API calls, so they don't appear in any specific order.

The following example shows a CloudTrail log entry that demonstrates the CreateLaunchConfiguration action.

{ "eventVersion": "1.05", "userIdentity": { "type": "Root", "principalId": "123456789012", "arn": "arn:aws:iam::123456789012:root", "accountId": "123456789012", "accessKeyId": "AKIAIOSFODNN7EXAMPLE", "sessionContext": { "attributes": { "mfaAuthenticated": "false", "creationDate": "2018-08-21T17:05:42Z" } } }, "eventTime": "2018-08-21T17:07:49Z", "eventSource": "autoscaling.amazonaws.com", "eventName": "CreateLaunchConfiguration", "awsRegion": "us-west-2", "sourceIPAddress": "192.0.2.0", "userAgent": "Coral/Jakarta", "requestParameters": { "ebsOptimized": false, "instanceMonitoring": { "enabled": false }, "instanceType": "t2.micro", "keyName": "EC2-key-pair-oregon", "blockDeviceMappings": [ { "deviceName": "/dev/xvda", "ebs": { "deleteOnTermination": true, "volumeSize": 8, "snapshotId": "snap-01676e0a2c3c7de9e", "volumeType": "gp2" } } ], "launchConfigurationName": "launch_configuration_1", "imageId": "ami-6cd6f714d79675a5", "securityGroups": [ "sg-00c429965fd921483" ] }, "responseElements": null, "requestID": "0737e2ea-fb2d-11e3-bfd8-99133058e7bb", "eventID": "3fcfb182-98f8-4744-bd45-b38835ab61cb", "eventType": "AwsApiCall", "recipientAccountId": "123456789012" }

With CloudWatch Logs, you can monitor and receive alerts for specific events captured by CloudTrail. The events sent to CloudWatch Logs are those configured to be logged by your trail, so make sure you have configured your trail or trails to log the event types that you are interested in monitoring. CloudWatch Logs can monitor information in the log files and notify you when certain thresholds are met. You can also archive your log data in highly durable storage. For more information, see the Amazon CloudWatch Logs User Guide and the Monitoring CloudTrail log files with Amazon CloudWatch Logs topic in the AWS CloudTrail User Guide.