aws / aws-lambda-builders

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

Bug: `sam build` and `sam local start-api` always pass `--release` to cargo lambda build #607

Closed jifalops closed 7 months ago

jifalops commented 7 months ago

Description:

Redirected from https://github.com/awslabs/aws-lambda-rust-runtime/issues/671.

I am using sam local start-api for local development, but cannot get it to stop passing --release to the build command.

Here is an example command that tries two separate ways of getting the correct behavior, but still --release is passed.

export SAM_BUILD_MODE=debug 
sam local start-api --debug  BuildCommand="/usr/local/cargo/bin/cargo lambda build" # no --release

Example output:

image

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

  1. OS: docker container: FROM rust (debian based)
  2. If using SAM CLI, sam --version: SAM CLI, version 1.87.0
  3. AWS region: East-1 / ohio

If there's no way to do this I might try the route of doing a debug build manually and pointing sam to it, but I'd really like the 'hot-reload' behavior.

lucashuy commented 7 months ago

Hi, thanks for raising this feature request. Using SAM CLI 1.107.0 and the hello world rust template, I can pass in DEBUG and have it not apply the --release flag:

SAM_BUILD_MODE=debug sam build --debug --no-cached
...
2024-01-15 14:57:19,868 | checking for cargo-lambda                                                          
2024-01-15 14:57:19,868 | potential cargo-lambda binaries: ['/opt/homebrew/bin/cargo-lambda']                
2024-01-15 14:57:19,869 | Executing cargo-lambda: /Users/lucashuy/.cargo/bin/cargo lambda build              
2024-01-15 14:57:19,869 | RUST_LOG environment variable set to `debug`                                       
2024-01-15 14:57:19,938 | DEBUG run: using build compiler configuration from metadata config=BuildConfig {   
compiler: None, target: None }
...

Can you try upgrading SAM CLI to see if that resolve this issue?

jifalops commented 7 months ago

After upgrading to SAM CLI, version 1.107.0, using SAM_BUILD_MODE=debug with sam build resolves the issue.

Note that if sam local start-api needs to build the application, it will ignore SAM_BUILD_MODE=debug (even if exported), so it's important to run sam build separately.