Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nested Application parameters are not being passed when running sam local start-api #2949

Closed
benjaminfiliatrault opened this issue Jun 11, 2021 · 3 comments
Labels
blocked/close-if-inactive Blocked for >14 days with no response, will be closed if still inactive after 7 days

Comments

@benjaminfiliatrault
Copy link

benjaminfiliatrault commented Jun 11, 2021

Description:

Let's expected the current resources:

./template.yml

AWSTemplateFormatVersion: 2010-09-09
Transform:
    - AWS::Serverless-2016-10-31

Resources:
    APIGateway:
        Type: AWS::Serverless::Api

    LambdaRole:
        Type: AWS::IAM::Role

    MyNestedLambdasA:
        Type: AWS::Serverless::Application
        Properties:
            Location: ./templates/nestedTemplateA.yml
            Parameters:
                privateAPIGateway: !Ref APIGateway
                lambdaRole: !GetAtt LambdaRole.Arn    

./templates/nestedTemplateA.yml

AWSTemplateFormatVersion: 2010-09-09
Transform:
    - AWS::Serverless-2016-10-31

Parameters:
    privateAPIGateway:
        Type: String
    lambdaRole:
        Type: String

Resources:
    HelloWorldLambda:
        Type: AWS::Serverless::Function
        Properties:
            FunctionName: hello-world
            CodeUri: ./handlers/
            Handler: hello-world.handler
            Role: !Ref lambdaRole
            Events:
                Get:
                    Type: Api
                    Properties:
                        RestApiId: !Ref privateAPIGateway
                        Path: /hello/world
                        Method: GET

I want to be able to put the API Gateway and the Role of the microservice in the root template.yml because all the lambdas that will be nested will use the same basic execution role and the same API Gateway.

The goal of nested the lambdas like that is for the readability. Imagine a service which offer 10 features that each feature have at least 1 lambda per CRUD operation, that's already 40 AWS::Serverless::Function which take about 20 lines with all the properties.

Observed result:

When running sam local start-api --warm-containers EAGER --skip-pull-image I get the following error

Error: [InvalidResourceException('HelloWorldLambda', "Event with id [Get] is invalid. RestApiId must be a valid reference to an 'AWS::Serverless::Api' resource in same template.")

Expected result:

The expected result is that the !Ref parameters is passed down in the nested stack to be used just as if I would have !Ref it from the template root itself.

Additional environment details (Ex: Windows, Mac, Amazon Linux etc)

  1. OS: Mac OS Big Sur version 11.4
  2. sam --version: 1.24.1
@benjaminfiliatrault benjaminfiliatrault changed the title Nested Application parameters are not being passed. Nested Application parameters are not being passed when running sam local start-api Jun 11, 2021
@mndeveci mndeveci added the blocked/more-info-needed More info is needed from the requester. If no response in 14 days, it will become stale. label Jun 15, 2021
@mndeveci
Copy link
Contributor

Thanks for reporting this.

What happens if you only have root template, and you have a parameter to point to ApiGW definition and you pass that parameter outside. Would that succeed to build?

@moelasmar moelasmar added blocked/close-if-inactive Blocked for >14 days with no response, will be closed if still inactive after 7 days and removed blocked/more-info-needed More info is needed from the requester. If no response in 14 days, it will become stale. labels Jul 19, 2021
@xazhao
Copy link
Contributor

xazhao commented Aug 11, 2021

Closing this because it has been inactive for 24 days.

@xazhao xazhao closed this as completed Aug 11, 2021
@github-actions
Copy link
Contributor

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
blocked/close-if-inactive Blocked for >14 days with no response, will be closed if still inactive after 7 days
Projects
None yet
Development

No branches or pull requests

4 participants