Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"sam build -u -e TARGET_CC=foo" leads to "cargo: Command not found" #3132

Closed
brainstorm opened this issue Aug 3, 2021 · 14 comments
Closed

Comments

@brainstorm
Copy link

brainstorm commented Aug 3, 2021

Description:

I'm trying to pass build variables to the sam build docker container to solve briansmith/ring#1332 cross-compiling issue, also pointed out over twitter.

Steps to reproduce:

On an Apple Silicon M1 laptop, run the following:

brew tap aws/tap
brew install aws-sam-cli
git clone https://github.com/umccr/s3-rust-noodles-bam && cd s3-rust-noodles-bam && git checkout s3-server
sam build -u -e FOO=BAR

Observed result:

When sam build is called with environment variable container-passing flag, cargo command is not found:

(base) rvalls@m1 s3-rust-noodles-bam % sam build --debug --use-container -e TARGET_CC=gcc
2021-08-03 12:46:09,833 | Telemetry endpoint configured to be https://aws-serverless-tools-telemetry.us-west-2.amazonaws.com/metrics
2021-08-03 12:46:09,834 | Using config file: samconfig.toml, config environment: default
2021-08-03 12:46:09,834 | Expand command line arguments to:
2021-08-03 12:46:09,834 | --template_file=/Users/rvalls/dev/umccr/s3-rust-noodles-bam/template.yml --use_container --container_env_var=('TARGET_CC=gcc',) --build_dir=.aws-sam/build --cache_dir=.aws-sam/cache
2021-08-03 12:46:09,887 | 'build' command is called
2021-08-03 12:46:09,887 | Starting Build inside a container
2021-08-03 12:46:09,889 | No Parameters detected in the template
2021-08-03 12:46:09,901 | 2 stacks found in the template
2021-08-03 12:46:09,901 | No Parameters detected in the template
2021-08-03 12:46:09,916 | 2 resources found in the stack
2021-08-03 12:46:09,916 | No Parameters detected in the template
2021-08-03 12:46:09,925 | Found Serverless function with name='s3Bam' and CodeUri='.'
2021-08-03 12:46:09,925 | --base-dir is not presented, adjusting uri . relative to /Users/rvalls/dev/umccr/s3-rust-noodles-bam/template.yml
2021-08-03 12:46:09,925 | No Parameters detected in the template
2021-08-03 12:46:09,935 | Instantiating build definitions
2021-08-03 12:46:09,937 | Unique function build definition found, adding as new (Function Build Definition: BuildDefinition(provided.al2, /Users/rvalls/dev/umccr/s3-rust-noodles-bam, Zip, , 6cd8efd1-34b8-4609-9a74-ac919577cfcd, {'BuildMethod': 'makefile'}, {'TARGET_CC': 'gcc'}, []), Function: Function(name='s3Bam', functionname='s3-bamheader', runtime='provided.al2', memory=128, timeout=30, handler='bootstrap.is.real.handler', imageuri=None, packagetype='Zip', imageconfig=None, codeuri='/Users/rvalls/dev/umccr/s3-rust-noodles-bam', environment=None, rolearn=None, layers=[], events={'RootEvent': {'Type': 'Api', 'Properties': {'Path': '/', 'Method': 'any', 'RestApiId': 'ServerlessRestApi'}}, 'GatewayEvent': {'Type': 'Api', 'Properties': {'Path': '/{proxy+}', 'Method': 'any', 'RestApiId': 'ServerlessRestApi'}}}, metadata={'BuildMethod': 'makefile'}, inlinecode=None, codesign_config_arn=None, stack_path=''))
2021-08-03 12:46:09,938 | Building codeuri: /Users/rvalls/dev/umccr/s3-rust-noodles-bam runtime: provided.al2 metadata: {'BuildMethod': 'makefile'} functions: ['s3Bam']
2021-08-03 12:46:09,938 | Building to following folder /Users/rvalls/dev/umccr/s3-rust-noodles-bam/.aws-sam/build/s3Bam

Fetching public.ecr.aws/sam/build-provided.al2:latest Docker container image......
2021-08-03 12:46:13,841 | Mounting /Users/rvalls/dev/umccr/s3-rust-noodles-bam as /tmp/samcli/source:ro,delegated inside runtime container
Using the request object from command line argument
Loading workflow module 'aws_lambda_builders.workflows'
Registering workflow 'PythonPipBuilder' with capability 'Capability(language='python', dependency_manager='pip', application_framework=None)'
Registering workflow 'NodejsNpmBuilder' with capability 'Capability(language='nodejs', dependency_manager='npm', application_framework=None)'
Registering workflow 'RubyBundlerBuilder' with capability 'Capability(language='ruby', dependency_manager='bundler', application_framework=None)'
Registering workflow 'GoDepBuilder' with capability 'Capability(language='go', dependency_manager='dep', application_framework=None)'
Registering workflow 'GoModulesBuilder' with capability 'Capability(language='go', dependency_manager='modules', application_framework=None)'
Registering workflow 'JavaGradleWorkflow' with capability 'Capability(language='java', dependency_manager='gradle', application_framework=None)'
Registering workflow 'JavaMavenWorkflow' with capability 'Capability(language='java', dependency_manager='maven', application_framework=None)'
Registering workflow 'DotnetCliPackageBuilder' with capability 'Capability(language='dotnet', dependency_manager='cli-package', application_framework=None)'
Registering workflow 'CustomMakeBuilder' with capability 'Capability(language='provided', dependency_manager=None, application_framework=None)'
Found workflow 'CustomMakeBuilder' to support capabilities 'Capability(language='provided', dependency_manager=None, application_framework=None)'
Running workflow 'CustomMakeBuilder'
Running CustomMakeBuilder:CopySource
CustomMakeBuilder:CopySource succeeded
Running CustomMakeBuilder:MakeBuild
Current Artifacts Directory : /tmp/samcli/artifacts
executing Make: ['make', '--makefile', '/tmp/samcli/source/Makefile', 'build-s3Bam']
CustomMakeBuilder:MakeBuild failed
Traceback (most recent call last):
  File "/usr/local/opt/sam-cli/lib64/python3.7/site-packages/aws_lambda_builders/workflows/custom_make/actions.py", line 94, in execute
    cwd=self.scratch_dir,
  File "/usr/local/opt/sam-cli/lib64/python3.7/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: cargo: Command not found
make: *** [build-s3Bam] Error 127

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/opt/sam-cli/lib64/python3.7/site-packages/aws_lambda_builders/workflow.py", line 269, in run
    action.execute()
  File "/usr/local/opt/sam-cli/lib64/python3.7/site-packages/aws_lambda_builders/workflows/custom_make/actions.py", line 97, in execute
    raise ActionFailedError(str(ex))
aws_lambda_builders.actions.ActionFailedError: Make Failed: make: cargo: Command not found
make: *** [build-s3Bam] Error 127
Builder workflow failed
Traceback (most recent call last):
  File "/usr/local/opt/sam-cli/lib64/python3.7/site-packages/aws_lambda_builders/workflows/custom_make/actions.py", line 94, in execute
    cwd=self.scratch_dir,
  File "/usr/local/opt/sam-cli/lib64/python3.7/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: cargo: Command not found
make: *** [build-s3Bam] Error 127

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/opt/sam-cli/lib64/python3.7/site-packages/aws_lambda_builders/workflow.py", line 269, in run
    action.execute()
  File "/usr/local/opt/sam-cli/lib64/python3.7/site-packages/aws_lambda_builders/workflows/custom_make/actions.py", line 97, in execute
    raise ActionFailedError(str(ex))
aws_lambda_builders.actions.ActionFailedError: Make Failed: make: cargo: Command not found
make: *** [build-s3Bam] Error 127

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/opt/sam-cli/lib64/python3.7/site-packages/aws_lambda_builders/__main__.py", line 126, in main
    mode=params.get("mode", None),
  File "/usr/local/opt/sam-cli/lib64/python3.7/site-packages/aws_lambda_builders/builder.py", line 125, in build
    return workflow.run()
  File "/usr/local/opt/sam-cli/lib64/python3.7/site-packages/aws_lambda_builders/workflow.py", line 76, in wrapper
    func(self, *args, **kwargs)
  File "/usr/local/opt/sam-cli/lib64/python3.7/site-packages/aws_lambda_builders/workflow.py", line 276, in run
    raise WorkflowFailedError(workflow_name=self.NAME, action_name=action.NAME, reason=str(ex))
aws_lambda_builders.exceptions.WorkflowFailedError: CustomMakeBuilder:MakeBuild - Make Failed: make: cargo: Command not found
make: *** [build-s3Bam] Error 127
2021-08-03 12:47:53,527 | Build inside container returned response {"jsonrpc": "2.0", "id": 1, "error": {"code": 400, "message": "CustomMakeBuilder:MakeBuild - Make Failed: make: cargo: Command not found\nmake: *** [build-s3Bam] Error 127"}}

Build Failed
2021-08-03 12:47:54,752 | Sending Telemetry: {'metrics': [{'commandRun': {'requestId': '09ec9ada-8b55-412e-8304-b82ef7beff57', 'installationId': 'b0a4feb6-813d-4f61-952f-5919f29d6b17', 'sessionId': '684afe41-d857-4475-8ce5-40368e98041e', 'executionEnvironment': 'CLI', 'ci': False, 'pyversion': '3.8.11', 'samcliVersion': '1.27.2', 'awsProfileProvided': False, 'debugFlagProvided': True, 'region': '', 'commandName': 'sam build', 'duration': 104915, 'exitReason': 'BuildInsideContainerError', 'exitCode': 1}}]}
2021-08-03 12:47:55,650 | HTTPSConnectionPool(host='aws-serverless-tools-telemetry.us-west-2.amazonaws.com', port=443): Read timed out. (read timeout=0.1)
Error: CustomMakeBuilder:MakeBuild - Make Failed: make: cargo: Command not found
make: *** [build-s3Bam] Error **127**

When calling sam build with no arguments, cargo seems to be there in the provided.al2 container:

(base) rvalls@m1 s3-rust-noodles-bam % sam build --debug
2021-08-03 12:50:43,892 | Telemetry endpoint configured to be https://aws-serverless-tools-telemetry.us-west-2.amazonaws.com/metrics
2021-08-03 12:50:43,892 | Using config file: samconfig.toml, config environment: default
2021-08-03 12:50:43,892 | Expand command line arguments to:
2021-08-03 12:50:43,892 | --template_file=/Users/rvalls/dev/umccr/s3-rust-noodles-bam/template.yml --build_dir=.aws-sam/build --cache_dir=.aws-sam/cache
2021-08-03 12:50:43,940 | 'build' command is called
2021-08-03 12:50:43,942 | No Parameters detected in the template
2021-08-03 12:50:43,953 | 2 stacks found in the template
2021-08-03 12:50:43,953 | No Parameters detected in the template
2021-08-03 12:50:43,968 | 2 resources found in the stack
2021-08-03 12:50:43,968 | No Parameters detected in the template
2021-08-03 12:50:43,977 | Found Serverless function with name='s3Bam' and CodeUri='.'
2021-08-03 12:50:43,978 | --base-dir is not presented, adjusting uri . relative to /Users/rvalls/dev/umccr/s3-rust-noodles-bam/template.yml
2021-08-03 12:50:43,978 | No Parameters detected in the template
2021-08-03 12:50:43,987 | Instantiating build definitions
2021-08-03 12:50:43,989 | Unique function build definition found, adding as new (Function Build Definition: BuildDefinition(provided.al2, /Users/rvalls/dev/umccr/s3-rust-noodles-bam, Zip, , 32329348-bbde-4e05-be4c-45e7c4718426, {'BuildMethod': 'makefile'}, {}, []), Function: Function(name='s3Bam', functionname='s3-bamheader', runtime='provided.al2', memory=128, timeout=30, handler='bootstrap.is.real.handler', imageuri=None, packagetype='Zip', imageconfig=None, codeuri='/Users/rvalls/dev/umccr/s3-rust-noodles-bam', environment=None, rolearn=None, layers=[], events={'RootEvent': {'Type': 'Api', 'Properties': {'Path': '/', 'Method': 'any', 'RestApiId': 'ServerlessRestApi'}}, 'GatewayEvent': {'Type': 'Api', 'Properties': {'Path': '/{proxy+}', 'Method': 'any', 'RestApiId': 'ServerlessRestApi'}}}, metadata={'BuildMethod': 'makefile'}, inlinecode=None, codesign_config_arn=None, stack_path=''))
2021-08-03 12:50:43,990 | Building codeuri: /Users/rvalls/dev/umccr/s3-rust-noodles-bam runtime: provided.al2 metadata: {'BuildMethod': 'makefile'} functions: ['s3Bam']
2021-08-03 12:50:43,990 | Building to following folder /Users/rvalls/dev/umccr/s3-rust-noodles-bam/.aws-sam/build/s3Bam
2021-08-03 12:50:43,991 | Loading workflow module 'aws_lambda_builders.workflows'
2021-08-03 12:50:43,993 | Registering workflow 'PythonPipBuilder' with capability 'Capability(language='python', dependency_manager='pip', application_framework=None)'
2021-08-03 12:50:43,994 | Registering workflow 'NodejsNpmBuilder' with capability 'Capability(language='nodejs', dependency_manager='npm', application_framework=None)'
2021-08-03 12:50:43,995 | Registering workflow 'RubyBundlerBuilder' with capability 'Capability(language='ruby', dependency_manager='bundler', application_framework=None)'
2021-08-03 12:50:43,996 | Registering workflow 'GoDepBuilder' with capability 'Capability(language='go', dependency_manager='dep', application_framework=None)'
2021-08-03 12:50:43,997 | Registering workflow 'GoModulesBuilder' with capability 'Capability(language='go', dependency_manager='modules', application_framework=None)'
2021-08-03 12:50:43,998 | Registering workflow 'JavaGradleWorkflow' with capability 'Capability(language='java', dependency_manager='gradle', application_framework=None)'
2021-08-03 12:50:43,999 | Registering workflow 'JavaMavenWorkflow' with capability 'Capability(language='java', dependency_manager='maven', application_framework=None)'
2021-08-03 12:50:44,000 | Registering workflow 'DotnetCliPackageBuilder' with capability 'Capability(language='dotnet', dependency_manager='cli-package', application_framework=None)'
2021-08-03 12:50:44,001 | Registering workflow 'CustomMakeBuilder' with capability 'Capability(language='provided', dependency_manager=None, application_framework=None)'
2021-08-03 12:50:44,001 | Found workflow 'CustomMakeBuilder' to support capabilities 'Capability(language='provided', dependency_manager=None, application_framework=None)'
2021-08-03 12:50:44,001 | Running workflow 'CustomMakeBuilder'
2021-08-03 12:50:44,001 | Running CustomMakeBuilder:CopySource
2021-08-03 12:50:48,306 | CustomMakeBuilder:CopySource succeeded
2021-08-03 12:50:48,306 | Running CustomMakeBuilder:MakeBuild
2021-08-03 12:50:48,306 | Current Artifacts Directory : /Users/rvalls/dev/umccr/s3-rust-noodles-bam/.aws-sam/build/s3Bam
2021-08-03 12:50:48,306 | executing Make: ['make', '--makefile', '/Users/rvalls/dev/umccr/s3-rust-noodles-bam/Makefile', 'build-s3Bam']
2021-08-03 12:50:56,801 | CustomMakeBuilder:MakeBuild failed
Traceback (most recent call last):
  File "/opt/homebrew/Cellar/aws-sam-cli/1.27.2/libexec/lib/python3.8/site-packages/aws_lambda_builders/workflows/custom_make/actions.py", line 87, in execute
    self.subprocess_make.run(
  File "/opt/homebrew/Cellar/aws-sam-cli/1.27.2/libexec/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: Compiling autocfg v1.0.1
   Compiling proc-macro2 v1.0.27
   Compiling unicode-xid v0.2.2
   Compiling syn v1.0.73
   Compiling libc v0.2.97
   Compiling cfg-if v1.0.0
   Compiling memchr v2.4.0
   Compiling log v0.4.14
   Compiling pin-project-lite v0.2.7
   Compiling futures-core v0.3.15
   Compiling bytes v1.0.1
   Compiling itoa v0.4.7
   Compiling lazy_static v1.4.0
   Compiling proc-macro-hack v0.5.19
   Compiling cc v1.0.68
   Compiling futures-sink v0.3.15
   Compiling futures-task v0.3.15
   Compiling futures-channel v0.3.15
   Compiling proc-macro-nested v0.1.7
   Compiling futures-io v0.3.15
   Compiling pin-utils v0.1.0
   Compiling slab v0.4.3
   Compiling fnv v1.0.7
   Compiling hashbrown v0.11.2
   Compiling once_cell v1.8.0
   Compiling serde_derive v1.0.126
   Compiling serde v1.0.126
   Compiling ryu v1.0.5
   Compiling httparse v1.4.1
   Compiling percent-encoding v2.1.0
   Compiling spin v0.5.2
   Compiling untrusted v0.7.1
   Compiling try-lock v0.2.3
   Compiling tower-service v0.3.1
   Compiling version_check v0.9.3
   Compiling ucd-trie v0.1.3
   Compiling httpdate v1.0.1
   Compiling regex-syntax v0.6.25
   Compiling either v1.6.1
   Compiling serde_json v1.0.64
   Compiling matches v0.1.8
   Compiling ansi_term v0.12.1
   Compiling base64 v0.13.0
   Compiling crc32fast v1.2.1
   Compiling xmlparser v0.13.3
   Compiling adler v1.0.2
   Compiling openssl-probe v0.1.4
   Compiling tower-layer v0.3.1
   Compiling diff v0.1.12
   Compiling bitflags v1.2.1
   Compiling hex v0.4.3
   Compiling zeroize v1.3.0
   Compiling tinyvec_macros v0.1.0
   Compiling byteorder v1.4.3
   Compiling fs_extra v1.2.0
   Compiling smallvec v1.6.1
   Compiling fastrand v1.4.1
   Compiling bit-vec v0.6.3
   Compiling md5 v0.7.0
   Compiling futures-macro v0.3.15
   Compiling tokio v1.7.1
   Compiling num-traits v0.2.14
   Compiling indexmap v1.7.0
   Compiling futures-util v0.3.15
   Compiling num-integer v0.1.44
   Compiling miniz_oxide v0.4.4
   Compiling tracing-core v0.1.18
   Compiling sharded-slab v0.1.1
   Compiling http v0.2.4
   Compiling thread_local v1.1.3
   Compiling ring v0.16.20
   Compiling pest v2.1.3
   Compiling bytes-utils v0.1.1
   Compiling form_urlencoded v1.0.1
   Compiling unicode-bidi v0.3.5
   Compiling proc-macro-error-attr v1.0.4
   Compiling proc-macro-error v1.0.4
   Compiling roxmltree v0.14.1
   Compiling pretty_assertions v0.7.2
   Compiling tinyvec v1.2.0
   Compiling jemalloc-sys v0.3.2
   Compiling regex-automata v0.1.10
error: failed to run custom build command for `ring v0.16.20`

Caused by:
  process didn't exit successfully: `/private/var/folders/s8/0tz3dy0d1sbg1_cv0ylkx_m80000gn/T/tmp27ah1k33/target/release/build/ring-0c3d64667514526d/build-script-build` (exit status: 101)
  --- stdout
  OPT_LEVEL = Some("3")
  TARGET = Some("x86_64-unknown-linux-gnu")
  HOST = Some("aarch64-apple-darwin")
  CC_x86_64-unknown-linux-gnu = None
  CC_x86_64_unknown_linux_gnu = None
  TARGET_CC = None
  CC = None
  CROSS_COMPILE = None
  CFLAGS_x86_64-unknown-linux-gnu = None
  CFLAGS_x86_64_unknown_linux_gnu = None
  TARGET_CFLAGS = None
  CFLAGS = None
  CRATE_CC_NO_DEFAULTS = None
  DEBUG = Some("false")
  CARGO_CFG_TARGET_FEATURE = Some("fxsr,sse,sse2")

  --- stderr
  running "cc" "-O3" "-ffunction-sections" "-fdata-sections" "-fPIC" "-m64" "-I" "include" "-Wall" "-Wextra" "-pedantic" "-pedantic-errors" "-Wall" "-Wextra" "-Wcast-align" "-Wcast-qual" "-Wconversion" "-Wenum-compare" "-Wfloat-equal" "-Wformat=2" "-Winline" "-Winvalid-pch" "-Wmissing-field-initializers" "-Wmissing-include-dirs" "-Wredundant-decls" "-Wshadow" "-Wsign-compare" "-Wsign-conversion" "-Wundef" "-Wuninitialized" "-Wwrite-strings" "-fno-strict-aliasing" "-fvisibility=hidden" "-fstack-protector" "-g3" "-DNDEBUG" "-c" "-o/private/var/folders/s8/0tz3dy0d1sbg1_cv0ylkx_m80000gn/T/tmp27ah1k33/target/x86_64-unknown-linux-gnu/release/build/ring-1b5ef9a99e86a98a/out/aesni-x86_64-elf.o" "/Users/rvalls/.cargo/registry/src/github.com-1ecc6299db9ec823/ring-0.16.20/pregenerated/aesni-x86_64-elf.S"
  /Users/rvalls/.cargo/registry/src/github.com-1ecc6299db9ec823/ring-0.16.20/pregenerated/aesni-x86_64-elf.S:1181:19: error: unexpected token in '.section' directive
  .section .note.GNU-stack,"",@progbits
                    ^
  thread 'main' panicked at 'execution failed', /Users/rvalls/.cargo/registry/src/github.com-1ecc6299db9ec823/ring-0.16.20/build.rs:656:9
  note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
warning: build failed, waiting for other jobs to finish...
error: build failed
make: *** [build-s3Bam] Error 101

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/opt/homebrew/Cellar/aws-sam-cli/1.27.2/libexec/lib/python3.8/site-packages/aws_lambda_builders/workflow.py", line 269, in run
    action.execute()
  File "/opt/homebrew/Cellar/aws-sam-cli/1.27.2/libexec/lib/python3.8/site-packages/aws_lambda_builders/workflows/custom_make/actions.py", line 97, in execute
    raise ActionFailedError(str(ex))
aws_lambda_builders.actions.ActionFailedError: Make Failed: Compiling autocfg v1.0.1
   Compiling proc-macro2 v1.0.27
   Compiling unicode-xid v0.2.2
   Compiling syn v1.0.73
   Compiling libc v0.2.97
   Compiling cfg-if v1.0.0
   Compiling memchr v2.4.0
   Compiling log v0.4.14
   Compiling pin-project-lite v0.2.7
   Compiling futures-core v0.3.15
   Compiling bytes v1.0.1
   Compiling itoa v0.4.7
   Compiling lazy_static v1.4.0
   Compiling proc-macro-hack v0.5.19
   Compiling cc v1.0.68
   Compiling futures-sink v0.3.15
   Compiling futures-task v0.3.15
   Compiling futures-channel v0.3.15
   Compiling proc-macro-nested v0.1.7
   Compiling futures-io v0.3.15
   Compiling pin-utils v0.1.0
   Compiling slab v0.4.3
   Compiling fnv v1.0.7
   Compiling hashbrown v0.11.2
   Compiling once_cell v1.8.0
   Compiling serde_derive v1.0.126
   Compiling serde v1.0.126
   Compiling ryu v1.0.5
   Compiling httparse v1.4.1
   Compiling percent-encoding v2.1.0
   Compiling spin v0.5.2
   Compiling untrusted v0.7.1
   Compiling try-lock v0.2.3
   Compiling tower-service v0.3.1
   Compiling version_check v0.9.3
   Compiling ucd-trie v0.1.3
   Compiling httpdate v1.0.1
   Compiling regex-syntax v0.6.25
   Compiling either v1.6.1
   Compiling serde_json v1.0.64
   Compiling matches v0.1.8
   Compiling ansi_term v0.12.1
   Compiling base64 v0.13.0
   Compiling crc32fast v1.2.1
   Compiling xmlparser v0.13.3
   Compiling adler v1.0.2
   Compiling openssl-probe v0.1.4
   Compiling tower-layer v0.3.1
   Compiling diff v0.1.12
   Compiling bitflags v1.2.1
   Compiling hex v0.4.3
   Compiling zeroize v1.3.0
   Compiling tinyvec_macros v0.1.0
   Compiling byteorder v1.4.3
   Compiling fs_extra v1.2.0
   Compiling smallvec v1.6.1
   Compiling fastrand v1.4.1
   Compiling bit-vec v0.6.3
   Compiling md5 v0.7.0
   Compiling futures-macro v0.3.15
   Compiling tokio v1.7.1
   Compiling num-traits v0.2.14
   Compiling indexmap v1.7.0
   Compiling futures-util v0.3.15
   Compiling num-integer v0.1.44
   Compiling miniz_oxide v0.4.4
   Compiling tracing-core v0.1.18
   Compiling sharded-slab v0.1.1
   Compiling http v0.2.4
   Compiling thread_local v1.1.3
   Compiling ring v0.16.20
   Compiling pest v2.1.3
   Compiling bytes-utils v0.1.1
   Compiling form_urlencoded v1.0.1
   Compiling unicode-bidi v0.3.5
   Compiling proc-macro-error-attr v1.0.4
   Compiling proc-macro-error v1.0.4
   Compiling roxmltree v0.14.1
   Compiling pretty_assertions v0.7.2
   Compiling tinyvec v1.2.0
   Compiling jemalloc-sys v0.3.2
   Compiling regex-automata v0.1.10
error: failed to run custom build command for `ring v0.16.20`

Caused by:
  process didn't exit successfully: `/private/var/folders/s8/0tz3dy0d1sbg1_cv0ylkx_m80000gn/T/tmp27ah1k33/target/release/build/ring-0c3d64667514526d/build-script-build` (exit status: 101)
  --- stdout
  OPT_LEVEL = Some("3")
  TARGET = Some("x86_64-unknown-linux-gnu")
  HOST = Some("aarch64-apple-darwin")
  CC_x86_64-unknown-linux-gnu = None
  CC_x86_64_unknown_linux_gnu = None
  TARGET_CC = None
  CC = None
  CROSS_COMPILE = None
  CFLAGS_x86_64-unknown-linux-gnu = None
  CFLAGS_x86_64_unknown_linux_gnu = None
  TARGET_CFLAGS = None
  CFLAGS = None
  CRATE_CC_NO_DEFAULTS = None
  DEBUG = Some("false")
  CARGO_CFG_TARGET_FEATURE = Some("fxsr,sse,sse2")

  --- stderr
  running "cc" "-O3" "-ffunction-sections" "-fdata-sections" "-fPIC" "-m64" "-I" "include" "-Wall" "-Wextra" "-pedantic" "-pedantic-errors" "-Wall" "-Wextra" "-Wcast-align" "-Wcast-qual" "-Wconversion" "-Wenum-compare" "-Wfloat-equal" "-Wformat=2" "-Winline" "-Winvalid-pch" "-Wmissing-field-initializers" "-Wmissing-include-dirs" "-Wredundant-decls" "-Wshadow" "-Wsign-compare" "-Wsign-conversion" "-Wundef" "-Wuninitialized" "-Wwrite-strings" "-fno-strict-aliasing" "-fvisibility=hidden" "-fstack-protector" "-g3" "-DNDEBUG" "-c" "-o/private/var/folders/s8/0tz3dy0d1sbg1_cv0ylkx_m80000gn/T/tmp27ah1k33/target/x86_64-unknown-linux-gnu/release/build/ring-1b5ef9a99e86a98a/out/aesni-x86_64-elf.o" "/Users/rvalls/.cargo/registry/src/github.com-1ecc6299db9ec823/ring-0.16.20/pregenerated/aesni-x86_64-elf.S"
  /Users/rvalls/.cargo/registry/src/github.com-1ecc6299db9ec823/ring-0.16.20/pregenerated/aesni-x86_64-elf.S:1181:19: error: unexpected token in '.section' directive
  .section .note.GNU-stack,"",@progbits
                    ^
  thread 'main' panicked at 'execution failed', /Users/rvalls/.cargo/registry/src/github.com-1ecc6299db9ec823/ring-0.16.20/build.rs:656:9
  note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
warning: build failed, waiting for other jobs to finish...
error: build failed
make: *** [build-s3Bam] Error 101

Build Failed
2021-08-03 12:50:57,258 | Sending Telemetry: {'metrics': [{'commandRun': {'requestId': 'a2e56033-37e4-4bc2-8c39-0a9ec41dba7f', 'installationId': 'b0a4feb6-813d-4f61-952f-5919f29d6b17', 'sessionId': 'f7ac1940-5452-4195-8558-7c51c453afc4', 'executionEnvironment': 'CLI', 'ci': False, 'pyversion': '3.8.11', 'samcliVersion': '1.27.2', 'awsProfileProvided': False, 'debugFlagProvided': True, 'region': '', 'commandName': 'sam build', 'duration': 13364, 'exitReason': 'WorkflowFailedError', 'exitCode': 1}}]}
2021-08-03 12:50:58,193 | HTTPSConnectionPool(host='aws-serverless-tools-telemetry.us-west-2.amazonaws.com', port=443): Read timed out. (read timeout=0.1)
Error: CustomMakeBuilder:MakeBuild - Make Failed: Compiling autocfg v1.0.1
   Compiling proc-macro2 v1.0.27
   Compiling unicode-xid v0.2.2
   Compiling syn v1.0.73
   Compiling libc v0.2.97
   Compiling cfg-if v1.0.0
   Compiling memchr v2.4.0
   Compiling log v0.4.14
   Compiling pin-project-lite v0.2.7
   Compiling futures-core v0.3.15
   Compiling bytes v1.0.1
   Compiling itoa v0.4.7
   Compiling lazy_static v1.4.0
   Compiling proc-macro-hack v0.5.19
   Compiling cc v1.0.68
   Compiling futures-sink v0.3.15
   Compiling futures-task v0.3.15
   Compiling futures-channel v0.3.15
   Compiling proc-macro-nested v0.1.7
   Compiling futures-io v0.3.15
   Compiling pin-utils v0.1.0
   Compiling slab v0.4.3
   Compiling fnv v1.0.7
   Compiling hashbrown v0.11.2
   Compiling once_cell v1.8.0
   Compiling serde_derive v1.0.126
   Compiling serde v1.0.126
   Compiling ryu v1.0.5
   Compiling httparse v1.4.1
   Compiling percent-encoding v2.1.0
   Compiling spin v0.5.2
   Compiling untrusted v0.7.1
   Compiling try-lock v0.2.3
   Compiling tower-service v0.3.1
   Compiling version_check v0.9.3
   Compiling ucd-trie v0.1.3
   Compiling httpdate v1.0.1
   Compiling regex-syntax v0.6.25
   Compiling either v1.6.1
   Compiling serde_json v1.0.64
   Compiling matches v0.1.8
   Compiling ansi_term v0.12.1
   Compiling base64 v0.13.0
   Compiling crc32fast v1.2.1
   Compiling xmlparser v0.13.3
   Compiling adler v1.0.2
   Compiling openssl-probe v0.1.4
   Compiling tower-layer v0.3.1
   Compiling diff v0.1.12
   Compiling bitflags v1.2.1
   Compiling hex v0.4.3
   Compiling zeroize v1.3.0
   Compiling tinyvec_macros v0.1.0
   Compiling byteorder v1.4.3
   Compiling fs_extra v1.2.0
   Compiling smallvec v1.6.1
   Compiling fastrand v1.4.1
   Compiling bit-vec v0.6.3
   Compiling md5 v0.7.0
   Compiling futures-macro v0.3.15
   Compiling tokio v1.7.1
   Compiling num-traits v0.2.14
   Compiling indexmap v1.7.0
   Compiling futures-util v0.3.15
   Compiling num-integer v0.1.44
   Compiling miniz_oxide v0.4.4
   Compiling tracing-core v0.1.18
   Compiling sharded-slab v0.1.1
   Compiling http v0.2.4
   Compiling thread_local v1.1.3
   Compiling ring v0.16.20
   Compiling pest v2.1.3
   Compiling bytes-utils v0.1.1
   Compiling form_urlencoded v1.0.1
   Compiling unicode-bidi v0.3.5
   Compiling proc-macro-error-attr v1.0.4
   Compiling proc-macro-error v1.0.4
   Compiling roxmltree v0.14.1
   Compiling pretty_assertions v0.7.2
   Compiling tinyvec v1.2.0
   Compiling jemalloc-sys v0.3.2
   Compiling regex-automata v0.1.10
error: failed to run custom build command for `ring v0.16.20`

Caused by:
  process didn't exit successfully: `/private/var/folders/s8/0tz3dy0d1sbg1_cv0ylkx_m80000gn/T/tmp27ah1k33/target/release/build/ring-0c3d64667514526d/build-script-build` (exit status: 101)
  --- stdout
  OPT_LEVEL = Some("3")
  TARGET = Some("x86_64-unknown-linux-gnu")
  HOST = Some("aarch64-apple-darwin")
  CC_x86_64-unknown-linux-gnu = None
  CC_x86_64_unknown_linux_gnu = None
  TARGET_CC = None
  CC = None
  CROSS_COMPILE = None
  CFLAGS_x86_64-unknown-linux-gnu = None
  CFLAGS_x86_64_unknown_linux_gnu = None
  TARGET_CFLAGS = None
  CFLAGS = None
  CRATE_CC_NO_DEFAULTS = None
  DEBUG = Some("false")
  CARGO_CFG_TARGET_FEATURE = Some("fxsr,sse,sse2")

  --- stderr
  running "cc" "-O3" "-ffunction-sections" "-fdata-sections" "-fPIC" "-m64" "-I" "include" "-Wall" "-Wextra" "-pedantic" "-pedantic-errors" "-Wall" "-Wextra" "-Wcast-align" "-Wcast-qual" "-Wconversion" "-Wenum-compare" "-Wfloat-equal" "-Wformat=2" "-Winline" "-Winvalid-pch" "-Wmissing-field-initializers" "-Wmissing-include-dirs" "-Wredundant-decls" "-Wshadow" "-Wsign-compare" "-Wsign-conversion" "-Wundef" "-Wuninitialized" "-Wwrite-strings" "-fno-strict-aliasing" "-fvisibility=hidden" "-fstack-protector" "-g3" "-DNDEBUG" "-c" "-o/private/var/folders/s8/0tz3dy0d1sbg1_cv0ylkx_m80000gn/T/tmp27ah1k33/target/x86_64-unknown-linux-gnu/release/build/ring-1b5ef9a99e86a98a/out/aesni-x86_64-elf.o" "/Users/rvalls/.cargo/registry/src/github.com-1ecc6299db9ec823/ring-0.16.20/pregenerated/aesni-x86_64-elf.S"
  /Users/rvalls/.cargo/registry/src/github.com-1ecc6299db9ec823/ring-0.16.20/pregenerated/aesni-x86_64-elf.S:1181:19: error: unexpected token in '.section' directive
  .section .note.GNU-stack,"",@progbits
                    ^
  thread 'main' panicked at 'execution failed', /Users/rvalls/.cargo/registry/src/github.com-1ecc6299db9ec823/ring-0.16.20/build.rs:656:9
  note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
warning: build failed, waiting for other jobs to finish...
error: build failed
make: *** [build-s3Bam] Error 101

Expected result:

I expect sam build to correctly cross-compile a x86_64-unknown-linux-gnu Rust lambda that runs on a provided.al2 container without involving MUSL.

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

  1. OS: Apple Silicon running OSX Big Sur 11.4
  2. sam --version: SAM CLI, version 1.27.2
  3. AWS region: local, ap-southeast-2 otherwise
@brainstorm
Copy link
Author

brainstorm commented Aug 3, 2021

For completeness, here's the containers that I have on docker images so far:

amazon/aws-sam-cli-emulation-image-provided.al2   rapid-1.27.2                   6e864f19bc63   5 days ago     244MB
public.ecr.aws/sam/build-provided.al2             latest                         4f70a87adc2f   11 days ago    1.88GB
amazon/aws-sam-cli-emulation-image-provided.al2   latest                         70efd43277f7   11 days ago    227MB
amazon/aws-sam-cli-emulation-image-provided.al2   rapid-1.24.1                   9f3e53a81136   6 weeks ago    244MB
amazon/aws-sam-cli-emulation-image-provided.al2   <none>                         b688c0edef90   7 weeks ago    227MB
amazon/aws-sam-cli-emulation-image-python3.8      rapid-1.22.0.dev202104291816   857b0163bb0b   2 months ago   516MB
amazon/aws-sam-cli-emulation-image-python3.8      latest                         a2d941bb092d   2 months ago   500MB

But it doesn't matter because after wiping them all:

docker images | grep aws | awk -P '{ print $3 }' | xargs docker rmi

and rerunning sam build so that it only picks up the provided.al2:latest container, the results show above remain the same:

aws_lambda_builders.workflows.custom_make.make.MakeExecutionError: Make Failed: make: cargo: Command not found

Which leads me to believe that passing environment variables might wipe or mangle $PATH too within the container?

@brainstorm brainstorm changed the title Different containers used in "sam build" vs "sam build -u -e TARGET_CC=foo"? "sam build -u -e TARGET_CC=foo" leads to "cargo: Command not found" Aug 3, 2021
@sriram-mv sriram-mv added stage/needs-investigation Requires a deeper investigation area/build sam build command labels Aug 3, 2021
@jfuss
Copy link
Contributor

jfuss commented Aug 3, 2021

@brainstorm sam build is not the same thing as sam build -u. sam build without the -u runs on your machine not a docker image. So I assume you are not seeing Cargo: Command not found when running sam build because you have Cargo installed.

In your case, the public.ecr.aws/sam/build-provided.al2 is use when using -u (this depend on what the function runtime is), which does not include Cargo. This is by design because we cannot add every language package manager/tooling into the container for build. That would make the image huge and impact performance. You can do the following to overcome this:

  1. In your Makefile, install Cargo.
  2. Create a new image that has Cargo installed and pass the new image to --build-image

1 will work but you will be installing Cargo over and over again for each build. Which will just make your build slower. So I recommend you to take the second path.

@jfuss jfuss added blocked/close-if-inactive Blocked for >14 days with no response, will be closed if still inactive after 7 days type/question and removed stage/needs-investigation Requires a deeper investigation labels Aug 3, 2021
@brainstorm
Copy link
Author

brainstorm commented Aug 4, 2021

Thanks @jfuss, I understand the issue better now, although I see that it'll get a bit more complex before it gets easier?:

index 09a3175..7515a02 100644
--- a/Makefile
+++ b/Makefile
@@ -1,6 +1,7 @@
 build-s3Bam:
 # TODO: Put conditional code depending on arch... for now it will lead to Exec error anyway though unless it's x86_64 provided.al2 :/
 # Intel GNU
+       curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
        cargo build --release --target x86_64-unknown-linux-gnu
        cp ./target/x86_64-unknown-linux-gnu/release/bootstrap $(ARTIFACTS_DIR)
 #

I'd like to build on top of provided.al2, but perhaps that container is a bit... hardened and not suitable for building? I'll have to check upstream's provided.al2 dockerfile, I guess, or switch to a more build-friendly container? The (dropbear? bash?) shell does not seem to play well with the cargo setup script:

% sam build -u -bi public.ecr.aws/sam/build-provided.al2
Starting Build inside a container
Building codeuri: /Users/rvalls/dev/umccr/s3-rust-noodles-bam runtime: provided.al2 metadata: {'BuildMethod': 'makefile'} functions: ['s3Bam']

Fetching public.ecr.aws/sam/build-provided.al2 Docker container image......
Mounting /Users/rvalls/dev/umccr/s3-rust-noodles-bam as /tmp/samcli/source:ro,delegated inside runtime container

Build Failed
Running CustomMakeBuilder:CopySource
Running CustomMakeBuilder:MakeBuild
Current Artifacts Directory : /tmp/samcli/artifacts
Error: CustomMakeBuilder:MakeBuild - Make Failed: /usr/bin/head: error reading ‘/proc/self/exe’: Bad file descriptor
/usr/bin/head: failed to close ‘/proc/self/exe’: Bad file descriptor
rustup: unknown platform bitness
/usr/bin/sh: line 358: [: : integer expression expected
info: downloading installer
rustup: Unable to run interactively. Run with -y to accept defaults, --help for additional options
make: *** [build-s3Bam] Error 1

Also, how can I define a build-only target on the same Makefile without interfering with the default sam build host-only target? I'm thinking about:

 % git diff Makefile
diff --git a/Makefile b/Makefile
index 09a3175..614bb06 100644
--- a/Makefile
+++ b/Makefile
@@ -1,6 +1,9 @@
+build-only-container:
+        curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
+ # TODO: Other build-only related commands
+        cargo build --release --target x86_64-unknown-linux-gnu
+        cp ./target/x86_64-unknown-linux-gnu/release/bootstrap $(ARTIFACTS_DIR)
# Host-only sam build target
 build-s3Bam:
        cargo build --release --target x86_64-unknown-linux-gnu
        cp ./target/x86_64-unknown-linux-gnu/release/bootstrap $(ARTIFACTS_DIR)

Or perhaps I should drop sam build -bi and build the container separatedly outside the SAM CLI?

See https://github.com/umccr/s3-rust-noodles-bam/blob/d93d79a7e9d78e54bfb0cf141350f28986e26463/Makefile for more context.

@brainstorm
Copy link
Author

Also, is it possible to pass a --volumes equivalent to sam build so I can source scripts and run them on the container context?

@jfuss
Copy link
Contributor

jfuss commented Aug 9, 2021

I'd like to build on top of provided.al2, but perhaps that container is a bit... hardened and not suitable for building?

Not sure what you mean by this. The build-provided.al1 image should be a good base. You may need to install tools you need into the image though.

Also, how can I define a build-only target on the same Makefile without interfering with the default sam build host-only target?

Not sure I understand the question here. Are you trying to build some functions locally, while others in a container? If so that is not supported. #1825 is similar to this and I don't think we have a specific issue to cover this use-case yet.

Also, is it possible to pass a --volumes equivalent to sam build so I can source scripts and run them on the container context?

No. You can provide a customer image but we don't allow mounting of volumes into the build container.

@brainstorm
Copy link
Author

brainstorm commented Aug 19, 2021

Not sure what you mean by this. The build-provided.al1 image should be a good base. You may need to install tools you need into the image though.

Sorry, I'll try to be more specific: provided.al1 images have a too old GLIBC for Rust lambdas, so I strongly prefer provided.al2 for anything Rust... also where can I pull that build-provided images from? public.ecr.aws/lambda/*?

I have been looking around the AWS ECR public registry here:

https://gallery.ecr.aws/?operatingSystems=Linux&architectures=x86-64%2Cx86&searchTerm=lambda

Not sure I understand the question here. Are you trying to build some functions locally, while others in a container? If so that is not supported. #1825 is similar to this and I don't think we have a specific issue to cover this use-case yet.

Apologies again, what I meant was whether there was a possibility to ship the container building "recipe"/Dockerfile along with the SAM cli project itself, as in:

make build <--- builds the container using the Makefile from SAM (pointed by template.yml)
make <--- builds the binaries/artifacts for SAM (default target)

But nevermind about this question, I guess that such a building container needs to be built separatedly now.

I'll now try and build a container with the docs I referred to above in https://github.com/aws/aws-lambda-base-images and report back, thanks for the support and guidance, @jfuss.

@brainstorm
Copy link
Author

So I went and did a:

$ git clone https://github.com/aws/aws-lambda-base-images
$ git checkout provided.al2
$ docker build -t provided.al2:latest . -f Dockerfile.provided.al2

Which built provided.al2:latest, but then on sam build time I got:

$ sam --version
SAM CLI, version 1.28.0
$ sam build -u -bi provided.al2:latest
Starting Build inside a container
Building codeuri: /Users/rvalls/dev/umccr/s3-rust-noodles-bam runtime: provided.al2 metadata: {'BuildMethod': 'makefile'} functions: ['s3Bam']
Failed to download a new provided.al2:latest image. Invoking with the already downloaded image.
Mounting /Users/rvalls/dev/umccr/s3-rust-noodles-bam as /tmp/samcli/source:ro,delegated inside runtime container

Build Failed
Error: You are running an outdated version of Docker container 'provided.al2:latest' that is not compatible withthis version of SAM CLI. Please upgrade to continue to continue with build. Reason: 'lambda-builders executable not found in container'

Which is a confusing error messages because the base-images repo seems to be updated quite recently and frequently:

https://github.com/aws/aws-lambda-base-images/commits/provided.al2

Is there an easy way to bypass that "not compatible withthis version of SAM CLI" before changing SAM CLI's code?

@brainstorm
Copy link
Author

I've now found https://github.com/aws/aws-sam-build-images/blob/develop/build-image-src/Dockerfile-provided-al2 ... which I guess it's the proper official SAM CLI lambda docker image(s).

@brainstorm
Copy link
Author

brainstorm commented Aug 23, 2021

Some progress while using docker buildx build on my M1 with the official SAM cli provided-al2 docker images.

Given those minor changes (installing the rust toolchain via rustup):

Dockerfile-provided-al2 diff, just adding Rust toolchain
diff --git a/build-image-src/Dockerfile-provided-al2 b/build-image-src/Dockerfile-provided-al2
index 4c08d59..0225860 100644
--- a/build-image-src/Dockerfile-provided-al2
+++ b/build-image-src/Dockerfile-provided-al2
@@ -42,7 +42,12 @@ RUN curl -L "https://github.com/awslabs/aws-sam-cli/archive/v$SAM_CLI_VERSION.zi
   /usr/local/opt/sam-cli/bin/pip3 --no-cache-dir install ./aws-sam-cli-$SAM_CLI_VERSION && \
   rm samcli.zip && rm -rf aws-sam-cli-$SAM_CLI_VERSION

-ENV PATH=$PATH:/usr/local/opt/sam-cli/bin
+# Install cargo and other Rust friends
+RUN curl -L "https://sh.rustup.rs" -o "rustup.sh"
+RUN chmod +x rustup.sh && sh rustup.sh -y
+RUN ls -alh $HOME/.cargo/bin/
+
+ENV PATH=$PATH:/usr/local/opt/sam-cli/bin:$HOME/.cargo/bin

 ENV LANG=en_US.UTF-8

And then rebuilding the container via docker cross-building:

Building provided-al2 container via "docker buildx build --platform=linux/amd64..."
% docker buildx build --progress tty --platform=linux/amd64 -f Dockerfile-provided-al2 -t amazon/aws-sam-cli-build-image-provided.al2 --build-arg SAM_CLI_VERSION=$SAM_CLI_VERSION .
[+] Building 113.4s (18/18) FINISHED
 => [internal] load build definition from Dockerfile-provided-al2                                                                                                                                                                                                                                                                                                                                                                                                                                 0.4s
 => => transferring dockerfile: 45B                                                                                                                                                                                                                                                                                                                                                                                                                                                               0.0s
 => [internal] load .dockerignore                                                                                                                                                                                                                                                                                                                                                                                                                                                                 0.6s
 => => transferring context: 2B                                                                                                                                                                                                                                                                                                                                                                                                                                                                   0.0s
 => [internal] load metadata for docker.io/amazon/aws-sam-cli-emulation-image-java8.al2:latest                                                                                                                                                                                                                                                                                                                                                                                                    1.6s
 => [internal] load metadata for docker.io/library/amazonlinux:2                                                                                                                                                                                                                                                                                                                                                                                                                                  1.7s
 => [stage-1 1/3] FROM docker.io/library/amazonlinux:2@sha256:93e55c026fe5dba304ff3f24690b07cb39f610b160844a575bb8f3fec41b3a5e                                                                                                                                                                                                                                                                                                                                                                    0.0s
 => [internal] load build context                                                                                                                                                                                                                                                                                                                                                                                                                                                                 0.4s
 => => transferring context: 38B                                                                                                                                                                                                                                                                                                                                                                                                                                                                  0.0s
 => [stage-0 1/1] FROM docker.io/amazon/aws-sam-cli-emulation-image-java8.al2@sha256:fd619bdf4ebe812b54784c8d6f28af25730a76337e7acd088dad3e9065fcdbf8                                                                                                                                                                                                                                                                                                                                             0.2s
 => => resolve docker.io/amazon/aws-sam-cli-emulation-image-java8.al2@sha256:fd619bdf4ebe812b54784c8d6f28af25730a76337e7acd088dad3e9065fcdbf8                                                                                                                                                                                                                                                                                                                                                     0.2s
 => CACHED [stage-1 2/3] COPY --from=0 / /rootfs                                                                                                                                                                                                                                                                                                                                                                                                                                                  0.0s
 => CACHED [stage-1 3/3] RUN yum groupinstall -y development --installroot=/rootfs &&   yum install -d1 --installroot=/rootfs -y   yum   tar   gzip   unzip   python3   jq   grep   curl   make   rsync   binutils   gcc-c++   procps   libgmp3-dev   zlib1g-dev   liblzma-dev   libxslt-devel   libmpc-devel   && yum clean all                                                                                                                                                                  0.0s
 => CACHED [stage-2 2/9] COPY --from=1 /rootfs /                                                                                                                                                                                                                                                                                                                                                                                                                                                  0.0s
 => CACHED [stage-2 3/9] RUN curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip" && unzip awscliv2.zip && ./aws/install && rm awscliv2.zip && rm -rf ./aws                                                                                                                                                                                                                                                                                                          0.0s
 => CACHED [stage-2 4/9] RUN curl -L "https://github.com/awslabs/aws-sam-cli/archive/v1.28.0.zip" -o "samcli.zip" &&   unzip samcli.zip && python3 -m venv /usr/local/opt/sam-cli &&   /usr/local/opt/sam-cli/bin/pip3 --no-cache-dir install -r ./aws-sam-cli-1.28.0/requirements/reproducible-linux.txt &&   /usr/local/opt/sam-cli/bin/pip3 --no-cache-dir install ./aws-sam-cli-1.28.0 &&   rm samcli.zip && rm -rf aws-sam-cli-1.28.0                                                        0.0s
 => [stage-2 5/9] RUN curl -L "https://sh.rustup.rs" -o "rustup.sh"                                                                                                                                                                                                                                                                                                                                                                                                                               1.8s
 => [stage-2 6/9] RUN chmod +x rustup.sh && sh rustup.sh -y                                                                                                                                                                                                                                                                                                                                                                                                                                      97.2s
 => [stage-2 7/9] RUN ls -alh $HOME/.cargo/bin/                                                                                                                                                                                                                                                                                                                                                                                                                                                   1.6s
 => [stage-2 8/9] RUN pip3 install wheel                                                                                                                                                                                                                                                                                                                                                                                                                                                          4.5s
 => [stage-2 9/9] COPY ATTRIBUTION.txt /                                                                                                                                                                                                                                                                                                                                                                                                                                                          0.9s
 => exporting to image                                                                                                                                                                                                                                                                                                                                                                                                                                                                            4.2s
 => => exporting layers                                                                                                                                                                                                                                                                                                                                                                                                                                                                           3.9s
 => => writing image sha256:d37f65f4ead6d286f07b344409e0e0a30a39bb08a2fd8652afde09e63d615f7a                                                                                                                                                                                                                                                                                                                                                                                                      0.0s
 => => naming to docker.io/amazon/aws-sam-cli-build-image-provided.al2

Cargo is not being found because of $PATH issues:

Cargo not found
% sam build --debug -u -bi amazon/aws-sam-cli-build-image-provided.al2 --skip-pull-image -e PATH=$PATH:/home/ec2-user/.cargo/bin
2021-08-23 15:35:48,641 | Telemetry endpoint configured to be https://aws-serverless-tools-telemetry.us-west-2.amazonaws.com/metrics
2021-08-23 15:35:48,641 | Using config file: samconfig.toml, config environment: default
2021-08-23 15:35:48,641 | Expand command line arguments to:
2021-08-23 15:35:48,641 | --template_file=/Users/rvalls/dev/umccr/s3-rust-noodles-bam/template.yml --use_container --build_image=('amazon/aws-sam-cli-build-image-provided.al2',) --skip_pull_image --container_env_var=('PATH=/opt/homebrew/opt/curl/bin:/Users/rvalls/.mambaforge/bin:/Users/rvalls/.mambaforge/condabin:/opt/homebrew/opt/coreutils/libexec/gnubin:/usr/local/bin:/opt/homebrew/bin:/opt/homebrew/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:/Library/Apple/usr/bin:/Users/rvalls/.cargo/bin:/home/ec2-user/.cargo/bin',) --build_dir=.aws-sam/build --cache_dir=.aws-sam/cache
2021-08-23 15:35:48,697 | 'build' command is called
2021-08-23 15:35:48,697 | Starting Build inside a container
2021-08-23 15:35:48,699 | No Parameters detected in the template
2021-08-23 15:35:48,711 | 2 stacks found in the template
2021-08-23 15:35:48,711 | No Parameters detected in the template
2021-08-23 15:35:48,727 | 2 resources found in the stack
2021-08-23 15:35:48,727 | No Parameters detected in the template
2021-08-23 15:35:48,736 | Found Serverless function with name='s3Bam' and CodeUri='.'
2021-08-23 15:35:48,736 | --base-dir is not presented, adjusting uri . relative to /Users/rvalls/dev/umccr/s3-rust-noodles-bam/template.yml
2021-08-23 15:35:48,736 | No Parameters detected in the template
2021-08-23 15:35:48,747 | Instantiating build definitions
2021-08-23 15:35:48,749 | Unique function build definition found, adding as new (Function Build Definition: BuildDefinition(provided.al2, /Users/rvalls/dev/umccr/s3-rust-noodles-bam, Zip, , 6820be7d-0ff1-4e23-9eb1-03994e2db6f4, {'BuildMethod': 'makefile'}, {'PATH': '/opt/homebrew/opt/curl/bin:/Users/rvalls/.mambaforge/bin:/Users/rvalls/.mambaforge/condabin:/opt/homebrew/opt/coreutils/libexec/gnubin:/usr/local/bin:/opt/homebrew/bin:/opt/homebrew/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:/Library/Apple/usr/bin:/Users/rvalls/.cargo/bin:/home/ec2-user/.cargo/bin'}, []), Function: Function(name='s3Bam', functionname='s3-bamheader', runtime='provided.al2', memory=128, timeout=30, handler='bootstrap.is.real.handler', imageuri=None, packagetype='Zip', imageconfig=None, codeuri='/Users/rvalls/dev/umccr/s3-rust-noodles-bam', environment=None, rolearn=None, layers=[], events={'RootEvent': {'Type': 'Api', 'Properties': {'Path': '/', 'Method': 'any', 'RestApiId': 'ServerlessRestApi'}}, 'GatewayEvent': {'Type': 'Api', 'Properties': {'Path': '/{proxy+}', 'Method': 'any', 'RestApiId': 'ServerlessRestApi'}}}, metadata={'BuildMethod': 'makefile'}, inlinecode=None, codesign_config_arn=None, stack_path=''))
2021-08-23 15:35:48,750 | Building codeuri: /Users/rvalls/dev/umccr/s3-rust-noodles-bam runtime: provided.al2 metadata: {'BuildMethod': 'makefile'} functions: ['s3Bam']
2021-08-23 15:35:48,750 | Building to following folder /Users/rvalls/dev/umccr/s3-rust-noodles-bam/.aws-sam/build/s3Bam
2021-08-23 15:35:48,771 | Requested to skip pulling images ...

2021-08-23 15:35:48,771 | Mounting /Users/rvalls/dev/umccr/s3-rust-noodles-bam as /tmp/samcli/source:ro,delegated inside runtime container

Build Failed
2021-08-23 15:35:52,253 | Sending Telemetry: {'metrics': [{'commandRun': {'requestId': '7a75ec26-92e1-485d-9709-1c5578c2319d', 'installationId': 'b0a4feb6-813d-4f61-952f-5919f29d6b17', 'sessionId': '160f561e-7cd4-4367-bcd0-9a4d47be20e8', 'executionEnvironment': 'CLI', 'ci': False, 'pyversion': '3.8.11', 'samcliVersion': '1.28.0', 'awsProfileProvided': False, 'debugFlagProvided': True, 'region': '', 'commandName': 'sam build', 'duration': 3611, 'exitReason': 'UnsupportedBuilderLibraryVersionError', 'exitCode': 1}}]}
2021-08-23 15:35:53,098 | HTTPSConnectionPool(host='aws-serverless-tools-telemetry.us-west-2.amazonaws.com', port=443): Read timed out. (read timeout=0.1)
Error: You are running an outdated version of Docker container 'amazon/aws-sam-cli-build-image-provided.al2' that is not compatible withthis version of SAM CLI. Please upgrade to continue to continue with build. Reason: 'lambda-builders executable not found in container'
(base) rvalls@m1 s3-rust-noodles-bam % sam build --debug -u -bi amazon/aws-sam-cli-build-image-provided.al2 --skip-pull-image
2021-08-23 15:40:33,061 | Telemetry endpoint configured to be https://aws-serverless-tools-telemetry.us-west-2.amazonaws.com/metrics
2021-08-23 15:40:33,061 | Using config file: samconfig.toml, config environment: default
2021-08-23 15:40:33,061 | Expand command line arguments to:
2021-08-23 15:40:33,062 | --template_file=/Users/rvalls/dev/umccr/s3-rust-noodles-bam/template.yml --use_container --build_image=('amazon/aws-sam-cli-build-image-provided.al2',) --skip_pull_image --build_dir=.aws-sam/build --cache_dir=.aws-sam/cache
2021-08-23 15:40:33,137 | 'build' command is called
2021-08-23 15:40:33,137 | Starting Build inside a container
2021-08-23 15:40:33,139 | No Parameters detected in the template
2021-08-23 15:40:33,151 | 2 stacks found in the template
2021-08-23 15:40:33,151 | No Parameters detected in the template
2021-08-23 15:40:33,168 | 2 resources found in the stack
2021-08-23 15:40:33,169 | No Parameters detected in the template
2021-08-23 15:40:33,178 | Found Serverless function with name='s3Bam' and CodeUri='.'
2021-08-23 15:40:33,178 | --base-dir is not presented, adjusting uri . relative to /Users/rvalls/dev/umccr/s3-rust-noodles-bam/template.yml
2021-08-23 15:40:33,178 | No Parameters detected in the template
2021-08-23 15:40:33,189 | Instantiating build definitions
2021-08-23 15:40:33,192 | Unique function build definition found, adding as new (Function Build Definition: BuildDefinition(provided.al2, /Users/rvalls/dev/umccr/s3-rust-noodles-bam, Zip, , af6db324-c90e-4f89-9c33-84dec6d7ac8d, {'BuildMethod': 'makefile'}, {}, []), Function: Function(name='s3Bam', functionname='s3-bamheader', runtime='provided.al2', memory=128, timeout=30, handler='bootstrap.is.real.handler', imageuri=None, packagetype='Zip', imageconfig=None, codeuri='/Users/rvalls/dev/umccr/s3-rust-noodles-bam', environment=None, rolearn=None, layers=[], events={'RootEvent': {'Type': 'Api', 'Properties': {'Path': '/', 'Method': 'any', 'RestApiId': 'ServerlessRestApi'}}, 'GatewayEvent': {'Type': 'Api', 'Properties': {'Path': '/{proxy+}', 'Method': 'any', 'RestApiId': 'ServerlessRestApi'}}}, metadata={'BuildMethod': 'makefile'}, inlinecode=None, codesign_config_arn=None, stack_path=''))
2021-08-23 15:40:33,194 | Building codeuri: /Users/rvalls/dev/umccr/s3-rust-noodles-bam runtime: provided.al2 metadata: {'BuildMethod': 'makefile'} functions: ['s3Bam']
2021-08-23 15:40:33,194 | Building to following folder /Users/rvalls/dev/umccr/s3-rust-noodles-bam/.aws-sam/build/s3Bam
2021-08-23 15:40:33,223 | Requested to skip pulling images ...

2021-08-23 15:40:33,223 | Mounting /Users/rvalls/dev/umccr/s3-rust-noodles-bam as /tmp/samcli/source:ro,delegated inside runtime container
Using the request object from command line argument
Loading workflow module 'aws_lambda_builders.workflows'
Registering workflow 'PythonPipBuilder' with capability 'Capability(language='python', dependency_manager='pip', application_framework=None)'
Registering workflow 'NodejsNpmBuilder' with capability 'Capability(language='nodejs', dependency_manager='npm', application_framework=None)'
Registering workflow 'RubyBundlerBuilder' with capability 'Capability(language='ruby', dependency_manager='bundler', application_framework=None)'
Registering workflow 'GoDepBuilder' with capability 'Capability(language='go', dependency_manager='dep', application_framework=None)'
Registering workflow 'GoModulesBuilder' with capability 'Capability(language='go', dependency_manager='modules', application_framework=None)'
Registering workflow 'JavaGradleWorkflow' with capability 'Capability(language='java', dependency_manager='gradle', application_framework=None)'
Registering workflow 'JavaMavenWorkflow' with capability 'Capability(language='java', dependency_manager='maven', application_framework=None)'
Registering workflow 'DotnetCliPackageBuilder' with capability 'Capability(language='dotnet', dependency_manager='cli-package', application_framework=None)'
Registering workflow 'CustomMakeBuilder' with capability 'Capability(language='provided', dependency_manager=None, application_framework=None)'
Found workflow 'CustomMakeBuilder' to support capabilities 'Capability(language='provided', dependency_manager=None, application_framework=None)'
Running workflow 'CustomMakeBuilder'
Running CustomMakeBuilder:CopySource
CustomMakeBuilder:CopySource succeeded
Running CustomMakeBuilder:MakeBuild
Current Artifacts Directory : /tmp/samcli/artifacts
executing Make: ['make', '--makefile', '/tmp/samcli/source/Makefile', 'build-s3Bam']
CustomMakeBuilder:MakeBuild failed
Traceback (most recent call last):
  File "/usr/local/opt/sam-cli/lib64/python3.7/site-packages/aws_lambda_builders/workflows/custom_make/actions.py", line 94, in execute
    cwd=self.scratch_dir,
  File "/usr/local/opt/sam-cli/lib64/python3.7/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: cargo: Command not found
make: *** [build-s3Bam] Error 127

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/opt/sam-cli/lib64/python3.7/site-packages/aws_lambda_builders/workflow.py", line 269, in run
    action.execute()
  File "/usr/local/opt/sam-cli/lib64/python3.7/site-packages/aws_lambda_builders/workflows/custom_make/actions.py", line 97, in execute
    raise ActionFailedError(str(ex))
aws_lambda_builders.actions.ActionFailedError: Make Failed: make: cargo: Command not found
make: *** [build-s3Bam] Error 127
Builder workflow failed
Traceback (most recent call last):
  File "/usr/local/opt/sam-cli/lib64/python3.7/site-packages/aws_lambda_builders/workflows/custom_make/actions.py", line 94, in execute
    cwd=self.scratch_dir,
  File "/usr/local/opt/sam-cli/lib64/python3.7/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: cargo: Command not found
make: *** [build-s3Bam] Error 127

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/opt/sam-cli/lib64/python3.7/site-packages/aws_lambda_builders/workflow.py", line 269, in run
    action.execute()
  File "/usr/local/opt/sam-cli/lib64/python3.7/site-packages/aws_lambda_builders/workflows/custom_make/actions.py", line 97, in execute
    raise ActionFailedError(str(ex))
aws_lambda_builders.actions.ActionFailedError: Make Failed: make: cargo: Command not found
make: *** [build-s3Bam] Error 127

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/opt/sam-cli/lib64/python3.7/site-packages/aws_lambda_builders/__main__.py", line 126, in main
    mode=params.get("mode", None),
  File "/usr/local/opt/sam-cli/lib64/python3.7/site-packages/aws_lambda_builders/builder.py", line 125, in build
    return workflow.run()
  File "/usr/local/opt/sam-cli/lib64/python3.7/site-packages/aws_lambda_builders/workflow.py", line 76, in wrapper
    func(self, *args, **kwargs)
  File "/usr/local/opt/sam-cli/lib64/python3.7/site-packages/aws_lambda_builders/workflow.py", line 276, in run
    raise WorkflowFailedError(workflow_name=self.NAME, action_name=action.NAME, reason=str(ex))
aws_lambda_builders.exceptions.WorkflowFailedError: CustomMakeBuilder:MakeBuild - Make Failed: make: cargo: Command not found
make: *** [build-s3Bam] Error 127
2021-08-23 15:42:12,018 | Build inside container returned response {"jsonrpc": "2.0", "id": 1, "error": {"code": 400, "message": "CustomMakeBuilder:MakeBuild - Make Failed: make: cargo: Command not found\nmake: *** [build-s3Bam] Error 127"}}

Build Failed
2021-08-23 15:42:15,593 | Sending Telemetry: {'metrics': [{'commandRun': {'requestId': 'd3bea992-dfd1-4e66-88a0-de73064136ed', 'installationId': 'b0a4feb6-813d-4f61-952f-5919f29d6b17', 'sessionId': 'cc4826ec-cc8d-4394-9c38-15d6fd4f4591', 'executionEnvironment': 'CLI', 'ci': False, 'pyversion': '3.8.11', 'samcliVersion': '1.28.0', 'awsProfileProvided': False, 'debugFlagProvided': True, 'region': '', 'commandName': 'sam build', 'duration': 102528, 'exitReason': 'BuildInsideContainerError', 'exitCode': 1}}]}
2021-08-23 15:42:16,408 | HTTPSConnectionPool(host='aws-serverless-tools-telemetry.us-west-2.amazonaws.com', port=443): Read timed out. (read timeout=0.1)
Error: CustomMakeBuilder:MakeBuild - Make Failed: make: cargo: Command not found
make: *** [build-s3Bam] Error 127

But then, when passing -e PATH=$PATH:/home/ec2-user/.cargo/bin to sam build I'm facing the following issue:

$PATH inside the container not appendable with `sam build -e`?
(base) rvalls@m1 s3-rust-noodles-bam % sam build --debug -u -bi amazon/aws-sam-cli-build-image-provided.al2 --skip-pull-image -e PATH=$PATH:/home/ec2-user/.cargo/bin

2021-08-23 15:51:23,428 | Telemetry endpoint configured to be https://aws-serverless-tools-telemetry.us-west-2.amazonaws.com/metrics
2021-08-23 15:51:23,428 | Using config file: samconfig.toml, config environment: default
2021-08-23 15:51:23,428 | Expand command line arguments to:
2021-08-23 15:51:23,428 | --template_file=/Users/rvalls/dev/umccr/s3-rust-noodles-bam/template.yml --use_container --build_image=('amazon/aws-sam-cli-build-image-provided.al2',) --skip_pull_image --container_env_var=('PATH=/opt/homebrew/opt/curl/bin:/Users/rvalls/.mambaforge/bin:/Users/rvalls/.mambaforge/condabin:/opt/homebrew/opt/coreutils/libexec/gnubin:/usr/local/bin:/opt/homebrew/bin:/opt/homebrew/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:/Library/Apple/usr/bin:/Users/rvalls/.cargo/bin:/home/ec2-user/.cargo/bin',) --build_dir=.aws-sam/build --cache_dir=.aws-sam/cache
2021-08-23 15:51:23,457 | 'build' command is called
2021-08-23 15:51:23,457 | Starting Build inside a container
2021-08-23 15:51:23,459 | No Parameters detected in the template
2021-08-23 15:51:23,471 | 2 stacks found in the template
2021-08-23 15:51:23,471 | No Parameters detected in the template
2021-08-23 15:51:23,487 | 2 resources found in the stack
2021-08-23 15:51:23,487 | No Parameters detected in the template
2021-08-23 15:51:23,496 | Found Serverless function with name='s3Bam' and CodeUri='.'
2021-08-23 15:51:23,497 | --base-dir is not presented, adjusting uri . relative to /Users/rvalls/dev/umccr/s3-rust-noodles-bam/template.yml
2021-08-23 15:51:23,497 | No Parameters detected in the template
2021-08-23 15:51:23,507 | Instantiating build definitions
2021-08-23 15:51:23,510 | Unique function build definition found, adding as new (Function Build Definition: BuildDefinition(provided.al2, /Users/rvalls/dev/umccr/s3-rust-noodles-bam, Zip, , 42c58a46-681a-40d6-b870-0220c2ec8751, {'BuildMethod': 'makefile'}, {'PATH': '/opt/homebrew/opt/curl/bin:/Users/rvalls/.mambaforge/bin:/Users/rvalls/.mambaforge/condabin:/opt/homebrew/opt/coreutils/libexec/gnubin:/usr/local/bin:/opt/homebrew/bin:/opt/homebrew/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:/Library/Apple/usr/bin:/Users/rvalls/.cargo/bin:/home/ec2-user/.cargo/bin'}, []), Function: Function(name='s3Bam', functionname='s3-bamheader', runtime='provided.al2', memory=128, timeout=30, handler='bootstrap.is.real.handler', imageuri=None, packagetype='Zip', imageconfig=None, codeuri='/Users/rvalls/dev/umccr/s3-rust-noodles-bam', environment=None, rolearn=None, layers=[], events={'RootEvent': {'Type': 'Api', 'Properties': {'Path': '/', 'Method': 'any', 'RestApiId': 'ServerlessRestApi'}}, 'GatewayEvent': {'Type': 'Api', 'Properties': {'Path': '/{proxy+}', 'Method': 'any', 'RestApiId': 'ServerlessRestApi'}}}, metadata={'BuildMethod': 'makefile'}, inlinecode=None, codesign_config_arn=None, stack_path=''))
2021-08-23 15:51:23,511 | Building codeuri: /Users/rvalls/dev/umccr/s3-rust-noodles-bam runtime: provided.al2 metadata: {'BuildMethod': 'makefile'} functions: ['s3Bam']
2021-08-23 15:51:23,511 | Building to following folder /Users/rvalls/dev/umccr/s3-rust-noodles-bam/.aws-sam/build/s3Bam
2021-08-23 15:51:23,524 | Requested to skip pulling images ...

2021-08-23 15:51:23,524 | Mounting /Users/rvalls/dev/umccr/s3-rust-noodles-bam as /tmp/samcli/source:ro,delegated inside runtime container

Build Failed
2021-08-23 15:51:26,281 | Sending Telemetry: {'metrics': [{'commandRun': {'requestId': '3a3a6221-9cb3-4bad-a828-bcfd7cd671fa', 'installationId': 'b0a4feb6-813d-4f61-952f-5919f29d6b17', 'sessionId': '8196b43f-8961-49f2-bcc9-d791df4c0102', 'executionEnvironment': 'CLI', 'ci': False, 'pyversion': '3.8.11', 'samcliVersion': '1.28.0', 'awsProfileProvided': False, 'debugFlagProvided': True, 'region': '', 'commandName': 'sam build', 'duration': 2852, 'exitReason': 'UnsupportedBuilderLibraryVersionError', 'exitCode': 1}}]}
2021-08-23 15:51:27,228 | HTTPSConnectionPool(host='aws-serverless-tools-telemetry.us-west-2.amazonaws.com', port=443): Read timed out. (read timeout=0.1)
Error: You are running an outdated version of Docker container 'amazon/aws-sam-cli-build-image-provided.al2' that is not compatible withthis version of SAM CLI. Please upgrade to continue to continue with build. Reason: 'lambda-builders executable not found in container'

Telemetry most likely fails because when passing the new -e option to sam build messes up with the internal docker $PATH (probably passing in my actual's shell $PATH from the host?).

I'll keep digging on this, but happy to hear feedback if there's an easier path to all this, @jfuss et al ;)

@brainstorm
Copy link
Author

brainstorm commented Aug 23, 2021

Unfortunately, passing in an env.json file to avoid the hosts's shell expansion of env vars while using -ef instead of -e with the following command arrangement:

sam build --debug -u -bi amazon/aws-sam-cli-build-image-provided.al2 --skip-pull-image -ef env_vars.json

{
        "Parameters": {
                "PATH": "$PATH:$HOME/.cargo/bin"
        }
}

Yields similar results:

% sam build --debug -u -bi amazon/aws-sam-cli-build-image-provided.al2 --skip-pull-image -ef env_vars.json
2021-08-23 16:14:32,135 | Telemetry endpoint configured to be https://aws-serverless-tools-telemetry.us-west-2.amazonaws.com/metrics
2021-08-23 16:14:32,135 | Using config file: samconfig.toml, config environment: default
2021-08-23 16:14:32,135 | Expand command line arguments to:
2021-08-23 16:14:32,135 | --template_file=/Users/rvalls/dev/umccr/s3-rust-noodles-bam/template.yml --use_container --build_image=('amazon/aws-sam-cli-build-image-provided.al2',) --skip_pull_image --container_env_var_file=env_vars.json --build_dir=.aws-sam/build --cache_dir=.aws-sam/cache
2021-08-23 16:14:32,184 | 'build' command is called
2021-08-23 16:14:32,184 | Starting Build inside a container
2021-08-23 16:14:32,186 | No Parameters detected in the template
2021-08-23 16:14:32,197 | 2 stacks found in the template
2021-08-23 16:14:32,197 | No Parameters detected in the template
2021-08-23 16:14:32,213 | 2 resources found in the stack
2021-08-23 16:14:32,213 | No Parameters detected in the template
2021-08-23 16:14:32,222 | Found Serverless function with name='s3Bam' and CodeUri='.'
2021-08-23 16:14:32,223 | --base-dir is not presented, adjusting uri . relative to /Users/rvalls/dev/umccr/s3-rust-noodles-bam/template.yml
2021-08-23 16:14:32,223 | No Parameters detected in the template
2021-08-23 16:14:32,233 | Instantiating build definitions
2021-08-23 16:14:32,235 | Unique function build definition found, adding as new (Function Build Definition: BuildDefinition(provided.al2, /Users/rvalls/dev/umccr/s3-rust-noodles-bam, Zip, , af11c4f7-fda4-4c47-a919-7ede4330a06a, {'BuildMethod': 'makefile'}, {'PATH': '.cargo/bin'}, []), Function: Function(name='s3Bam', functionname='s3-bamheader', runtime='provided.al2', memory=128, timeout=30, handler='bootstrap.is.real.handler', imageuri=None, packagetype='Zip', imageconfig=None, codeuri='/Users/rvalls/dev/umccr/s3-rust-noodles-bam', environment=None, rolearn=None, layers=[], events={'RootEvent': {'Type': 'Api', 'Properties': {'Path': '/', 'Method': 'any', 'RestApiId': 'ServerlessRestApi'}}, 'GatewayEvent': {'Type': 'Api', 'Properties': {'Path': '/{proxy+}', 'Method': 'any', 'RestApiId': 'ServerlessRestApi'}}}, metadata={'BuildMethod': 'makefile'}, inlinecode=None, codesign_config_arn=None, stack_path=''))
2021-08-23 16:14:32,236 | Building codeuri: /Users/rvalls/dev/umccr/s3-rust-noodles-bam runtime: provided.al2 metadata: {'BuildMethod': 'makefile'} functions: ['s3Bam']
2021-08-23 16:14:32,236 | Building to following folder /Users/rvalls/dev/umccr/s3-rust-noodles-bam/.aws-sam/build/s3Bam
2021-08-23 16:14:32,248 | Requested to skip pulling images ...

2021-08-23 16:14:32,248 | Mounting /Users/rvalls/dev/umccr/s3-rust-noodles-bam as /tmp/samcli/source:ro,delegated inside runtime container

Build Failed
2021-08-23 16:14:35,584 | Sending Telemetry: {'metrics': [{'commandRun': {'requestId': '98913725-26d8-471c-8eba-070be1c88320', 'installationId': 'b0a4feb6-813d-4f61-952f-5919f29d6b17', 'sessionId': '167b2165-d8fc-4e22-bb47-186e19e01012', 'executionEnvironment': 'CLI', 'ci': False, 'pyversion': '3.8.11', 'samcliVersion': '1.28.0', 'awsProfileProvided': False, 'debugFlagProvided': True, 'region': '', 'commandName': 'sam build', 'duration': 3448, 'exitReason': 'UnsupportedBuilderLibraryVersionError', 'exitCode': 1}}]}
2021-08-23 16:14:36,403 | HTTPSConnectionPool(host='aws-serverless-tools-telemetry.us-west-2.amazonaws.com', port=443): Read timed out. (read timeout=0.1)
Error: You are running an outdated version of Docker container 'amazon/aws-sam-cli-build-image-provided.al2' that is not compatible withthis version of SAM CLI. Please upgrade to continue to continue with build. Reason: 'lambda-builders executable not found in container'

@prenx4x prenx4x removed the blocked/close-if-inactive Blocked for >14 days with no response, will be closed if still inactive after 7 days label Aug 30, 2021
@brainstorm
Copy link
Author

brainstorm commented Sep 28, 2021

Any ideas on how/what to tackle next here @prenx4x and @jfuss ? Pointers super welcome!

@brainstorm
Copy link
Author

Thanks to @hoffa I managed to fix this in aws/aws-sam-build-images#26 (comment) ... unfortunately the sam local start-api and sam local invoke -e event.json keep failing with exec format error, check the linked (closed) PR above for details.

@brainstorm
Copy link
Author

Nevermind, the AWS Rust team is doing a great job with cargo-lambda, SAM is not strictly needed anymore, AFAICT.

@0cv
Copy link

0cv commented May 7, 2022

Nevermind, the AWS Rust team is doing a great job with cargo-lambda, SAM is not strictly needed anymore, AFAICT.

yes, cargo lambda is great until one depends on native C library such as openssl, libsodium and the likes. Which is not unusual for any beyond "hello world" project... Then, you either figure out how to link to all the required .so or give up and rely on Docker. But build times are terrible on Docker, even with a prepared image. It appears that sam build -u never cache any build items nor dependencies, so that for every new build, cargo is going to 1- Download every crate and 2- Rebuild all modules and deps. It's a ~5 minutes build for a rather small project, thus essentially a no-go for local development. Well, the not so ideal workaround I found is to build a prepared image based on public.ecr.aws/sam/build-provided.al2:latest-x86_64, install all dependencies and create a base local image (what I already had). Then I've another incremental image which has the downloaded crates and pre-built, cached, dependencies. And instead of sam build, I "simply" copy the source files and do a regular cargo build inside that incremental image and then save it and extract the exec. Well, I don't know how others are doing, maybe I'm doing something wrong, or maybe I shall just use a Linux computer instead. Either way, I feel like sam build -u has some room for improvements

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants