AWS Eventbridge with SQS Target via Terraform

Stefan Pöltl
3 min readApr 13, 2023
Decoupling via Eventbridge

In this post we will setup a pretty common architecture pattern for async data processing on AWS. Distributed applications can fire events to Eventbridge and the payload gets forwarded to a SQS queue, dependent on defined rules.

To create the infrastructure we use Terraform(IaC) with the following module:

This module is able to create an event bus that accepts events and forwards them based on defined rules to connected targets. Let’s get our hands dirty and connect a new SQS queue to the default event bus of AWS Eventbridge:

resource "aws_sqs_queue" "queue" {
name = "processing-queue"
sqs_managed_sse_enabled = false
visibility_timeout_seconds = 30 #30 seconds
message_retention_seconds = 86400 #1day
}

module "eventbridge" {
source = "terraform-aws-modules/eventbridge/aws"
version = "v1.17.1"
create_bus = false #use default bus

rules = {
processing = {
description = "Capture all processing events"
event_pattern = jsonencode({ "detail-type" : ["my/event"] })
enabled = true
}
}

targets = {…

--

--