严重错误:CloudFormation模板无效:模板错误:Fn :: GetAtt实例引用未定义资源角色

时间:2020-05-13 17:58:36

标签: yaml amazon-iam serverless-framework serverless aws-serverless

我正在尝试使用无服务器框架将服务部署到AWS并不断出现以下错误:Error: The CloudFormation template is invalid: Template error: instance of Fn::GetAtt references undefined resource dev-example

这是我的serverless.yml文件的相关部分:

service: example 

provider:
  name: aws
  runtime: python3.7
  memorySize: 128
  logRetentionInDays: 1
  timeout: 300 
  role: ${opt:stage}-${self:service}

  resources:
    Resources:
      dev-example:
        Type: AWS::IAM::Role
        Properties:
          RoleName: ${opt:stage}-${self:service}-role
          AssumeRolePolicyDocument:
            Version: '2020-05-13'
            Statement:
              - Effect: Allow
                Principal:
                  Service:
                    - lambda.amazonaws.com
                Action: 'sts:AssumeRole' 
          ManagedPolicyArns:
            - arn:aws:iam::aws:policy/service-role/AWSLambdaVPCAccessExecutionRole
            - arn:aws:iam::aws:policy/AmazonRDSDataFullAccess
            - arn:aws:iam::aws:policy/AmazonS3ReadOnlyAccess
            - arn:aws:iam::aws:policy/service-role/AWSLambdaRole
          Policies:
            - PolicyName: ${opt:stage}-${self:service}-policies
              PolicyDocument:
                Version: '2020-05-13'
                Statement:
                  - Effect: Allow
                    Action: 
                      - logs:CreateLogGroups
                      - logs:CreateLogStream
                      - logs:PutLogEvents
                    Resource:
                      - 'Fn::Join':
                        - ':'
                        -
                          - 'arn:aws:logs'
                          - Ref: 'AWS::Region'
                          - Ref: 'AWS::AccountId'
                          - 'log-group:/aws/lambda/*:*:*' 

关于导致此错误的原因的任何见解都会很棒!

使用以下模板创建自定义IAM角色的资源格式:https://www.serverless.com/framework/docs/providers/aws/guide/iam/

1 个答案:

答案 0 :(得分:0)

我建议看一下无服务器伪参数插件,它可以帮助您简化某些AWS变量参数的配置,从而消除您遇到的错误

https://www.serverless.com/plugins/serverless-pseudo-parameters/