3.9 KiB
Fleet CloudWatch Logs to GCP Pub/Sub Bridge
This module creates an AWS Lambda subscription target for a Fleet CloudWatch log group and forwards log events to a GCP Pub/Sub topic.
The Lambda function reads Google service account credentials from an existing AWS Secrets Manager secret.
Deploy this module in the same AWS region as the Fleet CloudWatch log group.
The bridge Lambda is implemented in Go and compiled during Terraform apply.
Publishing uses the official cloud.google.com/go/pubsub/v2 client library.
The Terraform execution environment must include a working go toolchain.
Usage
provider "aws" {
region = "us-east-2"
}
variable "gcp_pubsub_service_account_credentials_json" {
description = "Google service-account credentials JSON shared by the customer (for example from target-account-gcp publisher_credentials_json)."
type = string
sensitive = true
}
resource "aws_secretsmanager_secret" "gcp_pubsub_credentials" {
name = "fleet/gcp/pubsub/service-account"
}
resource "aws_secretsmanager_secret_version" "gcp_pubsub_credentials" {
secret_id = aws_secretsmanager_secret.gcp_pubsub_credentials.id
secret_string = jsonencode({
service_account_json = var.gcp_pubsub_service_account_credentials_json
})
}
module "fleet_pubsub_bridge" {
source = "github.com/fleetdm/fleet-terraform//addons/byo-cloudwatch-log-sharing/pubsub-bridge?depth=1&ref=tf-mod-addon-byo-cloudwatch-log-sharing-v1.0.0"
subscription = {
log_group_name = module.fleet.byo-vpc.byo-db.byo-ecs.logging_config["awslogs-group"]
filter_pattern = ""
}
gcp_pubsub = {
project_id = "customer-observability-prod"
topic_id = "fleet-logs"
credentials_secret_arn = aws_secretsmanager_secret.gcp_pubsub_credentials.arn
}
lambda = {
function_name = "fleet-cloudwatch-pubsub-bridge"
role_name = "fleet-cloudwatch-pubsub-bridge-role"
policy_name = "fleet-cloudwatch-pubsub-bridge-policy"
timeout = 60
memory_size = 256
batch_size = 1000
}
dlq = {
enabled = true
queue_name = "fleet-cloudwatch-pubsub-bridge-dlq"
maximum_retry_attempts = 2
maximum_event_age_in_seconds = 3600
}
alerting = {
enabled = true
sns_topic_arns = ["arn:aws:sns:us-east-2:111111111111:fleet-ops-alerts"]
period_seconds = 300
evaluation_periods = 1
datapoints_to_alarm = 1
lambda_errors_threshold = 1
dlq_visible_messages_threshold = 1
enable_ok_notifications = true
}
replayer = {
enabled = true
function_name = "fleet-cloudwatch-pubsub-bridge-replayer"
batch_size = 10
maximum_batching_window_in_seconds = 5
maximum_concurrency = 2
}
}
output "fleet_pubsub_bridge" {
value = module.fleet_pubsub_bridge
}
The referenced secret should contain either:
- A Google service-account key JSON document directly.
- A JSON object with a
service_account_jsonfield that contains the service-account key JSON.
This module uses CloudWatch alarms for notifications so alerts fire on state transitions instead of per-failed event, which avoids high-volume SNS spam during sustained failures.
A built-in SQS replayer Lambda is enabled by default and re-drives failed async events from the DLQ back to the main bridge Lambda with partial-batch failure handling.
Reprocessing Options
- Built-in automatic replay:
Use the module's default
replayersettings to continuously re-drive failed events from DLQ. - Manual/batched replay: Drain DLQ messages to S3 for analysis, then replay selected batches during controlled windows.
- Scheduled replay workflow: Use EventBridge Scheduler or Step Functions to periodically replay aged DLQ messages with rate limits and stop conditions.