aws / aws/aws-toolkit-vscode

SAM Debug: failed to build layers with Python

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

Description

**Describe the bug**

I have a SAM application that consists of lamda functions and one shared **lambda layer**. The layer uses a **makefile** identifier for building a resource within the template. I can't run and debug the application from VS Code - it fails on (from aws toolkit logs):

```
Running command: (not started) [/usr/local/bin/sam build --build-dir /mnt/c/project/project/.aws-sam/output --template /mnt/c/project/project/template.yaml --use-container --manifest /mnt/c/project/project/.aws-sam/debug-requirements.txt --cached --debug]
...
...
...
Fetching public.ecr.aws/sam/build-python3.8:latest-x86_64 Docker container image......
2022-02-14 12:05:17,274 | Mounting /mnt/c/project/project/ as /tmp/samcli/source:ro,delegated inside runtime container
Using the request object from the command line argument
...
executing Make: ['make', '--makefile', '/tmp/samcli/manifest/debug-requirements.txt', 'build-ProjectDependencies']
CustomMakeBuilder:MakeBuild failed
Traceback (most recent call last):
File "/usr/local/opt/sam-cli/lib/python3.8/site-packages/aws_lambda_builders/workflows/custom_make/actions.py", line 87, in execute
self.subprocess_make.run(
File "/usr/local/opt/sam-cli/lib/python3.8/site-packages/aws_lambda_builders/workflows/custom_make/make.py", line 88, in run
raise MakeExecutionError(message=err.decode("utf8").strip())
aws_lambda_builders.workflows.custom_make.make.MakeExecutionError: Make Failed: make: *** No rule to make target `build-ProjectDependencies'. Stop.
...
```

The part with **--manifest /mnt/c/project/project/.aws-sam/debug-requirements.txt** looks very strange to me. It is added by default from aws toolkit in VS Code and it causes the issue.

Running build directly from the terminal:
```
sam build --template-file template.yaml --use-container --cached --debug
```

Gives:

```
...
executing Make: ['make', '--makefile', '/tmp/samcli/source/Makefile', 'build-ProjectDependencies']
CustomMakeBuilder:MakeBuild succeeded
...
```

**To Reproduce**

Steps to reproduce the behavior:
1. Create SAM App with lambda layer with **makefile** as BuildMethod
2. Create debug configuration
3. Run debug

**Expected behavior**

SAM app should build and run properly after a click on run and debug in VS Code. Build should succeed similar as from directly the terminal.

**Desktop (please complete the following information):**

- OS: WSL 2 Ubuntu 20.04
- Visual Studio Code Version: 1.64.2
- AWS Toolkit Version: 1.35

**Additional context**

Configuration:
```
{
"configurations": [
{
"type": "aws-sam",
"request": "direct-invoke",
"name": "API Classifier",
"invokeTarget": {
"target": "api",
"templatePath": "${workspaceFolder}/project/template.yaml",
"logicalId": "ClassifierLambda"
},
"api": {
"path": "/classifier",
"httpMethod": "post",
"payload": {
"json": {}
}
},
"sam": {
"containerBuild": true,
"buildDir": "${workspaceFolder}/project/.aws-sam",
"buildArguments": [
"--cached",
"--debug",
],
"localArguments": [
"--env-vars",
"${workspaceFolder}/project/EnvironmentVariables/env.json"
]
}
}
]
}
```

Contributor guide

Open the contributing guide

Research direction

Start with the VS Code SAM direct-invoke configuration and the referenced template.yaml, then compare the generated .aws-sam/debug-requirements.txt with the source Makefile and the successful terminal sam build command. Trace where the debug build supplies --manifest; done means the VS Code Run and Debug path builds the makefile-based layer successfully, matching the terminal build.

Written by the indexing model from the issue text.

Assessment

Tech stack
aws, docker, typescript, vscode
Domain
cloud, devtools
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.