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.

SAM Debug: failed to build layers with Python

See original GitHub issue

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"
                ]
            }
        }
    ]
}

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
kbadkowskicommented, Feb 21, 2022

Your bits of advice helped me. I managed to run locally my app using the AWS toolkit. Thank you for the workaround and help. Would be nice if it will work in the future without adding debugpy==1.5.1 to the lambda’s requirements.txt.

0reactions
JadenSimoncommented, Feb 16, 2022

@kbadkowski

Looks like the build is taking a long time and causing the toolkit to timeout. Try adjusting this settingaws.samcli.lambda.timeout to a higher value, maybe double or more. The value is in milliseconds.

A fast way to find the setting is by running the command Preferences: Open User Settings then pasting aws.samcli.lambda.timeout into the settings search bar.

Updates regarding timeouts in SAM debug flows are partially tracked apart of this issue: https://github.com/aws/aws-toolkit-vscode/issues/2455

Read more comments on GitHub >

github_iconTop Results From Across the Web

sam local start-api - AWS Serverless Application Model
The AWS SAM CLI first tries to locate a template file built using the sam build command, located in the .aws-sam subfolder, and...
Read more >
why does sam sync --watch fails due to a ... - Stack Overflow
I have no idea what is going on here... help! Here is my Dockerfile: FROM public.ecr.aws/lambda/python:3.9 COPY app.py requirements.txt ./ RUN ...
Read more >
Invoking AWS Lambda functions locally using AWS SAM CLI
The following is the command to install AWS CLI. $ pip3 install awscli --upgrade --user $ aws --version aws-cli/1.16.77 Python/3.6.7 Darwin ...
Read more >
terraform-aws-modules/lambda/aws
Use AWS SAM CLI to test Lambda Function - read more. Features. Build dependencies for your Lambda Function and Layer. Support builds locally...
Read more >
aws-sam-cli Changelog - PyUp.io
feat: Adding --on-failure to sam deploy by lucashuy in ... fix: Create layer root folder before adding layer readme for ADL by qingchm...
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