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

配置Lambda触发器权限时CloudFormation报match方法未定义错误求助

问题原因

错误undefined method 'match' for {"Ref"=>"EventRuleName"}的核心原因是:你在AWS::Lambda::Permission的SourceArn中,用Fn::GetAtt去引用模板参数EventRuleName,但GetAtt只能作用于当前模板内定义的CloudFormation资源逻辑ID,无法通过参数中的资源名称来获取Arn。CloudFormation解析时把!Ref EventRuleName识别为一个对象,而非有效的资源引用,因此抛出错误。

解决方案

根据你的场景,分两种情况处理:

情况1:EventBridge规则和权限在同一个CloudFormation模板内

如果规则是在当前模板里定义的,直接引用规则的资源逻辑ID即可,不需要用参数传递名称。示例模板修改如下:

AWSTemplateFormatVersion: '2010-09-09'
Transform: 'AWS::Serverless-2016-10-31'
Description: ""

Parameters:
  LambdaFunctionName:
    Type: String
    Default: lambda-function1
  EventBridgeRuleRoleName:
    Type: String
    Default: EventBridgeRuleRole1
  Env:
    Type: String
  AWSTenant:
    Type: String
  TeamTag:
    Type: String
    Default: team1

Resources:
  # 先定义EventBridge规则资源
  MyEventBridgeRule:
    Type: AWS::Events::Rule
    Properties:
      Name: EventBridgeRule1 # 可根据需求用参数控制名称
      # 补充规则的其他配置(如ScheduleExpression、Targets等)

  PermissionForEvent0ToInvokeLambda:
    Type: AWS::Lambda::Permission
    Properties:
      FunctionName: !Ref LambdaFunctionName
      Action: "lambda:InvokeFunction"
      Principal: "events.amazonaws.com"
      SourceArn: !GetAtt MyEventBridgeRule.Arn

情况2:EventBridge规则在其他CloudFormation栈中

如果规则是外部栈创建的,直接传递规则的Arn作为参数,而非名称:

AWSTemplateFormatVersion: '2010-09-09'
Transform: 'AWS::Serverless-2016-10-31'
Description: ""

Parameters:
  LambdaFunctionName:
    Type: String
    Default: lambda-function1
  EventBridgeRuleRoleName:
    Type: String
    Default: EventBridgeRuleRole1
  EventRuleArn: # 新增Arn参数,直接传入规则的完整Arn
    Type: String
  Env:
    Type: String
  AWSTenant:
    Type: String
  TeamTag:
    Type: String
    Default: team1

Resources:
  PermissionForEvent0ToInvokeLambda:
    Type: AWS::Lambda::Permission
    Properties:
      FunctionName: !Ref LambdaFunctionName
      Action: "lambda:InvokeFunction"
      Principal: "events.amazonaws.com"
      SourceArn: !Ref EventRuleArn # 直接引用Arn参数

若外部栈已导出规则的Arn,也可使用!ImportValue导入:

SourceArn: !ImportValue ExportedEventRuleArn

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.29 17:01:05