I'm following these instructions from AWS to try to add access logs to my application load balancer.
Precisely the policies described at the Bucket permissions
-> To prepare an Amazon S3 bucket for access logging
-> point 5
Unfortunately when I add the policy it returns 'MalformedPolicy: Invalid policy syntax"
Can anyone point me in the right direction with this?
Policy data:
data "aws_iam_policy_document" "allow-lb-aws" {
statement {
principals {
type = "service"
identifiers = ["logdelivery.elb.amazonaws.com"]
}
actions = [
"s3:PutObject",
"s3:ListBucket",
]
resources = [
"arn:aws:s3:::${aws_s3_bucket.lb-logs.bucket}/main-lb/AWSLogs/652711504416/*"
]
}
}
In the console, this shows up as:
+ resource "aws_s3_bucket_policy" "allow-lb-aws" {
+ bucket = "<my-bucket-name>"
+ id = (known after apply)
+ policy = jsonencode(
{
+ Statement = [
+ {
+ Action = [
+ "s3:PutObject",
+ "s3:ListBucket",
]
+ Effect = "Allow"
+ Principal = {
+ service = "logdelivery.elb.amazonaws.com"
}
+ Resource = "arn:aws:s3:::<my bucket name>/main-lb/AWSLogs/<europe-west-2-listed-account>/*"
+ Sid = ""
},
]
+ Version = "2012-10-17"
}
)
}