Skip to content

sam-beta-cdk local invoke will fail when using a Lambda Layer created in a different substack #2853

Open
@dazzle1979

Description

@dazzle1979

Description:

Using the new sam-beta-cdk it is possible to locally invoke Lambda function in your CDK project. This should also work when the Lamba function is using a Lambda Layer which is created in the CDK.

When testing I found out this only works when the Lambda Function and Layer are created in the same (sub)stack. When using different substacks sam-beta-cdk local invoke will fail with the following error:

Error: referencetosamcdklayerdemolayerstackNestedStacklayerstackNestedStackResource8F1D43CDOutputssamcdklayerdemolayerstacklayertest7F01C4FERef is an Invalid Layer Arn.

Steps to reproduce:

  1. Clone https://github.com/dazzle1979/sam-cdk-layer-demo
  2. Create a local environment: python3 -m venv .env
  3. Install dependencies pip install -r requirements.txt
  4. Run: sam-beta-cdk build
  5. Run: sam-beta-cdk local invoke sam-cdk-layer-demo/test-function-same-stack
  6. Run: sam-beta-cdk local invoke sam-cdk-layer-demo/lambda-stack/test-function

Observed result:

Invoking test-function will fail:

Error: referencetosamcdklayerdemolayerstackNestedStacklayerstackNestedStackResource8F1D43CDOutputssamcdklayerdemolayerstacklayertest7F01C4FERef is an Invalid Layer Arn.

Expected result:

I would expect invoking both function would have the same result because they are the same only not created in the same stack.

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

  1. OS: Mac OS Big Sur 11.2.3
  2. sam --version: SAM CLI, version 1.23.0
  3. sam-beta-cdk --version: SAM CLI, version 1.22.0.dev202104291816

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions