aws-sam-cli: sam local invoke throws "Error: Error building docker image"

Description:

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

Steps to reproduce:

Observed result:

Expected result:

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

  1. OS:
  2. sam --version:
  3. AWS region:

Add --debug flag to command you are running

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 4
  • Comments: 17 (13 by maintainers)

Most upvoted comments

It does appear isolated to only CodeBuild. Or at least it’s running fine locally on my Mac machine.

We have not yet started explicitly definiting an Architecture in our Lambda function, so it’s defaulting to x86_64 Architecture.

Local Logs:

$ sam local start-lambda --warm-containers EAGER --port 3000 --env-vars env.json
Initializing the lambda functions containers.
Image was not found.
Removing rapid images for repo public.ecr.aws/sam/emulation-nodejs14.x
Building image.....................................................................................................................................................................................
Skip pulling image and use local one: public.ecr.aws/sam/emulation-nodejs14.x:rapid-1.33.0-x86_64.

Mounting /dev/test-lambda-repo/.aws-sam/build/TestLambdaFunction as /var/task:ro,delegated inside runtime container
Containers Initialization is done.
Starting the Local Lambda Service. You can now invoke your Lambda Functions defined in your template through the endpoint.
2021-10-04 17:43:17  * Running on http://127.0.0.1:3000/ (Press CTRL+C to quit)

We are facing same issue while invoking a lambda in AWS code build machine-

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 AWS region: us-east-1 AWS CodeBuild - Linux env