Logging API calls for your Classic Load Balancer using AWS CloudTrail - Elastic Load Balancing

Logging API calls for your Classic Load Balancer using AWS CloudTrail

Elastic Load Balancing is integrated with AWS CloudTrail, a service that provides a record of actions taken by a user, role, or an AWS service in Elastic Load Balancing. CloudTrail captures all API calls for Elastic Load Balancing as events. The calls captured include calls from the AWS Management Console and code calls to the Elastic Load Balancing API operations. If you create a trail, you can enable continuous delivery of CloudTrail events to an Amazon S3 bucket, including events for Elastic Load Balancing. 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 Elastic Load Balancing, 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.

To monitor other actions for your load balancer, such as when a client makes a request to your load balancer, use access logs. For more information, see Access logs for your Classic Load Balancer.

Elastic Load Balancing information in CloudTrail

CloudTrail is enabled on your AWS account when you create the account. When activity occurs in Elastic Load Balancing, that activity is recorded in a CloudTrail event along with other AWS service events in Event history. You can view, search, and download recent events in your AWS account. For more information, see Viewing events with CloudTrail event history.

For an ongoing record of events in your AWS account, including events for Elastic Load Balancing, 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 AWS Regions. The trail logs events from all Regions in the AWS partition and delivers the log files to the Amazon S3 bucket that you specify. Additionally, you can configure other AWS services to further analyze and act upon the event data collected in CloudTrail logs. For more information, see the following:

All Elastic Load Balancing actions for Classic Load Balancers are logged by CloudTrail and are documented in the Elastic Load Balancing API Reference version 2012-06-01. For example, calls to the CreateLoadBalancer and DeleteLoadBalancer 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 user credentials.

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

  • Whether the request was made by another AWS service.

For more information, see the CloudTrail userIdentity element.

Understanding Elastic Load Balancing 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 log files include events for all AWS API calls for your AWS account, not just Elastic Load Balancing API calls. You can locate calls to the Elastic Load Balancing API by checking for eventSource elements with the value elasticloadbalancing.amazonaws.com. To view a record for a specific action, such as CreateLoadBalancer, check for eventName elements with the action name.

The following are example CloudTrail log records for Elastic Load Balancing for a user who created a Classic Load Balancer and then deleted it using the AWS CLI. You can identify the CLI using the userAgent elements. You can identify the requested API calls using the eventName elements. Information about the user (Alice) can be found in the userIdentity element.

Example: CreateLoadBalancer
{ "eventVersion": "1.03", "userIdentity": { "type": "IAMUser", "principalId": "AIDAJDPLRKLG7UEXAMPLE", "arn": "arn:aws:iam::123456789012:user/Alice", "accountId": "123456789012", "accessKeyId": "AKIAIOSFODNN7EXAMPLE", "userName": "Alice" }, "eventTime": "2016-04-01T15:31:48Z", "eventSource": "elasticloadbalancing.amazonaws.com", "eventName": "CreateLoadBalancer", "awsRegion": "us-west-2", "sourceIPAddress": "198.51.100.1", "userAgent": "aws-cli/1.10.10 Python/2.7.9 Windows/7 botocore/1.4.1", "requestParameters": { "subnets": ["subnet-12345678","subnet-76543210"], "loadBalancerName": "my-load-balancer", "listeners": [{ "protocol": "HTTP", "loadBalancerPort": 80, "instanceProtocol": "HTTP", "instancePort": 80 }] }, "responseElements": { "dNSName": "my-loadbalancer-1234567890.elb.amazonaws.com" }, "requestID": "b9960276-b9b2-11e3-8a13-f1ef1EXAMPLE", "eventID": "6f4ab5bd-2daa-4d00-be14-d92efEXAMPLE", "eventType": "AwsApiCall", "apiVersion": "2012-06-01", "recipientAccountId": "123456789012" }
Example: DeleteLoadBalancer
{ "eventVersion": "1.03", "userIdentity": { "type": "IAMUser", "principalId": "AIDAJDPLRKLG7UEXAMPLE", "arn": "arn:aws:iam::123456789012:user/Alice", "accountId": "123456789012", "accessKeyId": "AKIAIOSFODNN7EXAMPLE", "userName": "Alice" }, "eventTime": "2016-04-08T12:39:25Z", "eventSource": "elasticloadbalancing.amazonaws.com", "eventName": "DeleteLoadBalancer", "awsRegion": "us-west-2", "sourceIPAddress": "198.51.100.1", "userAgent": "aws-cli/1.10.10 Python/2.7.9 Windows/7 botocore/1.4.1", "requestParameters": { "loadBalancerName": "my-load-balancer" }, "responseElements": null, "requestID": "f0f17bb6-b9ba-11e3-9b20-999fdEXAMPLE", "eventID": "4f99f0e8-5cf8-4c30-b6da-3b69fEXAMPLE" "eventType": "AwsApiCall", "apiVersion": "2012-06-01", "recipientAccountId": "123456789012" }