-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Description
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)
- OS: Mac OS Big Sur version 11.4
sam --version
: 1.24.1