(I just filed this bug report but perhaps someone here can answer.)
sam build
fails with the sam Hello World Example
when building for Image (Docker) deployment for x86_64
architecture on Apple M1 Silicon.
Under the hood, SAM will use docker to build a docker image. For some reason it's not working on my Mac. It works just fine from an AWS x86 Linux system running . So now I'm trying to run x86 AWS Linux in docker on my mac for that docker in docker
experience. I haven't gotten that working yet.
Here I create a simple SAM deployment with their Hello World example and Image deployment:
simsong@Simsons-MacBook-Pro ~ % sam init
You can preselect a particular runtime or package type when using the `sam init` experience.
Call `sam init --help` to learn more.
Which template source would you like to use?
1 - AWS Quick Start Templates
2 - Custom Template Location
Choice: 1
Choose an AWS Quick Start application template
1 - Hello World Example
2 - Data processing
3 - Hello World Example with Powertools for AWS Lambda
4 - Multi-step workflow
5 - Scheduled task
6 - Standalone function
7 - Serverless API
8 - Infrastructure event management
9 - Lambda Response Streaming
10 - Serverless Connector Hello World Example
11 - Multi-step workflow with Connectors
12 - GraphQLApi Hello World Example
13 - Full Stack
14 - Lambda EFS example
15 - DynamoDB Example
16 - Machine Learning
Template: 1
Use the most popular runtime and package type? (python3.13 and zip) [y/N]: N
Which runtime would you like to use?
1 - dotnet8
2 - dotnet6
3 - go (provided.al2)
4 - go (provided.al2023)
5 - graalvm.java11 (provided.al2)
6 - graalvm.java17 (provided.al2)
7 - java21
8 - java17
9 - java11
10 - java8.al2
11 - nodejs22.x
12 - nodejs20.x
13 - nodejs18.x
14 - nodejs16.x
15 - python3.9
16 - python3.8
17 - python3.13
18 - python3.12
19 - python3.11
20 - python3.10
21 - ruby3.3
22 - ruby3.2
23 - rust (provided.al2)
24 - rust (provided.al2023)
Runtime: 19
What package type would you like to use?
1 - Zip
2 - Image
Package type: 2
Based on your selections, the only dependency manager available is pip.
We will proceed copying the template using pip.
Would you like to enable X-Ray tracing on the function(s) in your application? [y/N]: N
Would you like to enable monitoring using CloudWatch Application Insights?
For more info, please view https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/cloudwatch-application-insights.html [y/N]: N
Would you like to set Structured Logging in JSON format on your Lambda functions? [y/N]: N
Project name [sam-app]: s3watch-image
-----------------------
Generating application:
-----------------------
Name: s3watch-image
Base Image: amazon/python3.11-base
Architectures: x86_64
Dependency Manager: pip
Output Directory: .
Configuration file: s3watch-image/samconfig.toml
Next steps can be found in the README file at s3watch-image/README.md
Commands you can use next
=========================
[*] Create pipeline: cd s3watch-image && sam pipeline init --bootstrap
[*] Validate SAM template: cd s3watch-image && sam validate
[*] Test Function in the Cloud: cd s3watch-image && sam sync --stack-name {stack-name} --watch
simsong@Simsons-MacBook-Pro ~ % sam init
simsong@Simsons-MacBook-Pro ~ % ls s3watch
drwxr-xr-x@ 11 simsong staff 352 Dec 3 06:29 s3watch
simsong@Simsons-MacBook-Pro ~ % cd s3watch-image
simsong@Simsons-MacBook-Pro s3watch-image % sam build
Building codeuri: /Users/simsong/s3watch-image runtime: None architecture: x86_64 functions: HelloWorldFunction
Building image for HelloWorldFunction function
Setting DockerBuildArgs for HelloWorldFunction function
Failed building function HelloWorldFunction
Build Failed
Error: failed to export image: NotFound: content digest sha256:d40a1d2caa9d01b32d5f0ce81782af06f49786c01729d03c6450ad78b06654c7: not found
simsong@Simsons-MacBook-Pro s3watch-image % sam build --debug
2024-12-03 06:32:31,563 | Config file location: /Users/simsong/s3watch-image/samconfig.toml
2024-12-03 06:32:31,565 | Loading configuration values from [default.['build'].parameters] (env.command_name.section) in config file at
'/Users/simsong/s3watch-image/samconfig.toml'...
2024-12-03 06:32:31,565 | Configuration values successfully loaded.
2024-12-03 06:32:31,566 | Configuration values are: {'stack_name': 's3watch-image', 'parallel': True}
2024-12-03 06:32:31,568 | Using SAM Template at /Users/simsong/s3watch-image/template.yaml
2024-12-03 06:32:31,586 | Using config file: samconfig.toml, config environment: default
2024-12-03 06:32:31,586 | Expand command line arguments to:
2024-12-03 06:32:31,586 | --template_file=/Users/simsong/s3watch-image/template.yaml --parallel --mount_with=READ --build_dir=.aws-sam/build
--cache_dir=.aws-sam/cache
2024-12-03 06:32:31,619 | 'build' command is called
2024-12-03 06:32:31,621 | No Parameters detected in the template
2024-12-03 06:32:31,633 | There is no customer defined id or cdk path defined for resource HelloWorldFunction, so we will use the resource logical id as the
resource id
2024-12-03 06:32:31,633 | There is no customer defined id or cdk path defined for resource ServerlessRestApi, so we will use the resource logical id as the
resource id
2024-12-03 06:32:31,634 | 0 stacks found in the template
2024-12-03 06:32:31,634 | No Parameters detected in the template
2024-12-03 06:32:31,642 | There is no customer defined id or cdk path defined for resource HelloWorldFunction, so we will use the resource logical id as the
resource id
2024-12-03 06:32:31,642 | There is no customer defined id or cdk path defined for resource ServerlessRestApi, so we will use the resource logical id as the
resource id
2024-12-03 06:32:31,643 | 2 resources found in the stack
2024-12-03 06:32:31,643 | Found Serverless function with name='HelloWorldFunction' and ImageUri='None'
2024-12-03 06:32:31,643 | --base-dir is not presented, adjusting uri ./hello_world relative to /Users/simsong/s3watch-image/template.yaml
2024-12-03 06:32:31,644 | --base-dir is not presented, adjusting uri . relative to /Users/simsong/s3watch-image/template.yaml
2024-12-03 06:32:31,645 | 2 resources found in the stack
2024-12-03 06:32:31,646 | Found Serverless function with name='HelloWorldFunction' and ImageUri='None'
2024-12-03 06:32:31,646 | Error occurred while trying to track an event: Event 'BuildFunctionRuntime' does not accept value 'None'.
2024-12-03 06:32:31,647 | Instantiating build definitions
2024-12-03 06:32:31,648 | Unique function build definition found, adding as new (Function Build Definition: BuildDefinition(None, /Users/simsong/s3watch-image,
Image, , 048ddf94-9def-4802-9031-236c4ab70d34, {'Dockerfile': 'Dockerfile', 'DockerContext': '/Users/simsong/s3watch-image/hello_world', 'DockerTag':
'python3.11-v1'}, {}, x86_64, []), Function: Function({'function_id': 'HelloWorldFunction', 'name': 'HelloWorldFunction', 'functionname': 'HelloWorldFunction',
'runtime': None, 'memory': None, 'timeout': 3, 'handler': None, 'imageuri': None, 'packagetype': 'Image', 'imageconfig': None, 'codeuri':
'/Users/simsong/s3watch-image', 'environment': None, 'rolearn': None, 'layers': [], 'events': {'HelloWorld': {'Type': 'Api', 'Properties': {'Path': '/hello',
'Method': 'get', 'RestApiId': 'ServerlessRestApi'}}}, 'metadata': {'Dockerfile': 'Dockerfile', 'DockerContext': '/Users/simsong/s3watch-image/hello_world',
'DockerTag': 'python3.11-v1', 'SamResourceId': 'HelloWorldFunction'}, 'inlinecode': None, 'codesign_config_arn': None, 'architectures': ['x86_64'],
'function_url_config': None, 'function_build_info': <FunctionBuildInfo.BuildableImage: ('BuildableImage', 'Regular IMAGE function which can be build with SAM
CLI')>, 'stack_path': '', 'runtime_management_config': None, 'logging_config': None}))
2024-12-03 06:32:31,651 | Async execution started
2024-12-03 06:32:31,651 | Invoking function functools.partial(<bound method ParallelBuildStrategy.build_single_function_definition of
<samcli.lib.build.build_strategy.ParallelBuildStrategy object at 0x1046c5d30>>, <samcli.lib.build.build_graph.FunctionBuildDefinition object at 0x10469ead0>)
2024-12-03 06:32:31,652 | Building codeuri: /Users/simsong/s3watch-image runtime: None architecture: x86_64 functions: HelloWorldFunction
2024-12-03 06:32:31,652 | Waiting for async results
2024-12-03 06:32:31,652 | Building to following folder /Users/simsong/s3watch-image/.aws-sam/build/HelloWorldFunction
2024-12-03 06:32:31,653 | Building image for HelloWorldFunction function
2024-12-03 06:32:31,660 | Setting DockerBuildArgs for HelloWorldFunction function
2024-12-03 06:32:33,053 | Failed building function HelloWorldFunction
2024-12-03 06:32:33,054 | Exception raised during the execution
Build Failed
2024-12-03 06:32:33,054 | Telemetry endpoint configured to be https://aws-serverless-tools-telemetry.us-west-2.amazonaws.com/metrics
2024-12-03 06:32:33,123 | Telemetry endpoint configured to be https://aws-serverless-tools-telemetry.us-west-2.amazonaws.com/metrics
2024-12-03 06:32:33,124 | Unable to find Click Context for getting session_id.
2024-12-03 06:32:33,124 | Sending Telemetry: {'metrics': [{'commandRun': {'requestId': '91b69b44-e223-413b-8197-a491fb57a6aa', 'installationId':
'98c02822-e59c-4cca-b055-9f3a4ae5aeb9', 'sessionId': 'ee4b716e-27ca-4da6-b7b5-af3022a8fe53', 'executionEnvironment': 'CLI', 'ci': False, 'pyversion': '3.13.0',
'samcliVersion': '1.131.0', 'awsProfileProvided': False, 'debugFlagProvided': True, 'region': '', 'commandName': 'sam build', 'metricSpecificAttributes':
{'projectType': 'CFN', 'gitOrigin': None, 'projectName': '20fe256ae70c5ee8593658e2d9ef6fac9b4264285f663c6d408486ef9e0c7bc8', 'initialCommit': None}, 'duration':
1468, 'exitReason': 'DockerBuildFailed', 'exitCode': 1}}]}
2024-12-03 06:32:33,126 | Sending Telemetry: {'metrics': [{'events': {'requestId': '6d243618-8e7f-40ce-8dff-674123e5a67f', 'installationId':
'98c02822-e59c-4cca-b055-9f3a4ae5aeb9', 'sessionId': 'ee4b716e-27ca-4da6-b7b5-af3022a8fe53', 'executionEnvironment': 'CLI', 'ci': False, 'pyversion': '3.13.0',
'samcliVersion': '1.131.0', 'commandName': 'sam build', 'metricSpecificAttributes': {'events': [{'event_name': 'SamConfigFileExtension', 'event_value': '.toml',
'thread_id': '50e0538b120f4050943efa3afbad8379', 'time_stamp': '2024-12-03 11:32:31.563', 'exception_name': None}, {'event_name': 'SamConfigFileExtension',
'event_value': '.toml', 'thread_id': '701826bd8bca45c5b77bede5b12c25e1', 'time_stamp': '2024-12-03 11:32:31.586', 'exception_name': None}]}}}]}
2024-12-03 06:32:33,389 | HTTPSConnectionPool(host='aws-serverless-tools-telemetry.us-west-2.amazonaws.com', port=443): Read timed out. (read timeout=0.1)
2024-12-03 06:32:33,390 | HTTPSConnectionPool(host='aws-serverless-tools-telemetry.us-west-2.amazonaws.com', port=443): Read timed out. (read timeout=0.1)
Error: failed to export image: NotFound: content digest sha256:d40a1d2caa9d01b32d5f0ce81782af06f49786c01729d03c6450ad78b06654c7: not found
sam --version
: SAM CLI, version 1.131.0# Paste the output of `sam --info` here
{
"version": "1.131.0",
"system": {
"python": "3.13.0",
"os": "macOS-15.1.1-arm64-arm-64bit-Mach-O"
},
"additional_dependencies": {
"docker_engine": "27.3.1",
"aws_cdk": "Not available",
"terraform": "Not available"
},
"available_beta_feature_env_vars": [
"SAM_CLI_BETA_FEATURES",
"SAM_CLI_BETA_BUILD_PERFORMANCE",
"SAM_CLI_BETA_TERRAFORM_SUPPORT",
"SAM_CLI_BETA_RUST_CARGO_LAMBDA"
]
}
This works without problem if I repeat the same steps from an EC2 instance running x86 AWS Linux.
I found an existing issue that makes it look like it's a Docker issue and the workaround is to downgrade the version of Docker: https://github.com/aws/aws-sam-cli/issues/7598
Although it's weird that your issue was fixed just by changing SAM CLI and not Docker