question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

'template' type invoke target not including transitive dependencies from a Ref'd layer with local invoke

See original GitHub issue

Desktop (please complete the following information):

  • OS: Ubuntu 20.04
  • VS Code version: 1.61.0
  • AWS Toolkit extension version: 1.30.0

Question

I have a sam template that contains both a layer, and a lambda function that Ref’s that layer in the same template. Trying to debug in vscode with the the target ‘template’ method (vs the code method) for a local invoke. The build step does not appear to transitively pull in the required dependencies defined in the layer.

I wasn’t sure if this was supposed to work, but I am able to get it working in pycharm with the aws toolkit as well as from the sam cli tools. So I’m hoping to get it working from vscode as well.

The root of the problem is that the dependencies from the layer are not being included in the output folder of the sam build step, and subsequently the docker image during the invoke step. I verified this at both stages (and in /opt in the docker container)…

The one difference I can see between the pycharm and vscode runs (besides the debug hooks) is that pycharm passes the name of the function to the sam build command, while vscode does not. It passes the template name, but not the resource name. So the resulting build command’s differ as shown below (note ‘SceneRunFunction’ being passed to the build command by pycharm and the resultant --resource_logical_id arg present in the expanded cmd line argument)

vscode:

2021-10-14 10:33:51 [INFO]: Running command: (not started) [/usr/local/bin/sam build --build-dir /tmp/aws-toolkit-vscode/vsctkQl0Npk/output --template /home/<me>/git/scene-file-parser/template.yml --manifest /tmp/aws-toolkit-vscode/vsctkQl0Npk/debug-requirements.txt --debug]
2021-10-14 10:33:52 [INFO]: 2021-10-14 10:33:52,047 | Telemetry endpoint configured to be https://aws-serverless-tools-telemetry.us-west-2.amazonaws.com/metrics

2021-10-14 10:33:52 [INFO]: 2021-10-14 10:33:52,047 | Using config file: samconfig.toml, config environment: default
2021-10-14 10:33:52,047 | Expand command line arguments to:
2021-10-14 10:33:52,047 | --template_file=/home/<me>/git/scene-file-parser/template.yml --build_dir=/tmp/aws-toolkit-vscode/vsctkQl0Npk/output --manifest=/tmp/aws-toolkit-vscode/vsctkQl0Npk/debug-requirements.txt --cache_dir=.aws-sam/cache 

pycharm:

/usr/local/bin/sam build SceneRunFunction --template /home/<me>/git/scene-file-parser/template.yml --build-dir /home/<me>/git/scene-file-parser/.aws-sam/build --debug --debug
2021-10-14 10:48:50,882 | Telemetry endpoint configured to be https://aws-serverless-tools-telemetry.us-west-2.amazonaws.com/metrics
2021-10-14 10:48:50,883 | Using config file: samconfig.toml, config environment: default
2021-10-14 10:48:50,883 | Expand command line arguments to:
2021-10-14 10:48:50,883 | --template_file=/home/<me>/git/scene-file-parser/template.yml --build_dir=/home/<me>/git/scene-file-parser/.aws-sam/build --resource_logical_id=SceneRunFunction --cache_dir=.aws-sam/cache

I’m new to vscode and the toolkit both, so seems more likely I’m missing something as opposed to there being a bug, so here’s my launch.json:

{
    "configurations": [
        {
            "type": "aws-sam",
            "request": "direct-invoke",
            "invokeTarget": {
                "target": "template",
                "logicalId": "SceneRunFunction",
                "templatePath": "${workspaceFolder}/template.yml"
            },
            "lambda": {
                "runtime": "python3.8",
                "payload": {
                    "json": {
                        "body": "blooh"
                    }
                }
            },
            "sam": {
                "buildArguments": [
                    "--debug"
                ],
                "containerBuild": false,
                "localArguments": [
                    "--debug"
                ],
                "skipNewImageCheck": false
            },
            "name": "scene-file-parser:SceneRunFunction"
        }
    ]
}```

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:3
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
justinmk3commented, Jan 3, 2022

Would like to leave this open. Not sure how to address it yet.

Related: #2395

0reactions
grgghrncommented, Oct 21, 2021

Looks like that did the trick. Adding it to the main/root requirements.txt (vs the one used to defined the lambda layer). Thank you!

Should this be left open or changed to a feature request or a bug issue maybe? Seems like a pretty easy workaround but probably not obvious if you don’t already know.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Working with AWS Lambda and Lambda Layers in AWS SAM
To use a Lambda function, a developer just needs to package their code and any dependencies into a zip file and upload that...
Read more >
What is the local workflow for AWS SAM templates which ...
I am having troubles locally invoking a lambda when my SAM template file includes a Layer with dependencies in a local zip file....
Read more >
Learning the Basics - Gradle User Manual
In Gradle, the scope of a dependency is called a configuration. For a full overview, see the reference material on dependency types. Often...
Read more >
Table of Contents - Micronaut Documentation
The javax.inject annotations are no longer a transitive dependency. Micronaut now ships with the Jakarta inject annotations. Either replace all javax.inject ...
Read more >
Web on Servlet Stack - Spring
Help the DispatcherServlet to invoke a handler mapped to a request, regardless of ... If the target method parameter type is not String...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found