Aws-sam-cli: Python Lambda Dependencies not built when defined in nested template

Created on 14 Jan 2019  路  2Comments  路  Source: aws/aws-sam-cli

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:

  1. datasource.yaml:
    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
  1. 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
    
  2. src/requirements.txt

    requests
    
  3. src/test.py

    def myhandler(event, context):
      print(event)
    
  4. 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>
    
  5. 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:

  1. aws s3 cp --recursive s3://mybucket/ .
  2. unzip 2b35401382a3a5ded0df8b7849ba2f99
  3. ls

    requirements.txt
    test.py
    

Expected result:

  1. ls

    requests
    requirements.txt
    test.py
    

Most helpful comment

@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.

All 2 comments

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Inkromind picture Inkromind  路  4Comments

goldenbearkin picture goldenbearkin  路  3Comments

rhlsthrm picture rhlsthrm  路  4Comments

GerbenRampaart picture GerbenRampaart  路  3Comments

Caian picture Caian  路  3Comments