'Severless Error: The CloudFormation template is invalid: Template error: instance of Fn::GetAtt references undefined resource name-of-role

I am trying to deploy a service to AWS using serverless framework and keep getting the following error: Error: The CloudFormation template is invalid: Template error: instance of Fn::GetAtt references undefined resource dev-example

Here are the relevant parts of my serverless.yml file:

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/*:*:*' 

Any insights as to what is causing this error would be great!

The resources format for the custom IAM Role was created using the template here: https://www.serverless.com/framework/docs/providers/aws/guide/iam/



Solution 1:[1]

I would suggest taking a look at the serverless-pseudo-parameters plug in that can help you simplify the configurative of some of those AWS variable parameters and thereby eliminate the error you are having

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

Solution 2:[2]

In this case you just give it the name of the resource:

provider:
  name: aws
  runtime: python3.7
  memorySize: 128
  logRetentionInDays: 1
  timeout: 300 
  role: dev-example

When the role is created it will be named what you have under RoleName with the substituted values.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Gareth McCumskey
Solution 2 vallard