sam local start-api not working with multiple cloudformation stacks
Description:
My application contains a Cloudformation stack for all Lambda Functions and then an API stack containing an API gateway with methods that use the functions from the Lambda Stack. The application was built using the aws-cdk and I am trying to start the API locally and curl to invoke the lambda functions via the API. Even after building the lambda functions using sam build -t /path/to/my/lambda/stack/template, starting the local API doesn't seem to find the lambda functions.
Mounting None at http://127.0.0.1:3000/matrices/{matrixId}/history [GET, OPTIONS]
and invoking via curl errors with ValueError: Function name is required. Since it's not mounting the Lambda function, that makes sense, but I'm not sure how to get it to point to the lambda function.
Steps to reproduce:
- Create a stack containing a lambda function.
- Create a stack containing an API gateway that uses the lambda function from the previous stack.
- Build the stacks and
cdk synth. - run
sam build -t /path/to/your/lambda/stack/template - run
sam local start-api -t /path/to/your/api/stack/template
Observed result:
Unable to resolve property FunctionName: OrderedDict([('Fn::ImportValue', 'Policy-Management-LambdaStack-mikebernard-blue:ExportsOutputFnGetAttPolicyManagementMatrixDownloadmikebernardblue3189B9D7Arn186F5E5B')]). Leaving as is.
Extracted Function ARN: arn:aws:lambda:us-east-1:123456789012:function:${stageVariables.MatrixDownload}
2022-02-07 16:15:11,950 | Stage variables are not supported. Ignoring integration with function ARN arn:aws:lambda:us-east-1:123456789012:function:${stageVariables.MatrixDownload}
Seems like there's an issue using stage variables but even when I put the function name in the template instead of the stage variable, I still get the first error.
Expected result:
The API template to follow references to the lambda functions and be mounted properly.
Additional environment details (Ex: Windows, Mac, Amazon Linux etc)
- OS: macOS Monterey 12.1
sam --version: 1.37.0- AWS region: us-east-1
Thanks @mikebernard for raising this issue.
Unfortunately sam local does not support handling multiple stacks right now. The API definition, and Lambda functions should be in the same stack. It also does not support nested stacks (see this issue https://github.com/aws/aws-sam-cli/issues/3306)
Duplicate of https://github.com/aws/aws-sam-cli/issues/3306 Closing.