question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Failed to deploy SAM application with reason of Template error: instance of Fn::GetAtt references undefined resource HelloWorldFunctionRole

See original GitHub issue

Desktop (please complete the following information):

  • OS: Window 10
  • VS Code version: 1.49.0(User setup)
  • AWS Toolkit extension version: AWS 1.13.0

Question

I want to deploy my HelloWorldFunction template(Generate by Hello World basic app) , I done the following:

  1. Ctrl + Shift + P
  2. AWS: Deploy SAM aplication
  3. choose template.yaml
  4. Select region
  5. Enter name for S3 bucket created
  6. Enter name of stack

Then I get this error when deploy:

Error: Error with child process: Error: Failed to create changeset for the stack: my-stack, ex: Waiter ChangeSetCreateComplete failed: Waiter encountered a terminal failure state Status: FAILED. 
Reason: Template error: instance of Fn::GetAtt references undefined resource HelloWorldFunctionRole
Deploy failed

It said undefined resource for HelloWorldFunctionRole. But I already stated the Role Arn in my HelloWorldFunction.

Here is my template.yaml:

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

  Sample SAM Template for MyLambda

# More info about Globals: https://github.com/awslabs/serverless-application-model/blob/master/docs/globals.rst
Globals:
  Function:
    Timeout: 3

Resources:
  HelloWorldFunction:
    Type: AWS::Serverless::Function # More info about Function Resource: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlessfunction
    Properties:
      CodeUri: hello_world/
      Handler: app.lambda_handler
      Runtime: python3.8
      Role: HERE I set the role arn that I created in AWS console  ** Here is what I add 
      Events:
        HelloWorld:
          Type: Api # More info about API Event Source: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#api
          Properties:
            Path: /hello
            Method: get

Outputs:
  # ServerlessRestApi is an implicit API created out of Events key under Serverless::Function
  # Find out more about other implicit resources you can reference within SAM
  # https://github.com/awslabs/serverless-application-model/blob/master/docs/internals/generated_resources.rst#api
  HelloWorldApi:
    Description: "API Gateway endpoint URL for Prod stage for Hello World function"
    Value: !Sub "https://${ServerlessRestApi}.execute-api.${AWS::Region}.amazonaws.com/Prod/hello/"
  HelloWorldFunction:
    Description: "Hello World Lambda Function ARN"
    Value: !GetAtt HelloWorldFunction.Arn
  HelloWorldFunctionIamRole:
    Description: "Implicit IAM Role created for Hello World function"
    Value: !GetAtt HelloWorldFunctionRole.Arn


All the above code is generated by AWS SAM Hello World template, I just add the Role Arn value in the field under Runtime as u see above…

What I have done:

  1. Created a role in AWS IAM Management Console.
  2. Attach policy as LambdaBasicExecutionPolicy for the role
  3. Copy Role Arn value to template.yaml as shown above

Then when deploy, I get the error as mention above.

Please give some guidance, don’t know what I missing out so far.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

8reactions
bryceitoc9commented, Sep 17, 2020

Hi @kenchoong

Could you try deleting the HelloWorldFunctionIamRole from the Output section? SAM autogenerates a role, I believe using those parameters. Removing this should let you manually set a role.

2reactions
kenchoongcommented, Sep 18, 2020

hey @bryceitoc9 ,thanks for the guidance.

It works now after delete HelloWorldFunctionIamRole from Output.

Thank you very much

Read more comments on GitHub >

github_iconTop Results From Across the Web

Template error: instance of Fn::GetAtt references undefined ...
I think you have to add the logical name of resource. Replace EventHandlerLambdaFunction to actual resource name eventHandler .
Read more >
Template error: instance of Fn::GetAtt references undefined ...
I am trying to deploy a service to AWS using serverless framework and keep getting the following error: Error: The CloudFormation template ......
Read more >
does not support attribute type arn in fn::getatt
Reason : Template error: instance of Fn::GetAtt references undefined resource HelloWorldFunctionRole ↓Layer Waiting for changeset to be created.. Error: Failed ...
Read more >
AWS SAM: Tutorial - Anto Online
A Liberal set of permissions to apply and deploy changes. For example, the AWS SAM CLI makes calls to Amazon S3 and AWS...
Read more >
Category: Amazon Web Services | itonaut.com
Simply deploy the following template via the AWS CloudFormation console. In the designer the template looks like this: Kinesis Data Stream ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found