Enable access logs for your Classic Load Balancer - Elastic Load Balancing

Enable access logs for your Classic Load Balancer

To enable access logs for your load balancer, you must specify the name of the Amazon S3 bucket where the load balancer will store the logs. You must also attach a bucket policy to this bucket that grants Elastic Load Balancing permission to write to the bucket.

Step 1: Create an S3 bucket

When you enable access logs, you must specify an S3 bucket for the access log files. The bucket must meet the following requirements.

Requirements
  • The bucket must be located in the same Region as the load balancer. The bucket and the load balancer can be owned by different accounts.

  • The only server-side encryption option that's supported is Amazon S3-managed keys (SSE-S3). For more information, see Amazon S3-managed encryption keys (SSE-S3).

To create an S3 bucket using the Amazon S3 console
  1. Open the Amazon S3 console at https://console.aws.amazon.com/s3/.

  2. Choose Create bucket.

  3. On the Create bucket page, do the following:

    1. For Bucket name, enter a name for your bucket. This name must be unique across all existing bucket names in Amazon S3. In some Regions, there might be additional restrictions on bucket names. For more information, see Bucket restrictions and limitations in the Amazon Simple Storage Service User Guide.

    2. For AWS Region, select the Region where you created your load balancer.

    3. For Default encryption, choose Amazon S3-managed keys (SSE-S3).

    4. Choose Create bucket.

Step 2: Attach a policy to your S3 bucket

Your S3 bucket must have a bucket policy that grants Elastic Load Balancing permission to write the access logs to the bucket. Bucket policies are a collection of JSON statements written in the access policy language to define access permissions for your bucket. Each statement includes information about a single permission and contains a series of elements.

If you're using an existing bucket that already has an attached policy, you can add the statement for Elastic Load Balancing access logs to the policy. If you do so, we recommend that you evaluate the resulting set of permissions to ensure that they are appropriate for the users that need access to the bucket for access logs.

Available bucket policies

The bucket policy that you'll use depends on the AWS Region of the bucket. Each expandable section below contains a bucket policy and information about when to use that policy.

This policy grants permissions to the specified log delivery service. Use this policy for load balancers in Availability Zones and Local Zones in the following Regions:

  • Asia Pacific (Hyderabad)

  • Asia Pacific (Melbourne)

  • Canada West (Calgary)

  • Europe (Spain)

  • Europe (Zurich)

  • Israel (Tel Aviv)

  • Middle East (UAE)

{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Principal": { "Service": "logdelivery.elasticloadbalancing.amazonaws.com" }, "Action": "s3:PutObject", "Resource": "arn:aws:s3:::bucket-name/prefix/AWSLogs/aws-account-id/*" } ] }

This policy grants permissions to the specified Elastic Load Balancing account ID. Use this policy for load balancers in Availability Zones or Local Zones in the Regions in the list below.

{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Principal": { "AWS": "arn:aws:iam::elb-account-id:root" }, "Action": "s3:PutObject", "Resource": "my-s3-arn" } ] }

Replace elb-account-id with the ID of the AWS account for Elastic Load Balancing for your Region:

  • US East (N. Virginia) – 127311923021

  • US East (Ohio) – 033677994240

  • US West (N. California) – 027434742980

  • US West (Oregon) – 797873946194

  • Africa (Cape Town) – 098369216593

  • Asia Pacific (Hong Kong) – 754344448648

  • Asia Pacific (Jakarta) – 589379963580

  • Asia Pacific (Mumbai) – 718504428378

  • Asia Pacific (Osaka) – 383597477331

  • Asia Pacific (Seoul) – 600734575887

  • Asia Pacific (Singapore) – 114774131450

  • Asia Pacific (Sydney) – 783225319266

  • Asia Pacific (Tokyo) – 582318560864

  • Canada (Central) – 985666609251

  • Europe (Frankfurt) – 054676820928

  • Europe (Ireland) – 156460612806

  • Europe (London) – 652711504416

  • Europe (Milan) – 635631232127

  • Europe (Paris) – 009996457667

  • Europe (Stockholm) – 897822967062

  • Middle East (Bahrain) – 076674570225

  • South America (São Paulo) – 507241528517

Replace my-s3-arn with the ARN of the location for your access logs. The ARN that you specify depends on whether you plan to specify a prefix when you enable access logs in step 3.

  • ARN example with a prefix

    arn:aws:s3:::bucket-name/prefix/AWSLogs/aws-account-id/*
  • ARN example without a prefix

    arn:aws:s3:::bucket-name/AWSLogs/aws-account-id/*
AWS GovCloud (US) Regions

This policy grants permissions to the specified Elastic Load Balancing account ID. Use this policy for load balancers in Availability Zones or Local Zones in the AWS GovCloud (US) Regions in the list below.

{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Principal": { "AWS": "arn:aws-us-gov:iam::elb:account-id:root" }, "Action": "s3:PutObject", "Resource": "my-s3-arn" } ] }

Replace elb-account-id with the ID of the AWS account for Elastic Load Balancing for your AWS account Region:

  • AWS GovCloud (US-West) – 048591011584

  • AWS GovCloud (US-East) – 190560391635

Replace my-s3-arn with the ARN of the location for your access logs. The ARN that you specify depends on whether you plan to specify a prefix when you enable access logs in step 3.

  • ARN example with a prefix

    arn:aws-us-gov:s3:::bucket-name/prefix/AWSLogs/aws-account-id/*
  • ARN example without a prefix

    arn:aws-us-gov:s3:::bucket-name/AWSLogs/aws-account-id/*
To attach a bucket policy for access logs to your bucket using the Amazon S3 console
  1. Open the Amazon S3 console at https://console.aws.amazon.com/s3/.

  2. Select the name of the bucket to open its details page.

  3. Choose Permissions and then choose Bucket policy, Edit.

  4. Update the bucket policy to grant the required permissions.

  5. Choose Save changes.

Step 3: Configure access logs

Use the following procedure to configure access logs to capture and deliver log files to your S3 bucket.

Requirements

The bucket must meet the requirements described in step 1, and you must attach a bucket policy as described in step 2. If you specify a prefix, it must not include the string "AWSLogs".

New EC2 experience
To configure access logs for your load balancer using the console
  1. Open the Amazon EC2 console at https://console.aws.amazon.com/ec2/.

  2. On the navigation pane, under Load Balancing, choose Load Balancers.

  3. Select the name of your load balancer to open its details page.

  4. On the Attributes tab, choose Edit.

  5. On the Edit load balancer attributes page, in the Monitoring section, do the following:

    1. Enable Access logs.

    2. For S3 URI, enter the S3 URI for your log files. The URI that you specify depends on whether you're using a prefix.

      • URI with a prefix: s3://bucket-name/prefix

      • URI without a prefix: s3://bucket-name

    3. Keep Logging interval as 60 minutes - default.

    4. Choose Save changes.

Old EC2 experience
To configure access logs for your load balancer using the console
  1. Open the Amazon EC2 console at https://console.aws.amazon.com/ec2/.

  2. On the navigation pane, under Load Balancing, choose Load Balancers.

  3. Select the name of your load balancer to open its details page.

  4. On the Description tab, choose Configure access logs.

  5. On the Configure access logs page, do the following:

    1. Select Enable access logs.

    2. Keep Interval as the default, 60 minutes.

    3. For S3 location, enter the S3 URI for your log files. The URI that you specify depends on whether you're using a prefix.

      • URI with a prefix: s3://bucket-name/prefix

      • URI without a prefix: s3://bucket-name

    4. Choose Save.

To configure access logs for your load balancer using the AWS CLI

First, create a .json file that enables Elastic Load Balancing to capture and deliver logs every 60 minutes to the S3 bucket that you created for the logs:

{ "AccessLog": { "Enabled": true, "S3BucketName": "my-loadbalancer-logs", "EmitInterval": 60, "S3BucketPrefix": "my-app" } }

Next, specify the .json file in the modify-load-balancer-attributes command as follows:

aws elb modify-load-balancer-attributes --load-balancer-name my-loadbalancer --load-balancer-attributes file://my-json-file.json

The following is an example response.

{ "LoadBalancerAttributes": { "AccessLog": { "Enabled": true, "EmitInterval": 60, "S3BucketName": "my-loadbalancer-logs", "S3BucketPrefix": "my-app" } }, "LoadBalancerName": "my-loadbalancer" }
To manage the S3 bucket for your access logs

Be sure to disable access logs before you delete the bucket that you configured for access logs. Otherwise, if there is a new bucket with the same name and the required bucket policy created in an AWS account that you don't own, Elastic Load Balancing could write the access logs for your load balancer to this new bucket.

Step 4: Verify bucket permissions

After access logs are enabled for your load balancer, Elastic Load Balancing validates the S3 bucket and creates a test file to ensure that the bucket policy specifies the required permissions. You can use the S3 console to verify that the test file was created. The test file is not an actual access log file; it doesn't contain example records.

To verify that Elastic Load Balancing created a test file in your S3 bucket
  1. Open the Amazon S3 console at https://console.aws.amazon.com/s3/.

  2. Select the name of the S3 bucket that you specified for access logs.

  3. Navigate to the test file, ELBAccessLogTestFile. The location depends on whether you're using a prefix.

    • Location with a prefix: my-bucket/prefix/AWSLogs/123456789012/ELBAccessLogTestFile

    • Location without a prefix: my-bucket/AWSLogs/123456789012/ELBAccessLogTestFile

Troubleshooting

Access Denied for bucket: bucket-name. Please check S3bucket permission

If you receive this error, the following are possible causes:

  • The bucket policy does not grant Elastic Load Balancing permission to write access logs to the bucket. Verify that you are using the correct bucket policy for the Region. Verify that the resource ARN uses the same bucket name that you specified when you enabled access logs. Verify that the resource ARN does not include a prefix if you did not specify a prefix when you enabled access logs.

  • The bucket uses an unsupported server-side encryption option. The bucket must use Amazon S3-managed keys (SSE-S3).