Description:
When a Python Lambda is defined within a Nested Stack and referenced from template.yaml, sam build fails to build dependecies defined in requirements.txt
This means that Lambdas fail to execute due to missing dependecies.
Steps to reproduce the issue:
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Globals:
Function:
Timeout: 3
Parameters:
ResolverNameParam:
Type: String
ApiIdParam:
Type: String
LambdaHandlerMethodParam:
Type: String
Resources:
LambdaResolverFunction:
Type: AWS::Serverless::Function
Properties:
CodeUri: src
Handler: myhandler
Runtime: python3.7
Tracing: Active
template.yaml:
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Globals:
Function:
Timeout: 3
Resources:
MyLambda:
Type: AWS::CloudFormation::Stack
Properties:
TemplateURL: lambda.yaml
src/requirements.txt
requests
src/test.py
def myhandler(event, context):
print(event)
sam build
Build Succeeded
Built Artifacts : .aws-sam/build
Built Template : .aws-sam/build/template.yaml
Commands you can use next
=========================
[*] Invoke Function: sam local invoke
[*] Package: sam package --s3-bucket <yourbucket>
sam package --output-template-file packaged.yaml --s3-bucket mybucket
Successfully packaged artifacts and wrote output template to file packaged.yaml.
Execute the following com....
Observed result:
aws s3 cp --recursive s3://mybucket/ .unzip 2b35401382a3a5ded0df8b7849ba2f99ls
requirements.txt
test.py
Expected result:
ls
requests
requirements.txt
test.py
Moving to the SAM CLI repo for help with sam build
@use-sparingly The template.yaml file does not have any functions within it. SAM CLI does not traverse Nested Stacks. You will need to build the template that contains the functions. So in your case you will need to run sam build -t lambda.yaml to build the functions within that template.
Closing as we don't yet support Nested Templates in SAM build or any other commands except package. We should create a general issue for this support.
Most helpful comment
@use-sparingly The
template.yamlfile does not have any functions within it. SAM CLI does not traverse Nested Stacks. You will need to build the template that contains the functions. So in your case you will need to runsam build -t lambda.yamlto build the functions within that template.Closing as we don't yet support Nested Templates in SAM build or any other commands except package. We should create a general issue for this support.