'template' type invoke target not including transitive dependencies from a Ref'd layer with local invoke
See original GitHub issueDesktop (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:
- Created 2 years ago
- Reactions:3
- Comments:5 (3 by maintainers)

Top Related StackOverflow Question
Would like to leave this open. Not sure how to address it yet.
Related: #2395
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.