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

Bug: Hello World Example does not build for x86_64 architecture with image deployment on Apple M1 Silicon #7768

Closed
simsong opened this issue Dec 3, 2024 · 5 comments
Labels
stage/needs-triage Automatically applied to new issues and PRs, indicating they haven't been looked at.

Comments

@simsong
Copy link

simsong commented Dec 3, 2024

Description:

sam build fails with the sam Hello World Example when building for Image (Docker) deployment for x86_64 architecture on Apple M1 Silicon.

This is on MacOS Sequoia 15.1.1 with a working docker installation.

Regular sam init selecting a ZIP file deployment creates a working lambda.

Steps to reproduce:

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

Observed result:

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

Expected result:

  • It should build a SAM package that I can then deploy.
  • This works if I specify a Zip deployment, rather than image.

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

  1. OS: MacOS Sequoia 15.1.1
  2. sam --version: SAM CLI, version 1.131.0
  3. AWS region: us-east-1
# 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.
@simsong simsong added the stage/needs-triage Automatically applied to new issues and PRs, indicating they haven't been looked at. label Dec 3, 2024
@jonife
Copy link
Contributor

jonife commented Dec 3, 2024

Hello @simsong I tried reproducing the error with the steps listed above and i couldn't reproduce it. i was wondering if you could provide the template .

Just out of curiosity can you try deleting all images and container and redownloading the image?

s3watch-image % sam build
Building codeuri: /Users/jonife/Documents/dev/sam/s3watch-image runtime: None architecture: x86_64 functions: HelloWorldFunction                                                            
Building image for HelloWorldFunction function                                                                                                                                              
Setting DockerBuildArgs for HelloWorldFunction function                                                                                                                                     
Step 1/5 : FROM public.ecr.aws/lambda/python:3.11
3.11: Pulling from lambda/python 
551ede2dc115: Pull complete 
697748a36594: Pull complete 
3ee554885aa3: Pull complete 
35e8cd243a50: Pull complete 
4dfc764ff7c1: Pull complete 
d7dceb961642: Pull complete 
Status: Downloaded newer image for public.ecr.aws/lambda/python:3.11 ---> f26857902e2e
Step 2/5 : COPY requirements.txt ./
 ---> 6ea50d71eb3c
Step 3/5 : RUN python3.11 -m pip install -r requirements.txt -t .
 ---> [Warning] The requested image's platform (linux/amd64) does not match the detected host platform (linux/arm64/v8) and no specific platform was requested
 ---> Running in fbbc83eec38c
Collecting requests (from -r requirements.txt (line 1))
  Downloading requests-2.32.3-py3-none-any.whl.metadata (4.6 kB)
Collecting charset-normalizer<4,>=2 (from requests->-r requirements.txt (line 1))
  Downloading charset_normalizer-3.4.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.metadata (34 kB)
Collecting idna<4,>=2.5 (from requests->-r requirements.txt (line 1))
  Downloading idna-3.10-py3-none-any.whl.metadata (10 kB)
Collecting urllib3<3,>=1.21.1 (from requests->-r requirements.txt (line 1))
  Downloading urllib3-2.2.3-py3-none-any.whl.metadata (6.5 kB)
Collecting certifi>=2017.4.17 (from requests->-r requirements.txt (line 1))
  Downloading certifi-2024.8.30-py3-none-any.whl.metadata (2.2 kB)
Downloading requests-2.32.3-py3-none-any.whl (64 kB)
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 64.9/64.9 kB 21.9 MB/s eta 0:00:00
Downloading certifi-2024.8.30-py3-none-any.whl (167 kB)
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 167.3/167.3 kB 6.7 MB/s eta 0:00:00
Downloading charset_normalizer-3.4.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (142 kB)
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 142.6/142.6 kB 59.8 MB/s eta 0:00:00
Downloading idna-3.10-py3-none-any.whl (70 kB)
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 70.4/70.4 kB 23.7 MB/s eta 0:00:00
Downloading urllib3-2.2.3-py3-none-any.whl (126 kB)
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 126.3/126.3 kB 13.4 MB/s eta 0:00:00
Installing collected packages: urllib3, idna, charset-normalizer, certifi, requests
Successfully installed certifi-2024.8.30 charset-normalizer-3.4.0 idna-3.10 requests-2.32.3 urllib3-2.2.3
WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv

[notice] A new release of pip is available: 24.0 -> 24.3.1
[notice] To update, run: pip install --upgrade pip
 ---> Removed intermediate container fbbc83eec38c
 ---> a21da3b303d9
Step 4/5 : COPY app.py ./
 ---> 319c39acc5a5
Step 5/5 : CMD ["app.lambda_handler"]
 ---> [Warning] The requested image's platform (linux/amd64) does not match the detected host platform (linux/arm64/v8) and no specific platform was requested
 ---> Running in 67ff10e18670
 ---> Removed intermediate container 67ff10e18670
 ---> 9ff4dc1cec2c
Successfully built 9ff4dc1cec2c
Successfully tagged helloworldfunction:python3.11-v1


Build Succeeded

Built Artifacts  : .aws-sam/build
Built Template   : .aws-sam/build/template.yaml

Commands you can use next
=========================
[*] Validate SAM template: sam validate
[*] Invoke Function: sam local invoke
[*] Test Function in the Cloud: sam sync --stack-name {{stack-name}} --watch
[*] Deploy: sam deploy --guided

@simsong
Copy link
Author

simsong commented Dec 3, 2024

Thanks for getting to this! I did a full reinstall of docker. If you tell me which directories to wipe, I can do that.

I will upload the template.yml file shortly.

@simsong
Copy link
Author

simsong commented Dec 4, 2024

Here is the template.yml file. I will try to create another user on my mac and see if there is the same problem.

AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: >
  python3.11

  Sample SAM Template for lambda-docker

# More info about Globals: https://github.com/awslabs/serverless-application-model/blob/master/docs/globals.rst
Globals:
  Function:
    Timeout: 3

Resources:
  HelloWorldFunction:
    Type: AWS::Serverless::Function # More info about Function Resource: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlessfunction
    Properties:
      PackageType: Image
      Architectures:
        - x86_64
      Events:
        HelloWorld:
          Type: Api # More info about API Event Source: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#api
          Properties:
            Path: /hello
            Method: get
    Metadata:
      Dockerfile: Dockerfile
      DockerContext: ./hello_world
      DockerTag: python3.11-v1

Outputs:
  # ServerlessRestApi is an implicit API created out of Events key under Serverless::Function
  # Find out more about other implicit resources you can reference within SAM
  # https://github.com/awslabs/serverless-application-model/blob/master/docs/internals/generated_resources.rst#api
  HelloWorldApi:
    Description: "API Gateway endpoint URL for Prod stage for Hello World function"
    Value: !Sub "https://${ServerlessRestApi}.execute-api.${AWS::Region}.amazonaws.com/Prod/hello/"
  HelloWorldFunction:
    Description: "Hello World Lambda Function ARN"
    Value: !GetAtt HelloWorldFunction.Arn
  HelloWorldFunctionIamRole:
    Description: "Implicit IAM Role created for Hello World function"
    Value: !GetAtt HelloWorldFunctionRole.Arn

@simsong
Copy link
Author

simsong commented Dec 5, 2024

More data points:

  • AWS Linux running in docker on my MacBook's simsong account had the same problem.
  • I created a new account on my MacBook called slg and did a clean install of SAM (but not Python or Docker). Started Docker desktop and did sam init and sam build and sam deploy. It worked.

Conclusion:

  • Something is wacko about my simsong account that caused this problem. It would be worth tracking down because we could add error reporting to sam build to say what is going wrong. However, I'm going to close this ticket, delete by simsong account and then recreate it. Hopefully that will do the trick.

@simsong simsong closed this as completed Dec 5, 2024
Copy link
Contributor

github-actions bot commented Dec 5, 2024

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stage/needs-triage Automatically applied to new issues and PRs, indicating they haven't been looked at.
Projects
None yet
Development

No branches or pull requests

2 participants