question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

`sam local invoke` (Using HelloWorld template throws "Error: Error building docker image"

See original GitHub issue

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 -

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:17 (6 by maintainers)

github_iconTop GitHub Comments

8reactions
mgrandiscommented, 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

4reactions
ninjasujancommented, Oct 6, 2021

I have fixed this issue by running this command

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

sam local invoke - AWS Serverless Application Model
The AWS SAM CLI first tries to locate a template file built using the sam build command, located in the .aws-sam subfolder, and...
Read more >
Newest 'aws-sam-cli' Questions - Stack Overflow
I have a cdk project that includes lambda functions, dynamodb and api gateway. To run it locally I use SAM local: sam local...
Read more >
Invoking AWS Lambda functions locally using AWS SAM CLI
You will need to install AWS CLI, AWS SAM CLI and Docker to invoke a Lambda function locally. If you already have AWS...
Read more >
Build Serverless APIs with Node.js and AWS Lambda
Error : Running AWS SAM projects locally requires Docker. Have you got it installed and running? Once the application is running, make a...
Read more >
AWS Lambda in Go, running locally with SAM and Docker
How to build and test AWS Lambdas locally before deploying to AWS!
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found