Files
fleet-terraform/addons/byo-cloudwatch-log-sharing/pubsub-bridge

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_json field 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

  1. Built-in automatic replay: Use the module's default replayer settings to continuously re-drive failed events from DLQ.
  2. Manual/batched replay: Drain DLQ messages to S3 for analysis, then replay selected batches during controlled windows.
  3. Scheduled replay workflow: Use EventBridge Scheduler or Step Functions to periodically replay aged DLQ messages with rate limits and stop conditions.

Requirements

Name Version
terraform >= 1.3.7
archive >= 2.4.0
aws >= 5.29.0
null >= 3.2.1

Providers

Name Version
archive >= 2.4.0
aws >= 5.29.0
null >= 3.2.1

Modules

No modules.

Resources

Name Type
aws_cloudwatch_log_group.bridge resource
aws_cloudwatch_log_group.replayer resource
aws_cloudwatch_log_subscription_filter.bridge resource
aws_cloudwatch_metric_alarm.dlq_visible_messages resource
aws_cloudwatch_metric_alarm.lambda_errors resource
aws_cloudwatch_metric_alarm.replayer_errors resource
aws_iam_policy.bridge resource
aws_iam_policy.replayer resource
aws_iam_role.bridge resource
aws_iam_role.replayer resource
aws_iam_role_policy_attachment.bridge resource
aws_iam_role_policy_attachment.lambda_basic_execution resource
aws_iam_role_policy_attachment.replayer resource
aws_iam_role_policy_attachment.replayer_lambda_basic_execution resource
aws_lambda_event_source_mapping.replayer resource
aws_lambda_function.bridge resource
aws_lambda_function.replayer resource
aws_lambda_function_event_invoke_config.bridge resource
aws_lambda_permission.allow_cloudwatch_logs resource
aws_sqs_queue.dlq resource
null_resource.bridge_build resource
null_resource.replayer_build resource
archive_file.bridge data source
archive_file.replayer data source
aws_caller_identity.current data source
aws_iam_policy_document.bridge data source
aws_iam_policy_document.lambda_assume_role data source
aws_iam_policy_document.replayer data source
aws_partition.current data source
aws_region.current data source

Inputs

Name Description Type Default Required
alerting CloudWatch alarm and SNS notification settings for bridge failures.
object({
enabled = optional(bool, true)
sns_topic_arns = optional(list(string), [])
enable_ok_notifications = optional(bool, true)
period_seconds = optional(number, 300)
evaluation_periods = optional(number, 1)
datapoints_to_alarm = optional(number, 1)
lambda_errors_threshold = optional(number, 1)
dlq_visible_messages_threshold = optional(number, 1)
})
{} no
dlq Asynchronous Lambda failure handling via SQS dead-letter queue.
object({
enabled = optional(bool, true)
queue_name = optional(string)
maximum_retry_attempts = optional(number, 2)
maximum_event_age_in_seconds = optional(number, 3600)
message_retention_seconds = optional(number, 1209600)
visibility_timeout_seconds = optional(number, 60)
sqs_managed_sse_enabled = optional(bool, true)
kms_master_key_id = optional(string, "")
})
{} no
gcp_pubsub GCP Pub/Sub settings and credentials secret reference for cloud.google.com/go/pubsub/v2. The secret must contain a Google service-account key JSON, or a JSON object with a service_account_json field containing that key JSON.
object({
project_id = string
topic_id = string
credentials_secret_arn = string
secret_kms_key_arn = optional(string, "")
})
n/a yes
lambda Go-based Lambda bridge configuration.
object({
function_name = optional(string, "fleet-cloudwatch-pubsub-bridge")
role_name = optional(string, "fleet-cloudwatch-pubsub-bridge-role")
policy_name = optional(string)
runtime = optional(string, "provided.al2")
architecture = optional(string, "x86_64")
memory_size = optional(number, 256)
timeout = optional(number, 60)
log_retention_in_days = optional(number, 30)
reserved_concurrent_executions = optional(number, -1)
batch_size = optional(number, 1000)
})
{} no
replayer SQS DLQ replayer settings. Replays failed bridge events back to the main bridge Lambda.
object({
enabled = optional(bool, true)
function_name = optional(string)
role_name = optional(string)
policy_name = optional(string)
runtime = optional(string)
architecture = optional(string)
memory_size = optional(number, 256)
timeout = optional(number, 60)
log_retention_in_days = optional(number, 30)
reserved_concurrent_executions = optional(number, -1)
batch_size = optional(number, 10)
maximum_batching_window_in_seconds = optional(number, 5)
maximum_concurrency = optional(number, 2)
})
{} no
subscription CloudWatch Logs subscription settings for sending Fleet log events to the Pub/Sub bridge Lambda.
object({
log_group_name = string
log_group_arn = optional(string)
filter_name = optional(string, "fleet-log-pubsub-bridge")
filter_pattern = optional(string, "")
})
n/a yes
tags Tags to apply to created resources that support tags. map(string) {} no

Outputs

Name Description
alerting CloudWatch alarm and notification resources for bridge health.
dlq Dead-letter queue configuration and resource details.
lambda Lambda bridge details.
pubsub Configured GCP Pub/Sub destination details.
replayer DLQ replayer Lambda and event source mapping details.
subscription_filter CloudWatch Logs subscription filter details.