首页 > 解决方案 > 模板错误:Fn::GetAtt 实例引用未定义资源 EventHandlerLambdaFunction

问题描述

谁能帮我找出问题所在?

我在我的无服务器 yml 中导入了这个 cloudformation 资源。这是我的功能配置:

Resources:
  eventHandler:
    Type: AWS::Serverless::Function
    Properties:
      CodeUri: eventLambda/
      Handler: dist/app.eventHandler
      Runtime: nodejs12.x
      FunctionName: eventHandler

这是我引用它的地方:

eventSourceRule:
    Type: 'AWS::Events::Rule'
    Properties:
      Name: eventSourceRule
      EventBusName: omnibus-${self:custom.stage}
      EventPattern: |
        {
          "source": ["op.api"]
        }
      RetryPolicy:
        MaximumRetryAttempts: 5
        MaximumEventAgeInSeconds: 900
      DeadLetterConfig:
        Type: SQS
        QueueLogicalId: EBRuleDLQ
      Targets:
        - Arn:
            Fn::GetAtt:
              - 'EventHandlerLambdaFunction'
              - 'Arn'
          Id: 'eventSourceRule'

请注意,我已经尝试过eventHandlerEventHandler但这些都不起作用。这就是我收到的错误:

The CloudFormation template is invalid: Template error: instance of Fn::GetAtt references undefined resource EventHandlerLambdaFunction

标签: amazon-web-servicesresourcesamazon-cloudformationserverless

解决方案


我认为您必须添加 资源的逻辑名称。
替换EventHandlerLambdaFunction为实际资源名称eventHandler
您没有使用您定义的 Lambda 资源的逻辑名称。


您可以尝试使用简单的 YAML 语法:

Targets:
  - Arn: !GetAtt eventHandler.Arn

参考:Fn::GetAtt AWS 文档


推荐阅读