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 local invoke (Using HelloWorld template throws "Error: Error building docker image" #3169

Closed
kingram6865 opened this issue Aug 12, 2021 · 24 comments
Labels
area/local/invoke sam local invoke command blocked/close-if-inactive Blocked for >14 days with no response, will be closed if still inactive after 7 days stage/bug-repro The issue/bug needs to be reproduced

Comments

@kingram6865
Copy link

Description:

When invoking sam build docker fails to build the image

Steps to reproduce:

  1. pip install aws-sam-cli
  2. mkdir test; cd test
  3. sam init; Choose HelloWorld
  4. sam build
  5. sam local invoke

Observed result:

$ sam local invoke
Invoking app.lambdaHandler (nodejs12.x)
Image was not found.
Building image...................
Failed to build Docker Image
NoneType: None
Error: Error building docker image: The command '/bin/sh -c chmod +x /var/rapid/aws-lambda-rie' returned a non-zero code: 1

Docker says:

$ docker ps -a
CONTAINER ID   IMAGE          COMMAND                  CREATED              STATUS                          PORTS     NAMES
59e236baf8e8   7f5c2fbde043   "/bin/sh -c 'chmod +…"   About a minute ago   Exited (1) About a minute ago             distracted_bhabha
dcdf8949474a   7f5c2fbde043   "/bin/sh -c 'chmod +…"   4 days ago           Exited (1) 4 days ago                     adoring_einstein
50a9c04dea71   7f5c2fbde043   "/bin/sh -c 'chmod +…"   4 days ago           Exited (1) 4 days ago                     musing_raman
559bb77ddac1   7f5c2fbde043   "/bin/sh -c 'chmod +…"   4 days ago           Exited (1) 4 days ago                     busy_hawking

Expected result:

Mounting /home/kingram/WORK/tmp/samtest/.aws-sam/build/HelloWorldFunction as /var/task:ro,delegated inside runtime container
START RequestId: 67bb22f1-747e-4655-92ad-c681f5482447 Version: $LATEST
END RequestId: 67bb22f1-747e-4655-92ad-c681f5482447
REPORT RequestId: 67bb22f1-747e-4655-92ad-c681f5482447 Init Duration: 0.08 ms Duration: 58.41 ms Billed Duration: 100 ms Memory Size: 128 MB Max Memory Used: 128 MB
No Content-Type given. Defaulting to 'application/json'.
2021-08-06 22:01:33 192.168.1.161 - - [06/Aug/2021 22:01:33] "GET /hello HTTP/1.1" 200 -
2021-08-06 22:01:34 192.168.1.161 - - [06/Aug/2021 22:01:34] "GET /favicon.ico HTTP/1.1" 403 -

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

  1. OS: Ubuntu 20.04
  2. sam --version: 1.27.2
  3. AWS region: us-west

Add --debug flag to command you are running

$ sam local invoke --debug
2021-08-12 22:47:16,261 | Telemetry endpoint configured to be https://aws-serverless-tools-telemetry.us-west-2.amazonaws.com/metrics
2021-08-12 22:47:16,263 | Using config file: samconfig.toml, config environment: default
2021-08-12 22:47:16,264 | Expand command line arguments to:
2021-08-12 22:47:16,264 | --template_file=/home/kingram/WORK/test/sam-app/.aws-sam/build/template.yaml --no_event --layer_cache_basedir=/home/kingram/.aws-sam/layers-pkg --container_host=localhost --container_host_interface=127.0.0.1 
2021-08-12 22:47:16,264 | local invoke command is called
2021-08-12 22:47:16,282 | No Parameters detected in the template
2021-08-12 22:47:16,375 | 2 stacks found in the template
2021-08-12 22:47:16,375 | No Parameters detected in the template
2021-08-12 22:47:16,464 | 2 resources found in the stack 
2021-08-12 22:47:16,464 | No Parameters detected in the template
2021-08-12 22:47:16,549 | Found Serverless function with name='HelloWorldFunction' and CodeUri='HelloWorldFunction'
2021-08-12 22:47:16,550 | --base-dir is not presented, adjusting uri HelloWorldFunction relative to /home/kingram/WORK/test/sam-app/.aws-sam/build/template.yaml
2021-08-12 22:47:16,569 | Found one Lambda function with name 'HelloWorldFunction'
2021-08-12 22:47:16,569 | Invoking app.lambdaHandler (nodejs12.x)
2021-08-12 22:47:16,569 | No environment variables found for function 'HelloWorldFunction'
2021-08-12 22:47:16,569 | Environment variables overrides data is standard format
2021-08-12 22:47:16,569 | Loading AWS credentials from session with profile 'None'
2021-08-12 22:47:16,611 | Resolving code path. Cwd=/home/kingram/WORK/test/sam-app/.aws-sam/build, CodeUri=/home/kingram/WORK/test/sam-app/.aws-sam/build/HelloWorldFunction
2021-08-12 22:47:16,611 | Resolved absolute path to code is /home/kingram/WORK/test/sam-app/.aws-sam/build/HelloWorldFunction
2021-08-12 22:47:16,611 | Code /home/kingram/WORK/test/sam-app/.aws-sam/build/HelloWorldFunction is not a zip/jar file
2021-08-12 22:47:16,618 | Image was not found.
Building image...................
2021-08-12 22:47:21,356 | Failed to build Docker Image
NoneType: None
2021-08-12 22:47:21,362 | Cleaning all decompressed code dirs
2021-08-12 22:47:21,364 | Sending Telemetry: {'metrics': [{'commandRun': {'requestId': '897aba07-bb21-48ce-853d-060c8473e075', 'installationId': '6e07d42b-6906-4f1c-b030-85891cf49146', 'sessionId': 'f8e81d61-11e9-4e26-91b8-5afda75aaeb6', 'executionEnvironment': 'CLI', 'ci': False, 'pyversion': '3.7.9', 'samcliVersion': '1.27.2', 'awsProfileProvided': False, 'debugFlagProvided': True, 'region': '', 'commandName': 'sam local invoke', 'duration': 5099, 'exitReason': 'ImageBuildException', 'exitCode': 1}}]}
2021-08-12 22:47:21,733 | 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 chmod +x /var/rapid/aws-lambda-rie' returned a non-zero code: 1

Other command:

$ sam local start-api --host 192.168.1.83 --debug
2021-08-12 22:50:33,828 | Telemetry endpoint configured to be https://aws-serverless-tools-telemetry.us-west-2.amazonaws.com/metrics
2021-08-12 22:50:33,830 | Using config file: samconfig.toml, config environment: default
2021-08-12 22:50:33,830 | Expand command line arguments to:
2021-08-12 22:50:33,831 | --template_file=/home/kingram/WORK/test/sam-app/.aws-sam/build/template.yaml --host=192.168.1.83 --port=3000 --static_dir=public --layer_cache_basedir=/home/kingram/.aws-sam/layers-pkg --container_host=localhost --container_host_interface=127.0.0.1 
2021-08-12 22:50:34,095 | local start-api command is called
2021-08-12 22:50:34,112 | No Parameters detected in the template
2021-08-12 22:50:34,204 | 2 stacks found in the template
2021-08-12 22:50:34,205 | No Parameters detected in the template
2021-08-12 22:50:34,289 | 2 resources found in the stack 
2021-08-12 22:50:34,289 | No Parameters detected in the template
2021-08-12 22:50:34,374 | Found Serverless function with name='HelloWorldFunction' and CodeUri='HelloWorldFunction'
2021-08-12 22:50:34,374 | --base-dir is not presented, adjusting uri HelloWorldFunction relative to /home/kingram/WORK/test/sam-app/.aws-sam/build/template.yaml
2021-08-12 22:50:34,384 | No Parameters detected in the template
2021-08-12 22:50:34,472 | No Parameters detected in the template
2021-08-12 22:50:34,557 | Found '1' API Events in Serverless function with name 'HelloWorldFunction'
2021-08-12 22:50:34,557 | Detected Inline Swagger definition
2021-08-12 22:50:34,557 | Lambda function integration not found in Swagger document at path='/hello' method='get'
2021-08-12 22:50:34,558 | Found '0' APIs in resource 'ServerlessRestApi'
2021-08-12 22:50:34,558 | Removed duplicates from '0' Explicit APIs and '1' Implicit APIs to produce '1' APIs
2021-08-12 22:50:34,558 | 1 APIs found in the template
2021-08-12 22:50:34,570 | Mounting HelloWorldFunction at http://192.168.1.83:3000/hello [GET]
2021-08-12 22:50:34,570 | You can now browse to the above endpoints to invoke your functions. You do not need to restart/reload SAM CLI while working on your functions, changes will be reflected instantly/automatically. You only need to restart SAM CLI if you update your AWS SAM template
2021-08-12 22:50:34,570 | Localhost server is starting up. Multi-threading = True
2021-08-12 22:50:34  * Running on http://192.168.1.83:3000/ (Press CTRL+C to quit)
2021-08-12 22:50:46,958 | Constructed String representation of Event to invoke Lambda. Event: {"body": null, "headers": {"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9", "Accept-Encoding": "gzip, deflate", "Accept-Language": "en-US,en;q=0.9", "Cache-Control": "max-age=0", "Connection": "keep-alive", "Dnt": "1", "Host": "192.168.1.83:3000", "Upgrade-Insecure-Requests": "1", "User-Agent": "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36", "X-Forwarded-Port": "3000", "X-Forwarded-Proto": "http"}, "httpMethod": "GET", "isBase64Encoded": false, "multiValueHeaders": {"Accept": ["text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9"], "Accept-Encoding": ["gzip, deflate"], "Accept-Language": ["en-US,en;q=0.9"], "Cache-Control": ["max-age=0"], "Connection": ["keep-alive"], "Dnt": ["1"], "Host": ["192.168.1.83:3000"], "Upgrade-Insecure-Requests": ["1"], "User-Agent": ["Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36"], "X-Forwarded-Port": ["3000"], "X-Forwarded-Proto": ["http"]}, "multiValueQueryStringParameters": null, "path": "/hello", "pathParameters": null, "queryStringParameters": null, "requestContext": {"accountId": "123456789012", "apiId": "1234567890", "domainName": "192.168.1.83:3000", "extendedRequestId": null, "httpMethod": "GET", "identity": {"accountId": null, "apiKey": null, "caller": null, "cognitoAuthenticationProvider": null, "cognitoAuthenticationType": null, "cognitoIdentityPoolId": null, "sourceIp": "192.168.1.161", "user": null, "userAgent": "Custom User Agent String", "userArn": null}, "path": "/hello", "protocol": "HTTP/1.1", "requestId": "650c92be-2f04-4c10-964e-95f99bfd7deb", "requestTime": "12/Aug/2021:22:50:34 +0000", "requestTimeEpoch": 1628808634, "resourceId": "123456", "resourcePath": "/hello", "stage": "Prod"}, "resource": "/hello", "stageVariables": null, "version": "1.0"}
2021-08-12 22:50:46,960 | Found one Lambda function with name 'HelloWorldFunction'
2021-08-12 22:50:46,961 | Invoking app.lambdaHandler (nodejs12.x)
2021-08-12 22:50:46,961 | No environment variables found for function 'HelloWorldFunction'
2021-08-12 22:50:46,961 | Environment variables overrides data is standard format
2021-08-12 22:50:46,962 | Loading AWS credentials from session with profile 'None'
2021-08-12 22:50:47,006 | Resolving code path. Cwd=/home/kingram/WORK/test/sam-app/.aws-sam/build, CodeUri=/home/kingram/WORK/test/sam-app/.aws-sam/build/HelloWorldFunction
2021-08-12 22:50:47,006 | Resolved absolute path to code is /home/kingram/WORK/test/sam-app/.aws-sam/build/HelloWorldFunction
2021-08-12 22:50:47,006 | Code /home/kingram/WORK/test/sam-app/.aws-sam/build/HelloWorldFunction is not a zip/jar file
2021-08-12 22:50:47,014 | Image was not found.
Building image...................
2021-08-12 22:50:51,571 | Failed to build Docker Image
NoneType: None
2021-08-12 22:50:51,576 | Cleaning all decompressed code dirs
2021-08-12 22:50:51,577 | Exception on /hello [GET]
Traceback (most recent call last):
  File "/PUBLIC/DOWNLOADS/.venv/lib/python3.7/site-packages/flask/app.py", line 2447, in wsgi_app
    response = self.full_dispatch_request()
  File "/PUBLIC/DOWNLOADS/.venv/lib/python3.7/site-packages/flask/app.py", line 1952, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/PUBLIC/DOWNLOADS/.venv/lib/python3.7/site-packages/flask/app.py", line 1821, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/PUBLIC/DOWNLOADS/.venv/lib/python3.7/site-packages/flask/_compat.py", line 39, in reraise
    raise value
  File "/PUBLIC/DOWNLOADS/.venv/lib/python3.7/site-packages/flask/app.py", line 1950, in full_dispatch_request
    rv = self.dispatch_request()
  File "/PUBLIC/DOWNLOADS/.venv/lib/python3.7/site-packages/flask/app.py", line 1936, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/PUBLIC/DOWNLOADS/aws-sam-cli/samcli/local/apigw/local_apigw_service.py", line 317, in _request_handler
    self.lambda_runner.invoke(route.function_name, event, stdout=stdout_stream_writer, stderr=self.stderr)
  File "/PUBLIC/DOWNLOADS/aws-sam-cli/samcli/commands/local/lib/local_lambda.py", line 137, in invoke
    container_host_interface=self.container_host_interface,
  File "/PUBLIC/DOWNLOADS/aws-sam-cli/samcli/lib/telemetry/metric.py", line 217, in wrapped_func
    return_value = func(*args, **kwargs)
  File "/PUBLIC/DOWNLOADS/aws-sam-cli/samcli/local/lambdafn/runtime.py", line 176, in invoke
    container = self.create(function_config, debug_context, container_host, container_host_interface)
  File "/PUBLIC/DOWNLOADS/aws-sam-cli/samcli/local/lambdafn/runtime.py", line 86, in create
    container_host_interface=container_host_interface,
  File "/PUBLIC/DOWNLOADS/aws-sam-cli/samcli/local/docker/lambda_container.py", line 87, in __init__
    image = LambdaContainer._get_image(lambda_image, runtime, packagetype, imageuri, layers)
  File "/PUBLIC/DOWNLOADS/aws-sam-cli/samcli/local/docker/lambda_container.py", line 213, in _get_image
    return lambda_image.build(runtime, packagetype, image, layers)
  File "/PUBLIC/DOWNLOADS/aws-sam-cli/samcli/local/docker/lambda_image.py", line 144, in build
    self._build_image(image if image else image_name, image_tag, downloaded_layers, stream=stream_writer)
  File "/PUBLIC/DOWNLOADS/aws-sam-cli/samcli/local/docker/lambda_image.py", line 245, in _build_image
    raise ImageBuildException("Error building docker image: {}".format(log["error"]))
samcli.commands.local.cli_common.user_exceptions.ImageBuildException: Error building docker image: The command '/bin/sh -c chmod +x /var/rapid/aws-lambda-rie' returned a non-zero code: 1
2021-08-12 22:50:51 192.168.1.161 - - [12/Aug/2021 22:50:51] "GET /hello HTTP/1.1" 502 -
2021-08-12 22:50:51 192.168.1.161 - - [12/Aug/2021 22:50:51] "GET /favicon.ico HTTP/1.1" 403 -

@xazhao
Copy link
Contributor

xazhao commented Aug 12, 2021

@kingram6865 Thanks for posting the issue. I was trying to reproduce the issue and sam local invoke works fine on my machine (I'm running on Mac OS).

Briefly looking into the code, this error happens when SAM CLI call Docker client to build image. I would suggest check if your Docker is running properly.

Were you able to make it running correctly? If yes, what's is the difference between working setup and not working setup? Found a similar issue here: #2622

@xazhao xazhao added area/local/invoke sam local invoke command stage/bug-repro The issue/bug needs to be reproduced labels Aug 12, 2021
@kingram6865
Copy link
Author

kingram6865 commented Aug 13, 2021

It looks like sam cli is looking for this /var/rapid/aws-lambda-rie, but I have no installed this.
It is Lambda Runtime interface emulator. https://github.com/aws/aws-lambda-runtime-interface-emulator
I don't know why it is breaking here. Does it install with sam cli?

This tool works on my x86 Ubuntu computer but that is not the machine where I want to run the edge.

If you have any suggestions I would love it.

@xazhao
Copy link
Contributor

xazhao commented Aug 16, 2021

Yes aws-lambda-rie will be installed in the Docker image when you run sam local.

Could you provide me more details about your environment details? Is it a x86 Ubuntu? What's your docker version?

@kingram6865
Copy link
Author

Machine details:
Hardware: Raspberry Pi 4
OS: Ubunto Server 20.04
Docker version 20.10.7, build 20.10.7-0ubuntu1~20.04.1

@mgrandis
Copy link
Contributor

mgrandis commented Aug 26, 2021

@kingram6865
Looks like you are attempting to build/run an x86 image on an ARM machine.
Have you configured qemu?
https://github.com/multiarch/qemu-user-static#getting-started

This command should be the one to use:
docker run --rm --privileged multiarch/qemu-user-static --reset -p yes

Let me know how it goes

@kingram6865
Copy link
Author

@kingram6865
Looks like you are attempting to build/run an x86 image on an ARM machine.
Have you configured qemu?
https://github.com/multiarch/qemu-user-static#getting-started

This command should be the one to use:
docker run --rm --privileged multiarch/qemu-user-static --reset -p yes

Let me know how it goes

It didn't work. I'm no longer at that position so it's moot now. I may work on it for a private project in time.

@awood45 awood45 added the blocked/close-if-inactive Blocked for >14 days with no response, will be closed if still inactive after 7 days label Sep 3, 2021
@awood45
Copy link
Member

awood45 commented Sep 3, 2021

Are you looking for us to continue to help debugging on this, or should we close?

@kingram6865
Copy link
Author

Are you looking for us to continue to help debugging on this, or should we close?

Thanks for asking. I think it's appropriate to close this issue now.

@aahung aahung closed this as completed Sep 13, 2021
@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.

@NithuPMTR
Copy link

NithuPMTR commented Sep 30, 2021

This issue seems to be recurring now. We are encountering below error while locally invoking a lambda in AWS code build machine

Image was not found.

842 | Building image............................................................................................................................
843 | Failed to build Docker Image
844 | NoneType: None
845 | Exception on /2015-03-31/functions/FunctionName/invocations [POST]
846 | Traceback (most recent call last):
847 | File "/root/.pyenv/versions/3.8.10/lib/python3.8/site-packages/flask/app.py", line 2447, in wsgi_app
848 | response = self.full_dispatch_request()
849 | File "/root/.pyenv/versions/3.8.10/lib/python3.8/site-packages/flask/app.py", line 1952, in full_dispatch_request
850 | rv = self.handle_user_exception(e)
851 | File "/root/.pyenv/versions/3.8.10/lib/python3.8/site-packages/flask/app.py", line 1821, in handle_user_exception
852 | reraise(exc_type, exc_value, tb)
853 | File "/root/.pyenv/versions/3.8.10/lib/python3.8/site-packages/flask/_compat.py", line 39, in reraise
854 | raise value
855 | File "/root/.pyenv/versions/3.8.10/lib/python3.8/site-packages/flask/app.py", line 1950, in full_dispatch_request
856 | rv = self.dispatch_request()
857 | File "/root/.pyenv/versions/3.8.10/lib/python3.8/site-packages/flask/app.py", line 1936, in dispatch_request
858 | return self.view_functionsrule.endpoint
859 | File "/root/.pyenv/versions/3.8.10/lib/python3.8/site-packages/samcli/local/lambda_service/local_lambda_invoke_service.py", line 151, in _invoke_request_handler
860 | self.lambda_runner.invoke(function_name, request_data, stdout=stdout_stream_writer, stderr=self.stderr)
861 | File "/root/.pyenv/versions/3.8.10/lib/python3.8/site-packages/samcli/commands/local/lib/local_lambda.py", line 130, in invoke
862 | self.local_runtime.invoke(
863 | File "/root/.pyenv/versions/3.8.10/lib/python3.8/site-packages/samcli/lib/telemetry/metric.py", line 217, in wrapped_func
864 | return_value = func(*args, **kwargs)
865 | File "/root/.pyenv/versions/3.8.10/lib/python3.8/site-packages/samcli/local/lambdafn/runtime.py", line 176, in invoke
866 | container = self.create(function_config, debug_context, container_host, container_host_interface)
867 | File "/root/.pyenv/versions/3.8.10/lib/python3.8/site-packages/samcli/local/lambdafn/runtime.py", line 73, in create
868 | container = LambdaContainer(
869 | File "/root/.pyenv/versions/3.8.10/lib/python3.8/site-packages/samcli/local/docker/lambda_container.py", line 87, in init
870 | image = LambdaContainer._get_image(lambda_image, runtime, packagetype, imageuri, layers)
871 | File "/root/.pyenv/versions/3.8.10/lib/python3.8/site-packages/samcli/local/docker/lambda_container.py", line 213, in _get_image
872 | return lambda_image.build(runtime, packagetype, image, layers)
873 | File "/root/.pyenv/versions/3.8.10/lib/python3.8/site-packages/samcli/local/docker/lambda_image.py", line 144, in build
874 | self._build_image(image if image else image_name, image_tag, downloaded_layers, stream=stream_writer)
875 | File "/root/.pyenv/versions/3.8.10/lib/python3.8/site-packages/samcli/local/docker/lambda_image.py", line 245, in _build_image
876 | raise ImageBuildException("Error building docker image: {}".format(log["error"]))
877 | samcli.commands.local.cli_common.user_exceptions.ImageBuildException: Error building docker image: The command '/bin/sh -c chmod +x /var/rapid/aws-lambda-rie' returned a non-zero code: 1

Build machine specs:

AWS CodeBuild - Linux env
SAM CLI --version: 1.27.2
AWS region: us-east-1

@RichaSharmaTR
Copy link

We are also facing same issue during sam build-

Image was not found.
188 | Building image...............
189 | Failed to build Docker Image
190 | NoneType: None
191 | Exception on /2015-03-31/functions/*****/invocations [POST]
192 | Traceback (most recent call last):
193 | File "/root/.pyenv/versions/3.8.10/lib/python3.8/site-packages/flask/app.py", line 2447, in wsgi_app
194 | response = self.full_dispatch_request()
195 | File "/root/.pyenv/versions/3.8.10/lib/python3.8/site-packages/flask/app.py", line 1952, in full_dispatch_request
196 | rv = self.handle_user_exception(e)
197 | File "/root/.pyenv/versions/3.8.10/lib/python3.8/site-packages/flask/app.py", line 1821, in handle_user_exception
198 | reraise(exc_type, exc_value, tb)
199 | File "/root/.pyenv/versions/3.8.10/lib/python3.8/site-packages/flask/_compat.py", line 39, in reraise
200 | raise value
201 | File "/root/.pyenv/versions/3.8.10/lib/python3.8/site-packages/flask/app.py", line 1950, in full_dispatch_request
202 | rv = self.dispatch_request()
203 | File "/root/.pyenv/versions/3.8.10/lib/python3.8/site-packages/flask/app.py", line 1936, in dispatch_request
204 | return self.view_functions[rule.endpoint](**req.view_args)
205 | File "/root/.pyenv/versions/3.8.10/lib/python3.8/site-packages/samcli/local/lambda_service/local_lambda_invoke_service.py", line 151, in _invoke_request_handler
206 | self.lambda_runner.invoke(function_name, request_data, stdout=stdout_stream_writer, stderr=self.stderr)
207 | File "/root/.pyenv/versions/3.8.10/lib/python3.8/site-packages/samcli/commands/local/lib/local_lambda.py", line 130, in invoke
208 | self.local_runtime.invoke(
209 | File "/root/.pyenv/versions/3.8.10/lib/python3.8/site-packages/samcli/lib/telemetry/metric.py", line 217, in wrapped_func
210 | return_value = func(*args, **kwargs)
211 | File "/root/.pyenv/versions/3.8.10/lib/python3.8/site-packages/samcli/local/lambdafn/runtime.py", line 176, in invoke
212 | container = self.create(function_config, debug_context, container_host, container_host_interface)
213 | File "/root/.pyenv/versions/3.8.10/lib/python3.8/site-packages/samcli/local/lambdafn/runtime.py", line 73, in create
214 | container = LambdaContainer(
215 | File "/root/.pyenv/versions/3.8.10/lib/python3.8/site-packages/samcli/local/docker/lambda_container.py", line 87, in __init__
216 | image = LambdaContainer._get_image(lambda_image, runtime, packagetype, imageuri, layers)
217 | File "/root/.pyenv/versions/3.8.10/lib/python3.8/site-packages/samcli/local/docker/lambda_container.py", line 213, in _get_image
218 | return lambda_image.build(runtime, packagetype, image, layers)
219 | File "/root/.pyenv/versions/3.8.10/lib/python3.8/site-packages/samcli/local/docker/lambda_image.py", line 144, in build
220 | self._build_image(image if image else image_name, image_tag, downloaded_layers, stream=stream_writer)
221 | File "/root/.pyenv/versions/3.8.10/lib/python3.8/site-packages/samcli/local/docker/lambda_image.py", line 245, in _build_image
222 | raise ImageBuildException("Error building docker image: {}".format(log["error"]))
223 | samcli.commands.local.cli_common.user_exceptions.ImageBuildException: Error building docker image: The command '/bin/sh -c chmod +x /var/rapid/aws-lambda-rie' returned a non-zero code: 1

SAM CLI, version 1.27.2

 


@princio
Copy link

princio commented Oct 5, 2021

I added the line:

[ LOG.info(f"{l}\n") for l in resp_stream ]

in docker/lambda_image.py:244.

The self.docker_client.api.build log response says this:

[Warning] The requested image's platform (linux/arm64/v8) does not match the detected host platform (linux/amd64) and no specific platform was requested

Could it be this the problem?

SAM CLI, version 1.26.0
Docker version 20.10.8, build 3967b7d

@princio
Copy link

princio commented Oct 5, 2021

I made it work.

The problem is that the:
amazon/aws-sam-cli-emulation-image-python3.8
is for platform arm64.

So I edited the image_name variable which is actually generated like that:
amazon/aws-sam-cli-emulation-image-python3.8

and I forced it adding this line [in sam-cli/local/docker/lambda_image.py::109]:
image_name = public.ecr.aws/sam/build-python3.8:1.33.0-20211005031850-x86_64

And the image was built and ran fine.

@mgrandis
Copy link
Contributor

mgrandis commented Oct 5, 2021

Thanks @princio for your investigation!
Indeed these shouldn't be arm64, I have contacted our languages team to revert these to amd64.

@ninjasujan
Copy link

I have fixed this issue by running this command

docker run --rm --privileged multiarch/qemu-user-static --reset -p yes

@jomach
Copy link

jomach commented Dec 10, 2021

Fixed from @ninjasujan worked for me too. I migrated from intel to M1 and then back to Intel...

@claudiodea
Copy link

In my case I was facing this when running SAM in a Gitlab docker runner.
When building with CDK I do

import { Runtime, Tracing, Architecture, SingletonFunctionProps } from "aws-cdk-lib/aws-lambda";
import { execSync } from "child_process";

const arch = execSync("uname -m").toString();

export const defaultFunctionProps: Pick<
  SingletonFunctionProps,
  "runtime" | "memorySize" | "tracing" | "architecture"
> = {
  runtime: Runtime.NODEJS_14_X,
  memorySize: 256,
  tracing: Tracing.ACTIVE,
  architecture: arch === "arm64" ? Architecture.ARM_64 : Architecture.X86_64
};

@deyvisonborges
Copy link

@jmamin
Copy link

jmamin commented Feb 2, 2023

still have the issue even after running @ninjasujan command !:
MacBook-Pro:lambda-local jamin$ docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
Unable to find image 'multiarch/qemu-user-static:latest' locally
latest: Pulling from multiarch/qemu-user-static
205dae5015e7: Pull complete
816739e52091: Pull complete
30abb83a18eb: Pull complete
0657daef200b: Pull complete
30c9c93f40b9: Pull complete
Digest: sha256:fe60359c92e86a43cc87b3d906006245f77bfc0565676b80004cc666e4feb9f0
Status: Downloaded newer image for multiarch/qemu-user-static:latest
WARNING: The requested image's platform (linux/amd64) does not match the detected host platform (linux/arm64/v8) and no specific platform was requested
Error while loading /qemu-binfmt-conf.sh: Exec format error

@angeldelblanco
Copy link

Same problem as @jmamin here when running 'docker run --rm --privileged multiarch/qemu-user-static --reset -p yes' in a Apple M1 mac:

The requested image's platform (linux/amd64) does not match the detected host platform (linux/arm64/v8) and no specific platform was requested

I've tried what @princio proposed, but the other way around - forcing to ARM instead of forcing x86.

Let me explain it better:

In file lambda_image.py, I've added a LOG.info in '_build_image' function before calling '_generate_dockerfile' to know what base_image and architecture variables are set:

LOG.info("base_image %s, architecture %s", base_image, architecture)
As you can see in the response, even I'm in apple m1, the architecture is set to x86_64

base_image public.ecr.aws/lambda/python:3.8-x86_64, architecture x86_64

By forcing the image name and arch to latest and arm64:

base_image = 'public.ecr.aws/sam/build-python3.8:latest' architecture = 'arm64' dockerfile_content = self._generate_dockerfile(base_image, layers, architecture)
I was able to properly build and run the image

@mgrandis: would it be possible to fix it? do not hesitate to ping me for any other info that might help.

Thanks in advamce

@tariromukute
Copy link

In my case, the solution turned out to be simple. Needed to change the template.yaml file from

Architectures:
    - x86_64

to

 Architectures:
    - arm64

See this thread on StackOverflow

@allerasouza
Copy link

In my case, the solution turned out to be simple. Needed to change the template.yaml file from

Architectures:
    - x86_64

to

 Architectures:
    - arm64

See this thread on StackOverflow

It worked for me. I am running on a Mac M1 with colima instead of conventional docker

@davyzhang3
Copy link

In my case, the solution turned out to be simple. Needed to change the template.yaml file from

Architectures:
    - x86_64

to

 Architectures:
    - arm64

See this thread on StackOverflow

Do that and run

sam build
sam local invoke

@adaly56
Copy link

adaly56 commented Feb 25, 2023

docker run --rm --privileged multiarch/qemu-user-static --reset -p yes

yep ... me too just like this ! i've been going back and forth with this issue for a while now. Would love to see a solution

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/local/invoke sam local invoke command blocked/close-if-inactive Blocked for >14 days with no response, will be closed if still inactive after 7 days stage/bug-repro The issue/bug needs to be reproduced
Projects
None yet
Development

No branches or pull requests