You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

AWS Event Bridge Pipe过滤规则在Terraform中导致消息无法传递

问题根源

当SQS作为EventBridge Pipe的源时,默认情况下Pipe仅将消息的body内容传递给过滤规则进行匹配。你当前发送的是纯文本消息Your message here,body中完全没有eventSource字段,因此过滤条件eventSource = ["aws:sqs"]无法匹配,所有消息都被过滤丢弃。

解决方案

根据你的需求选择以下两种方案之一:

方案一:基于消息体内容过滤

如果你希望过滤规则作用于消息body中的字段,需要发送JSON格式的消息,并确保body包含匹配字段:

  1. 修改测试命令,发送JSON结构的消息:
aws sqs send-message --queue-url https://sqs.<region>.amazonaws.com/<account>/example-source --message-body '{"eventSource": "aws:sqs"}' --region <region>
  1. 保持现有Terraform过滤规则不变,此时消息body中的eventSource字段会被过滤规则匹配,消息将正常传递到目标队列。

方案二:基于SQS消息元数据过滤

如果你希望基于SQS消息的元数据(如eventSource)进行过滤,需要配置Pipe传递包含元数据的完整事件结构:
修改Terraform中aws_pipes_pipe资源的source_parameters,添加sqs_queue_parameters并启用include_body_schema:

resource "aws_pipes_pipe" "example" {
  depends_on = [aws_iam_role_policy.source, aws_iam_role_policy.target]
  name       = "example-pipe"
  role_arn   = aws_iam_role.example.arn
  source     = aws_sqs_queue.source.arn
  target     = aws_sqs_queue.target.arn

  source_parameters {
    # 添加该配置,让Pipe传递包含元数据的完整事件
    sqs_queue_parameters {
      include_body_schema = true
    }

    filter_criteria {
      filter {
        pattern = jsonencode({
          eventSource = ["aws:sqs"]
        })
      }
    }
  }
}

配置完成后,即使发送纯文本消息,Pipe传递的事件结构中也会包含eventSource: "aws:sqs"元数据字段,过滤规则将正常匹配,消息会被传递到目标队列。

内容的提问来源于stack exchange,提问作者jdf

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.04 20:35:07