S3 server access logging
Use thelogging variable to enable server access logging on the bucket:
Partitioned log delivery
Usetarget_object_key_format to partition logs by date for easier Athena querying:
Log delivery bucket policies
The destination bucket must grant write access to the relevant service principal. The module provides toggle variables for each AWS service.attach_elb_log_delivery_policy
Allows Classic Elastic Load Balancer to write access logs. Grants permission to the ELB service account for older regions and the
logdelivery.elasticloadbalancing.amazonaws.com principal for newer regions.attach_lb_log_delivery_policy
Allows Application Load Balancer (ALB) and Network Load Balancer (NLB) to write logs via the
delivery.logs.amazonaws.com service principal.attach_cloudtrail_log_delivery_policy
Allows CloudTrail to write audit logs via the
cloudtrail.amazonaws.com service principal.attach_waf_log_delivery_policy
Allows AWS WAF to write web ACL traffic logs via the
delivery.logs.amazonaws.com service principal.attach_access_log_delivery_policy
Allows S3 server access log delivery via the
logging.s3.amazonaws.com service principal.Classic ELB log bucket
ALB/NLB log bucket
WAF log bucket
Combined log bucket (all services)
You can enable multiple policies on a single destination bucket:Scoping access log delivery
Theattach_access_log_delivery_policy supports additional conditions to restrict which source buckets and accounts can deliver logs:
| Variable | Type | Purpose |
|---|---|---|
access_log_delivery_policy_source_buckets | list(string) | List of source bucket ARNs allowed to deliver logs |
access_log_delivery_policy_source_accounts | list(string) | List of AWS account IDs allowed to deliver logs |
access_log_delivery_policy_source_organizations | list(string) | List of AWS Organization IDs allowed to deliver logs |
Scoping ALB/NLB log delivery by organization
StringEquals aws:ResourceOrgID condition to the bucket policy, restricting delivery to load balancers in the specified Organizations.
