Skip to content

Commit b16c1ff

Browse files
committed
feat: enable S3 and CloudFront access logging
- add dedicated log bucket for storing access logs - configure CloudFront distribution logging to write to log bucket
1 parent 9f03e72 commit b16c1ff

1 file changed

Lines changed: 18 additions & 0 deletions

File tree

terraform/website/main.tf

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,17 @@ resource "aws_s3_bucket" "bucket" {
22
bucket = var.domain
33
}
44

5+
resource "aws_s3_bucket_logging" "bucket_logging" {
6+
bucket = aws_s3_bucket.bucket.id
7+
8+
target_bucket = aws_s3_bucket.logs.id
9+
target_prefix = "s3-access-logs/"
10+
}
11+
12+
resource "aws_s3_bucket" "logs" {
13+
bucket = "${var.domain}-logs"
14+
}
15+
516
resource "aws_s3_bucket_ownership_controls" "bucket" {
617
bucket = aws_s3_bucket.bucket.id
718
rule {
@@ -70,6 +81,13 @@ resource "aws_cloudfront_distribution" "distribution" {
7081
is_ipv6_enabled = true
7182
price_class = "PriceClass_100"
7283

84+
logging_config {
85+
include_cookies = false
86+
bucket = "${aws_s3_bucket.logs.bucket_regional_domain_name}"
87+
prefix = "cloudfront/"
88+
}
89+
90+
7391
origin {
7492
domain_name = aws_s3_bucket_website_configuration.bucket.website_endpoint
7593
origin_id = aws_s3_bucket.bucket.bucket_regional_domain_name

0 commit comments

Comments
 (0)