Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

404
Views
Terraform Failure configuring LB attributes

I've followed the first answer on this post on StackOverflow but I obtain this error:

Failure configuring LB attributes: InvalidConfigurationRequest: Access Denied for bucket: myproject-log. Please check S3bucket permission status code: 400

This is my code:

s3_bucket

data "aws_elb_service_account" "main" {}

resource "aws_s3_bucket" "bucket_log" {
  bucket = "${var.project}-log"
  acl    = "log-delivery-write"

policy = <<POLICY
{
  "Id": "Policy",
  "Version": "2012-10-17",
  "Statement": [
    {
      "Action": [
        "s3:PutObject"
      ],
      "Effect": "Allow",
      "Resource": "arn:aws:s3:::${var.project}-log/AWSLogs/*",
      "Principal": {
        "AWS": [
          "${data.aws_elb_service_account.main.arn}"
        ]
      }
    }
  ]
}
POLICY

}

load balancer

resource "aws_lb" "vm_stage" {
  name = "${var.project}-lb-stg"
  internal           = false
  load_balancer_type = "application"
  subnets         = [aws_subnet.subnet_1.id, aws_subnet.subnet_2.id, aws_subnet.subnet_3.id]
  security_groups = [aws_security_group.elb_project_stg.id]
  access_logs {
    bucket  = aws_s3_bucket.bucket_log.id
    prefix  = "lb-stg"
    enabled = true
  }
  tags = {
    Name = "${var.project}-lb-stg"
  }
}
over 4 years ago · Santiago Trujillo
3 answers
Answer question

0

Just going to drop this here since this cross applied to another question that was asked.

This took me awhile to figure out, but the S3 bucket has two requirements per the documentation:

  • The bucket must be located in the same Region as the load balancer.
  • Amazon S3-Managed Encryption Keys (SSE-S3) is required. No other encryption options are supported.

Source: https://docs.aws.amazon.com/elasticloadbalancing/latest/classic/enable-access-logs.html

While it makes it seem like it's a permissions issue with the error message given it may actually be an issue with the bucket having the wrong encryption type. In my case the issue was that my bucket was unencrypted.

Updated the bucket to SSE-S3 encryption and I no longer received the error:

resource "aws_s3_bucket" "s3_access_logs_bucket" {
  bucket = var.access_logs_bucket_name
  acl = "private"
  server_side_encryption_configuration {
    rule {
      apply_server_side_encryption_by_default {
        sse_algorithm = "AES256"
      }
    }
  }

  versioning {
    enabled = true
  }

}

And just because, here's the policy I used:

data "aws_elb_service_account" "main" {}


data "aws_iam_policy_document" "s3_lb_write" {
  statement {
    principals {
      identifiers = ["${data.aws_elb_service_account.main.arn}"]
      type = "AWS"
    }

    actions = ["s3:PutObject"]

    resources = [
      "${aws_s3_bucket.s3_access_logs_bucket.arn}/*"
    ]
  }
}

resource "aws_s3_bucket_policy" "load_balancer_access_logs_bucket_policy" {
  bucket = aws_s3_bucket.s3_access_logs_bucket.id
  policy = data.aws_iam_policy_document.s3_lb_write.json
}
over 4 years ago · Santiago Trujillo Report

0

Official AWS Docs

https://docs.aws.amazon.com/elasticloadbalancing/latest/classic/enable-access-logs.html

Solution

Reference the docs above and change your bucket's iam policy to reflect what the documentation states. The logging is actually done by AWS and not your roles or IAM users. So you need to give ÅWS permission to do this. That's why the docs show statements in the policy that specify the delivery.logs.amazonaws.com principal. That principal is the AWS logging service. Even though your bucket is hosted on AWS, they don't give themselves access to your bucket by default. You have to explicitly grant access to AWS if you want their services to work.

over 4 years ago · Santiago Trujillo Report

0

As per this post, I was able to resolve this issue by disabling KMS and using SSE-S3 for bucket encryption. Also, there are additional permissions listed in the AWS docs.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!