aws / aws/aws-toolkit-vscode

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

Open
#2,165 5 comments 3 reactions 0 assignees View on GitHub
guidance sam ux
Dominant language
TypeScript
Stars
2k
Forks
807
Avg merge
10h 12m
Merged PRs (30d)
7

Description

**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//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//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//git/scene-file-parser/template.yml --build-dir /home//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//git/scene-file-parser/template.yml --build_dir=/home//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"
}
]
}```

Contributor guide

Open the contributing guide

Research direction

Start with the launch.json configuration and compare the VS Code and PyCharm SAM build commands shown in the issue, using template.yml and the SceneRunFunction logical ID. Verify that a template-target local invoke passes the resource ID, includes the layer's transitive dependencies in the SAM build output, and makes them available in the Docker container.

Written by the indexing model from the issue text.

Assessment

Tech stack
aws, python, vscode
Domain
cloud, devtools
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.