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: sam local invoke throws Error: Error building docker image when function uses x86_64 architectures #4771

Closed
PaulTreanor opened this issue Feb 27, 2023 · 4 comments · Fixed by Homebrew/homebrew-core#124616
Labels
stage/bug-repro The issue/bug needs to be reproduced

Comments

@PaulTreanor
Copy link

Description:

Invoking x86_64 lambda functions locally using sam local invoke causes the docker image to fail to build, including using the HelloWorld template.

This is the same problem as this closed issue #3169. Non of the solutions in that thread fixed the issue.

Steps to reproduce:

  1. Launch Docker desktop
  2. sam init
    1. Select option 1 - AWS Quick Start Templates
    2. Select the first template - Hello World Example
    3. Use the most popular runtime and package type (Python and zip)
    4. Don't enable X-Ray tracing
    5. Don't enable monitoring with CloudWatch Application Insights
  3. cd into newly made directory
  4. sam build --use-container
  5. sam local invoke HelloWorldFunction --debug

Observed result:

❯ sam local invoke HelloWorldFunction --debug
2023-02-27 14:52:31,489 | Config file location: /Users/paultreanor/code/learning/SAM/arm64-bug/samconfig.toml
2023-02-27 14:52:31,489 | Loading configuration values from [default.['local', 'invoke'].parameters] (env.command_name.section) in config file at '/Users/paultreanor/code/learning/SAM/arm64-bug/samconfig.toml'...
2023-02-27 14:52:31,491 | Configuration values successfully loaded.
2023-02-27 14:52:31,491 | Configuration values are: {'stack_name': 'arm64-bug'}
2023-02-27 14:52:31,493 | Using SAM Template at /Users/paultreanor/code/learning/SAM/arm64-bug/.aws-sam/build/template.yaml
2023-02-27 14:52:31,507 | Using config file: samconfig.toml, config environment: default
2023-02-27 14:52:31,507 | Expand command line arguments to:
2023-02-27 14:52:31,507 | --template_file=/Users/paultreanor/code/learning/SAM/arm64-bug/.aws-sam/build/template.yaml --function_logical_id=HelloWorldFunction --no_event --layer_cache_basedir=/Users/paultreanor/.aws-sam/layers-pkg --container_host=localhost --container_host_interface=127.0.0.1
2023-02-27 14:52:31,507 | local invoke command is called
2023-02-27 14:52:31,508 | No Parameters detected in the template
2023-02-27 14:52:31,518 | Sam customer defined id is more priority than other IDs. Customer defined id for resource HelloWorldFunction is HelloWorldFunction
2023-02-27 14:52:31,518 | 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](<❯ sam local invoke HelloWorldFunction --debug
2023-02-27 14:57:09,755 | Config file location: /Users/paultreanor/code/learning/SAM/arm64-bug/samconfig.toml
2023-02-27 14:57:09,756 | Loading configuration values from [default.['local', 'invoke'].parameters] (env.command_name.section) in config file at '/Users/paultreanor/code/learning/SAM/arm64-bug/samconfig.toml'...
2023-02-27 14:57:09,758 | Configuration values successfully loaded.
2023-02-27 14:57:09,758 | Configuration values are: {'stack_name': 'arm64-bug'}
2023-02-27 14:57:09,759 | Using SAM Template at /Users/paultreanor/code/learning/SAM/arm64-bug/.aws-sam/build/template.yaml
2023-02-27 14:57:09,771 | Using config file: samconfig.toml, config environment: default
2023-02-27 14:57:09,771 | Expand command line arguments to:
2023-02-27 14:57:09,771 | --template_file=/Users/paultreanor/code/learning/SAM/arm64-bug/.aws-sam/build/template.yaml --function_logical_id=HelloWorldFunction --no_event --layer_cache_basedir=/Users/paultreanor/.aws-sam/layers-pkg --container_host=localhost --container_host_interface=127.0.0.1
2023-02-27 14:57:09,771 | local invoke command is called
2023-02-27 14:57:09,773 | No Parameters detected in the template
2023-02-27 14:57:09,780 | Sam customer defined id is more priority than other IDs. Customer defined id for resource HelloWorldFunction is HelloWorldFunction
2023-02-27 14:57:09,780 | 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
2023-02-27 14:57:09,781 | 0 stacks found in the template
2023-02-27 14:57:09,781 | No Parameters detected in the template
2023-02-27 14:57:09,786 | Sam customer defined id is more priority than other IDs. Customer defined id for resource HelloWorldFunction is HelloWorldFunction
2023-02-27 14:57:09,786 | 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
2023-02-27 14:57:09,786 | 2 resources found in the stack
2023-02-27 14:57:09,786 | Found Serverless function with name='HelloWorldFunction' and CodeUri='HelloWorldFunction'
2023-02-27 14:57:09,786 | --base-dir is not presented, adjusting uri HelloWorldFunction relative to /Users/paultreanor/code/learning/SAM/arm64-bug/.aws-sam/build/template.yaml
2023-02-27 14:57:09,798 | Found one Lambda function with name 'HelloWorldFunction'
2023-02-27 14:57:09,798 | Invoking app.lambda_handler (python3.9)
2023-02-27 14:57:09,798 | No environment variables found for function 'HelloWorldFunction'
2023-02-27 14:57:09,798 | Loading AWS credentials from session with profile 'None'
2023-02-27 14:57:09,803 | Resolving code path. Cwd=/Users/paultreanor/code/learning/SAM/arm64-bug/.aws-sam/build, CodeUri=/Users/paultreanor/code/learning/SAM/arm64-bug/.aws-sam/build/HelloWorldFunction
2023-02-27 14:57:09,803 | Resolved absolute path to code is /Users/paultreanor/code/learning/SAM/arm64-bug/.aws-sam/build/HelloWorldFunction
2023-02-27 14:57:09,803 | Code /Users/paultreanor/code/learning/SAM/arm64-bug/.aws-sam/build/HelloWorldFunction is not a zip/jar file
2023-02-27 14:57:09,808 | Local image was not found.
2023-02-27 14:57:09,808 | Removing rapid images for repo public.ecr.aws/sam/emulation-python3.9
Building image....................
2023-02-27 14:57:11,510 | Failed to build Docker Image
NoneType: None
2023-02-27 14:57:11,511 | Cleaning all decompressed code dirs
2023-02-27 14:57:11,511 | Telemetry endpoint configured to be https://aws-serverless-tools-telemetry.us-west-2.amazonaws.com/metrics
2023-02-27 14:57:11,542 | Sending Telemetry: {'metrics': [{'commandRun': {'requestId': '5979d9ee-0ea4-4454-abf0-6f4105504f08', 'installationId': 'c6ab7b63-e751-49b3-b3f8-7c26f0ce3e15', 'sessionId': 'ce4b324c-1456-4871-bc17-7c5cae1450d8', 'executionEnvironment': 'CLI', 'ci': False, 'pyversion': '3.11.2', 'samcliVersion': '1.74.0', 'awsProfileProvided': False, 'debugFlagProvided': True, 'region': '', 'commandName': 'sam local invoke', 'metricSpecificAttributes': {'projectType': 'CFN', 'gitOrigin': None, 'projectName': 'bf807dc0e8a5c1b7a777c0d7d33689501f8e69af81ae22b5a16d4d1302bef99f', 'initialCommit': None}, 'duration': 1740, 'exitReason': 'ImageBuildException', 'exitCode': 1}}]}
2023-02-27 14:57:12,185 | HTTPSConnectionPool(host='aws-serverless-tools-telemetry.us-west-2.amazonaws.com', port=443): Read timed out. (read timeout=0.1)
Error: Error building docker image: The command '/bin/sh -c mv /var/rapid/aws-lambda-rie-x86_64 /var/rapid/aws-lambda-rie && chmod +x /var/rapid/aws-lambda-rie' returned a non-zero code: 1>)

Expected result:

Mounting /Users/paultreanor/code/learning/SAM/arm64-bug/.aws-sam/build/HelloWorldFunction as /var/task:ro,delegated inside runtime container
START RequestId: a35c8d00-bd02-4896-a1c1-a7087df3953a Version: $LATEST
END RequestId: a35c8d00-bd02-4896-a1c1-a7087df3953a
REPORT RequestId: a35c8d00-bd02-4896-a1c1-a7087df3953a	Init Duration: 0.14 ms	Duration: 82.07 ms	Billed Duration: 83 ms	Memory Size: 128 MB	Max Memory Used: 128 MB
{"statusCode": 200, "body": "{\"message\": \"hello world\"}"}%

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

  1. OS: MacOS Ventura 13.2
  2. sam --version: 1.74.0
  3. AWS region: eu-west-1
  4. Machine: Apple M1 ARM chip
  5. Docker version: 20.10.22

sam --info output:

{
  "version": "1.74.0",
  "system": {
    "python": "3.11.2",
    "os": "macOS-13.2-arm64-arm-64bit"
  },
  "additional_dependencies": {
    "docker_engine": "20.10.22",
    "aws_cdk": "Not available",
    "terraform": "Not available"
  }
}
@PaulTreanor PaulTreanor added the stage/needs-triage Automatically applied to new issues and PRs, indicating they haven't been looked at. label Feb 27, 2023
@sriram-mv
Copy link
Contributor

How have you installed sam? is it through homebrew or the pkg installer?

I tried to reproduce the same on my M1 mac with the the configuration you have listed under sam --info and I'm not able to with installing through homebrew or the pkg installer.

@sriram-mv sriram-mv added stage/bug-repro The issue/bug needs to be reproduced and removed stage/needs-triage Automatically applied to new issues and PRs, indicating they haven't been looked at. labels Feb 27, 2023
@PaulTreanor
Copy link
Author

How have you installed sam? is it through homebrew or the pkg installer?

I installed sam through homebrew. Uninstalling sam through homebrew (brew uninstall aws-sam-cli) and reinstalling sam using the pkg installer has fixed the issue.

Thanks for your help.

carlocab added a commit to carlocab/homebrew-core that referenced this issue Mar 3, 2023
These binaries are for use inside containers which might be running a
different architecture.

Also, add this to the autobump list since upstream has issues when there
are delayed updates to users.

Fixes Homebrew/discussions#4290
Fixes aws/aws-sam-cli#4771
Fixes aws/aws-sam-cli#4684
Fixes aws/aws-sam-cli#4607
Closes aws/aws-sam-cli#4614

Closes Homebrew#124616.

Signed-off-by: Carlo Cabrera <30379873+carlocab@users.noreply.github.com>
carlocab added a commit to Homebrew/homebrew-core that referenced this issue Mar 4, 2023
These binaries are for use inside containers which might be running a
different architecture.

Also, add this to the autobump list since upstream has issues when there
are delayed updates to users.

Fixes Homebrew/discussions#4290
Fixes aws/aws-sam-cli#4771
Fixes aws/aws-sam-cli#4684
Fixes aws/aws-sam-cli#4607
Closes aws/aws-sam-cli#4614

Closes #124616.

Signed-off-by: Carlo Cabrera <30379873+carlocab@users.noreply.github.com>
@moelasmar
Copy link
Contributor

Thanks @PaulTreanor for raising this issue. I am closing this issue as it seems you was able to fix the problem by reinstalling SAM CLI using pkg installer. Please do not hesitate to open a new issue if you are still facing the same issue or other issues.

@github-actions
Copy link
Contributor

⚠️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/bug-repro The issue/bug needs to be reproduced
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants