aws / aws-lambda-builders

Python library to compile, build & package AWS Lambda functions for several runtimes & framework
Apache License 2.0
330 stars 136 forks source link

Bug: Using AWS::Serverless::LayerVersion with BuildMethod: makefile and python runtime fails to build #566

Open shanti-calleja-its opened 8 months ago

shanti-calleja-its commented 8 months ago

Description:

Using a template with AWS::Serverless::LayerVersion and BuildMethod: makefile fails building because tha makefile passed to make command seems wrong. The code aws_lambda_builders/workflows/custom_make/actions.py", line 99 is using variable manifest_path which is a dependency manifest not the makefile

Steps to reproduce:

template.yaml

AWSTemplateFormatVersion : '2010-09-09' Transform: AWS::Serverless-2016-10-31 Description: A sample SAM template for deploying Lambda functions.

Resources:

LibsLayer: Type: AWS::Serverless::LayerVersion Properties: ContentUri: ../../layerlibs/ CompatibleRuntimes:

/usr/local/bin/sam build --build-dir /tmp/aws-toolkit-vscode/vsctkChoBiG/output --template /home/user/github/LambdAtom/atom_vmaas/.vscode/template.yml --manifest /tmp/aws-toolkit-vscode/vsctkChoBiG/debug-requirements.txt --debug

Observed result:

2023-11-04 12:53:36,389 | CustomMakeBuilder:CopySource succeeded
2023-11-04 12:53:36,390 | LibsLayer: Running CustomMakeBuilder:MakeBuild
2023-11-04 12:53:36,391 | LibsLayer: Current Artifacts Directory : /tmp/aws-toolkit-vscode/vsctkChoBiG/output/LibsLayer
2023-11-04 12:53:36,392 | executing Make: ['make', '--makefile', '/tmp/aws-toolkit-vscode/vsctkChoBiG/debug-requirements.txt', 'build-LibsLayer']
2023-11-04 12:53:36,402 | CustomMakeBuilder:MakeBuild failed
Traceback (most recent call last):
File "aws_lambda_builders/workflows/custom_make/actions.py", line 99, in execute
File "aws_lambda_builders/workflows/custom_make/make.py", line 115, in run
aws_lambda_builders.workflows.custom_make.make.MakeExecutionError: Make Failed: make: *** No rule to make target 'build-LibsLayer'. Stop.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "aws_lambda_builders/workflow.py", line 371, in run
File "aws_lambda_builders/workflows/custom_make/actions.py", line 109, in execute
aws_lambda_builders.actions.ActionFailedError: Make Failed: make: *** No rule to make target 'build-LibsLayer'. Stop.

Build Failed

Expected result:

['make', '--makefile', '/home/user/github/LambdAtom/layerlibs/Makefile', 'build-LibsLayer']

Additional environment details (Ex: Windows, Mac, Amazon Linux etc)

  1. OS: WSL2 Debian
  2. If using SAM CLI, sam --version: SAM CLI, version 1.100.0
  3. AWS region: Local environment and eu-west-3

Add --debug flag to any SAM CLI commands you are running

hawflau commented 8 months ago

@shanti-calleja-its thanks for raising the issue.

Can you try not setting the --manifest option? It seems like it's overridden where to look up the Makefile.

shanti-calleja-its commented 8 months ago

I can build the app using sam commands using the template.

The problem happens when I try to use vscode debugger. The launch.json uses the template as expected creating the build dir, copying files and building the command as:

/usr/local/bin/sam build --build-dir /tmp/aws-toolkit-vscode/vsctkChoBiG/output --template /home/user/github/LambdAtom/atom_vmaas/.vscode/template.yml --manifest /tmp/aws-toolkit-vscode/vsctkChoBiG/debug-requirements.txt

The manifest is modified by debugger including debugpy for debugging.

From my point of view the problem is that the CustomMakeBuilder is trying to read the manifest as a makefile when --manifest is passed to the build command. If Idon´t use the arguments, it works, but debugging is not enabled.