Fn::GetAtt 的无服务器 CloudFormation 模板错误实例引用未定义的资源

ann*_*iid 4 aws-cloudformation serverless-framework

我正在尝试设置一个新的存储库,但不断收到错误消息

The CloudFormation template is invalid: Template error: instance of Fn::GetAtt 
references undefined resource uatLambdaRole
Run Code Online (Sandbox Code Playgroud)

在我的 uat 阶段,但是具有完全相同格式的开发阶段工作正常。

我为每个环境都有一个资源文件。

开发者

devLambdaRole:
  Type: AWS::IAM::Role
  Properties:
    RoleName: dev-lambda-role # The name of the role to be created in aws
    AssumeRolePolicyDocument:
      Version: '2012-10-17'
      Statement:
        - Effect: Allow
          Principal:
            Service:
              - lambda.amazonaws.com
          Action: sts:AssumeRole
    ManagedPolicyArns:
      - arn:aws:iam::aws:policy/AWSLambdaFullAccess
      #Documentation states the below policy is included automatically when you add VPC configuration but it is currently bugged.
      - arn:aws:iam::aws:policy/service-role/AWSLambdaVPCAccessExecutionRole
Run Code Online (Sandbox Code Playgroud)

乌特

uatLambdaRole:
  Type: AWS::IAM::Role
  Properties:
    RoleName: uat-lambda-role # The name of the role to be created in aws
    AssumeRolePolicyDocument:
      Version: '2012-10-17'
      Statement:
        - Effect: Allow
          Principal:
            Service:
              - lambda.amazonaws.com
          Action: sts:AssumeRole
    ManagedPolicyArns:
      - arn:aws:iam::aws:policy/AWSLambdaFullAccess
      #Documentation states the below policy is included automatically when you add VPC configuration but it is currently bugged.
      - arn:aws:iam::aws:policy/service-role/AWSLambdaVPCAccessExecutionRole
Run Code Online (Sandbox Code Playgroud)

在我看来,serverless.yml我的角色被定义为

role: ${self:custom.stage}LambdaRole
Run Code Online (Sandbox Code Playgroud)

舞台设置为

custom:
  stage: ${opt:stage, self:provider.stage}
Run Code Online (Sandbox Code Playgroud)

运行serverless deploy --stage dev --verbose成功,但运行serverless deploy --stage uat --verbose失败并出现错误。谁能看到我做错了什么吗?uat 资源是直接从开发资源复制的,仅更改了阶段名称。

这是资源文件所在目录的屏幕截图 无服务器资源文件夹

Mer*_*ury 7

我遇到了同样的问题,最终我发现我的 SQS 队列名称在所有 3 个地方都不相同。SQS 名称应匹配的以下 3 个位置如下所示:

...
functions:
  mylambda:
    handler: sqsHandler.handler
    events:
      - sqs:
          arn:
            Fn::GetAtt:
              - mySqsName       #  <= Make sure that these match
              - Arn

resources:
  Resources:
    mySqsName:                  #  <= Make sure that these match
      Type: "AWS::SQS::Queue"
      Properties:
        QueueName: "mySqsName"    #  <= Make sure that these match
        FifoQueue: true
Run Code Online (Sandbox Code Playgroud)