Skip to content

Commit

Permalink
Send S3 notifications in staging environment
Browse files Browse the repository at this point in the history
The S3 bucket with the CDN logs for crates.io now sends S3 notifications
to an SQS queue. This enables crates.io to start counting downloads in
the background and not as part of the request-response cycle.
  • Loading branch information
jdno committed Jan 16, 2024
1 parent a440669 commit 30afce5
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,6 @@ inputs = {
static_fastly_weight = 100

fastly_customer_id_ssm_parameter = "/staging/crates-io/fastly/customer-id"

cdn_log_event_queue_arn = "arn:aws:sqs:us-west-1:359172468976:cdn-log-event-queue"
}
6 changes: 6 additions & 0 deletions terragrunt/modules/crates-io/_terraform.tf
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,9 @@ variable "fastly_aws_account_id" {
description = "The AWS account ID that Fastly uses to write logs"
default = "717331877981"
}

variable "cdn_log_event_queue_arn" {
# See the `crates-io-logs` module
description = "ARN of the SQS queue that receives S3 notifications for CDN logs"
type = string
}
18 changes: 18 additions & 0 deletions terragrunt/modules/crates-io/s3-logs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,21 @@ resource "aws_s3_bucket_public_access_block" "logs" {
ignore_public_acls = true
restrict_public_buckets = true
}

resource "aws_s3_bucket_notification" "cdn_log_event_queue" {
bucket = aws_s3_bucket.logs.id

queue {
id = "cloudfront"
events = ["s3:ObjectCreated:*"]
queue_arn = var.cdn_log_event_queue_arn
filter_prefix = "cloudfront/"
}

queue {
id = "fastly"
events = ["s3:ObjectCreated:*"]
queue_arn = var.cdn_log_event_queue_arn
filter_prefix = "fastly-requests/"
}
}

0 comments on commit 30afce5

Please sign in to comment.