1

I have a problem similar to Localstack Lambda Invoke fails on Windows only without terraform and with a different exception. I started my localstack using docker-compose up with the following docker-compose.yml:

version: "3.8"

services:
  localstack:
    image: localstack/localstack:latest
    ports:
      - "53:53"
      - "443:443"
      - "4510-4520:4510-4520"
      - "4566-4620:4566-4620"
    environment:
      - SERVICES=s3,sqs,ec2,dynamodb,lambda,sns
      - DEFULAT_REGION=us-east-1
      - DEBUG=1
      - DATA_DIR=/Users/michaelpukshanski/localstack/data
      - PORT_WEB_UI=${PORT_WEB_UI- }
      - LOCALSTACK_API_KEY=*****
      - LAMBDA_EXECUTOR=docker
      - KINESIS_ERROR_PROBABILITY=${KINESIS_ERROR_PROBABILITY- }
      - KINESIS_PROVIDER=kinesalite
      - DOCKER_HOST=unix:///var/run/docker.sock
      - HOST_TMP_FOLDER=/tmp/localstack
    volumes:
      - "${TMPDIR:-/tmp/localstack}:/tmp/localstack"
      - "/var/run/docker.sock:/var/run/docker.sock"
      - ./bin:/docker-entrypoint-initaws.d
    env_file:
      - .env
    networks:
      - localstack
    privileged: true
    
  reindex-lambda:
    image: reindex-lambda:latest
    build:
      context: ./sayatalabs-functions/reindex_display_models
    volumes:
      - "/var/run/docker.sock:/var/run/docker.sock"
    networks:
      - localstack

networks:
  localstack:
    external: false
    driver: bridge
    name: localstack

I also had the following Dockerfile in the reindex directory:

FROM public.ecr.aws/lambda/python:3.6

RUN python -m pip install --upgrade pip

COPY requirements.txt ${LAMBDA_TASK_ROOT}
RUN pip install -r ${LAMBDA_TASK_ROOT}/requirements.txt --quiet

COPY src/ ${LAMBDA_TASK_ROOT}

ENV AWS_ACCESS_KEY_ID=******
ENV AWS_DEFAULT_REGION=eu-central-1
ENV AWS_SECRET_ACCESS_KEY=*******

VOLUME '/var/run/docker.sock:/var/run/docker.sock'

CMD ["main.lambda_handler"]

I created the function:

awslocal lambda create-function --function-name reindex-lambda --code ImageUri=reindex-lambda:latest --role arn:aws:iam::000000000:role/lambda-ex --handler main.lambda_handler --timeout 11

With the output:

{
    "FunctionName": "reindex-lambda",
    "FunctionArn": "arn:aws:lambda:us-east-1:000000000000:function:reindex-lambda",
    "Role": "arn:aws:iam::000000000:role/lambda-ex",
    "Handler": "main.lambda_handler",
    "Description": "",
    "Timeout": 11,
    "LastModified": "2021-10-13T12:04:22.175+0000",
    "Version": "$LATEST",
    "VpcConfig": {},
    "TracingConfig": {
        "Mode": "PassThrough"
    },
    "RevisionId": "accc1abd-5ebe-4afe-a05e-4d12892aa548",
    "Layers": [],
    "State": "Active",
    "LastUpdateStatus": "Successful",
    "PackageType": "Zip"
}

After invoking the lambda:

awslocal lambda invoke --function-name arn:aws:lambda:us-east-1:000000000000:function:reindex-lambda response.json

I'm getting:

{
    "StatusCode": 200,
    "FunctionError": "Unhandled",
    "LogResult": "",
    "ExecutedVersion": "$LATEST"
}

And I'm getting the exception in the docker logs:

localstack_1      | 2021-10-13T12:19:57:INFO:localstack.services.awslambda.lambda_executors: Empty event body specified for invocation of Lambda "arn:aws:lambda:us-east-1:000000000000:function:reindex-lambda"
localstack_1      | 2021-10-13T12:19:57:INFO:localstack.services.awslambda.lambda_executors: Running lambda: arn:aws:lambda:us-east-1:000000000000:function:reindex-lambda
localstack_1      | 2021-10-13T12:19:57:DEBUG:localstack_ext.services.awslambda.lambda_extended: Putting invocation event (request ID a25b589f) for Lambda 'arn:aws:lambda:us-east-1:000000000000:function:reindex-lambda' to queue
localstack_1      | 2021-10-13T12:19:57:DEBUG:localstack_ext.services.awslambda.lambda_launcher: Executing custom image execution for image reindex-lambda:latest
localstack_1      | 2021-10-13T12:19:57:DEBUG:localstack.utils.docker: Getting the entrypoint for image: reindex-lambda:latest
localstack_1      | 2021-10-13T12:19:57:DEBUG:localstack.utils.docker: Running container with image: reindex-lambda:latest
localstack_1      | 2021-10-13T12:19:57:DEBUG:localstack.utils.docker: Creating container with image reindex-lambda:latest, command '['main.lambda_handler']', volumes [('/tmp/localstack', '/tmp')], env vars {'AWS_ACCESS_KEY_ID': 'test', 'AWS_SECRET_ACCESS_KEY': 'test', 'AWS_REGION': 'us-east-1', 'DOCKER_LAMBDA_USE_STDIN': '1', 'LOCALSTACK_HOSTNAME': '172.26.0.3', 'AWS_ENDPOINT_URL': 'http://172.26.0.3:4566', 'EDGE_PORT': '443', '_HANDLER': 'main.lambda_handler', 'AWS_LAMBDA_FUNCTION_TIMEOUT': '11', 'AWS_LAMBDA_FUNCTION_NAME': 'reindex-lambda', 'AWS_LAMBDA_FUNCTION_VERSION': '$LATEST', 'AWS_LAMBDA_FUNCTION_INVOKED_ARN': 'arn:aws:lambda:us-east-1:000000000000:function:reindex-lambda', 'AWS_LAMBDA_COGNITO_IDENTITY': '{}', 'AWS_LAMBDA_FUNCTION_MEMORY_SIZE': 1536, '_LAMBDA_RUNTIME': None, 'AWS_LAMBDA_LOG_GROUP_NAME': '/aws/lambda/reindex-lambda', 'AWS_LAMBDA_LOG_STREAM_NAME': 'test', 'AWS_LAMBDA_RUNTIME_API': 'reindex-lambda.us-east-1.localhost.localstack.cloud:4566', 'LOCALSTACK_HOSTS_ENTRY': 'reindex-lambda.us-east-1.localhost.localstack.cloud', 'LOCALSTACK_DEBUG': '1'}
localstack_1      | 2021-10-13T12:19:57:DEBUG:localstack.utils.docker: Starting container a452bc9de4f3d51b53c4d6300ab10acea46d2560161f7221595040418cc02b4e
localstack_1      | 2021-10-13T12:19:58:ERROR:localstack_ext.services.awslambda.lambda_extended: Unable to invoke Lambda "arn:aws:lambda:us-east-1:000000000000:function:reindex-lambda": 
localstack_1      | Traceback (most recent call last):
localstack_1      |   File "/opt/code/localstack/.venv/lib/python3.7/site-packages/docker/api/client.py", line 268, in _raise_for_status
localstack_1      |     response.raise_for_status()
localstack_1      |   File "/opt/code/localstack/.venv/lib/python3.7/site-packages/requests/models.py", line 943, in raise_for_status
localstack_1      |     raise HTTPError(http_error_msg, response=self)
localstack_1      | requests.exceptions.HTTPError: 400 Client Error: Bad Request for url: http+docker://localhost/v1.41/containers/a452bc9de4f3d51b53c4d6300ab10acea46d2560161f7221595040418cc02b4e/start
localstack_1      | 
localstack_1      | During handling of the above exception, another exception occurred:
localstack_1      | 
localstack_1      | Traceback (most recent call last):
localstack_1      |   File "/opt/code/localstack/localstack/utils/docker.py", line 1252, in start_container
localstack_1      |     container.start()
localstack_1      |   File "/opt/code/localstack/.venv/lib/python3.7/site-packages/docker/models/containers.py", line 404, in start
localstack_1      |     return self.client.api.start(self.id, **kwargs)
localstack_1      |   File "/opt/code/localstack/.venv/lib/python3.7/site-packages/docker/utils/decorators.py", line 19, in wrapped
localstack_1      |     return f(self, resource_id, *args, **kwargs)
localstack_1      |   File "/opt/code/localstack/.venv/lib/python3.7/site-packages/docker/api/container.py", line 1111, in start
localstack_1      |     self._raise_for_status(res)
localstack_1      |   File "/opt/code/localstack/.venv/lib/python3.7/site-packages/docker/api/client.py", line 270, in _raise_for_status
localstack_1      |     raise create_api_error_from_http_exception(e)
localstack_1      |   File "/opt/code/localstack/.venv/lib/python3.7/site-packages/docker/errors.py", line 31, in create_api_error_from_http_exception
localstack_1      |     raise cls(e, response=response, explanation=explanation)
localstack_1      | docker.errors.APIError: 400 Client Error for http+docker://localhost/v1.41/containers/a452bc9de4f3d51b53c4d6300ab10acea46d2560161f7221595040418cc02b4e/start: Bad Request ("OCI runtime create failed: container_linux.go:380: starting container process caused: exec: "/tmp/3bd20f4b.sh": stat /tmp/3bd20f4b.sh: no such file or directory: unknown")
localstack_1      | 
localstack_1      | During handling of the above exception, another exception occurred:
localstack_1      | 
localstack_1      | Traceback (most recent call last):
localstack_1      |   File "/opt/code/localstack/.venv/lib/python3.7/site-packages/localstack_ext/services/awslambda/lambda_extended.py", line 440, in do_run_lambda_executor
localstack_1      |   File "/opt/code/localstack/.venv/lib/python3.7/site-packages/localstack_ext/services/awslambda/lambda_launcher.py", line 222, in docker_separate_execute_in_container
localstack_1      |   File "/opt/code/localstack/.venv/lib/python3.7/site-packages/localstack_ext/services/awslambda/lambda_launcher.py", line 217, in custom_image_execute_in_container
localstack_1      |   File "/opt/code/localstack/localstack/utils/docker.py", line 1383, in run_container
localstack_1      |     attach=not detach,
localstack_1      |   File "/opt/code/localstack/localstack/utils/docker.py", line 1257, in start_container
localstack_1      |     raise ContainerException()
localstack_1      | localstack.utils.docker.ContainerException
localstack_1      | 2021-10-13T12:19:58:INFO:localstack_ext.services.awslambda.lambda_extended: Lambda container output: None
localstack_1      | None
localstack_1      | 2021-10-13T12:19:58:INFO:localstack.services.awslambda.lambda_api: Error executing Lambda function arn:aws:lambda:us-east-1:000000000000:function:reindex-lambda:  Traceback (most recent call last):
localstack_1      |   File "/opt/code/localstack/.venv/lib/python3.7/site-packages/docker/api/client.py", line 268, in _raise_for_status
localstack_1      |     response.raise_for_status()
localstack_1      |   File "/opt/code/localstack/.venv/lib/python3.7/site-packages/requests/models.py", line 943, in raise_for_status
localstack_1      |     raise HTTPError(http_error_msg, response=self)
localstack_1      | requests.exceptions.HTTPError: 400 Client Error: Bad Request for url: http+docker://localhost/v1.41/containers/a452bc9de4f3d51b53c4d6300ab10acea46d2560161f7221595040418cc02b4e/start
localstack_1      | 
localstack_1      | During handling of the above exception, another exception occurred:
localstack_1      | 
localstack_1      | Traceback (most recent call last):
localstack_1      |   File "/opt/code/localstack/localstack/utils/docker.py", line 1252, in start_container
localstack_1      |     container.start()
localstack_1      |   File "/opt/code/localstack/.venv/lib/python3.7/site-packages/docker/models/containers.py", line 404, in start
localstack_1      |     return self.client.api.start(self.id, **kwargs)
localstack_1      |   File "/opt/code/localstack/.venv/lib/python3.7/site-packages/docker/utils/decorators.py", line 19, in wrapped
localstack_1      |     return f(self, resource_id, *args, **kwargs)
localstack_1      |   File "/opt/code/localstack/.venv/lib/python3.7/site-packages/docker/api/container.py", line 1111, in start
localstack_1      |     self._raise_for_status(res)
localstack_1      |   File "/opt/code/localstack/.venv/lib/python3.7/site-packages/docker/api/client.py", line 270, in _raise_for_status
localstack_1      |     raise create_api_error_from_http_exception(e)
localstack_1      |   File "/opt/code/localstack/.venv/lib/python3.7/site-packages/docker/errors.py", line 31, in create_api_error_from_http_exception
localstack_1      |     raise cls(e, response=response, explanation=explanation)
localstack_1      | docker.errors.APIError: 400 Client Error for http+docker://localhost/v1.41/containers/a452bc9de4f3d51b53c4d6300ab10acea46d2560161f7221595040418cc02b4e/start: Bad Request ("OCI runtime create failed: container_linux.go:380: starting container process caused: exec: "/tmp/3bd20f4b.sh": stat /tmp/3bd20f4b.sh: no such file or directory: unknown")
localstack_1      | 
localstack_1      | During handling of the above exception, another exception occurred:
localstack_1      | 
localstack_1      | Traceback (most recent call last):
localstack_1      |   File "/opt/code/localstack/localstack/services/awslambda/lambda_api.py", line 811, in run_lambda
localstack_1      |     lock_discriminator=lock_discriminator,
localstack_1      |   File "/opt/code/localstack/localstack/services/awslambda/lambda_executors.py", line 426, in execute
localstack_1      |     return do_execute()
localstack_1      |   File "/opt/code/localstack/localstack/services/awslambda/lambda_executors.py", line 416, in do_execute
localstack_1      |     return _run(func_arn=func_arn)
localstack_1      |   File "/opt/code/localstack/localstack/utils/cloudwatch/cloudwatch_util.py", line 157, in wrapped
localstack_1      |     raise e
localstack_1      |   File "/opt/code/localstack/localstack/utils/cloudwatch/cloudwatch_util.py", line 153, in wrapped
localstack_1      |     result = func(*args, **kwargs)
localstack_1      |   File "/opt/code/localstack/localstack/services/awslambda/lambda_executors.py", line 403, in _run
localstack_1      |     raise e
localstack_1      |   File "/opt/code/localstack/localstack/services/awslambda/lambda_executors.py", line 399, in _run
localstack_1      |     result = self._execute(lambda_function, inv_context)
localstack_1      |   File "/opt/code/localstack/localstack/services/awslambda/lambda_executors.py", line 707, in _execute
localstack_1      |     result = self.run_lambda_executor(lambda_function=lambda_function, inv_context=inv_context)
localstack_1      |   File "/opt/code/localstack/.venv/lib/python3.7/site-packages/localstack_ext/services/awslambda/lambda_extended.py", line 525, in run_lambda_executor
localstack_1      |   File "/opt/code/localstack/.venv/lib/python3.7/site-packages/localstack_ext/services/awslambda/lambda_extended.py", line 428, in run_lambda_executor
localstack_1      |   File "/opt/code/localstack/.venv/lib/python3.7/site-packages/localstack_ext/services/awslambda/lambda_extended.py", line 440, in do_run_lambda_executor
localstack_1      |   File "/opt/code/localstack/.venv/lib/python3.7/site-packages/localstack_ext/services/awslambda/lambda_launcher.py", line 222, in docker_separate_execute_in_container
localstack_1      |   File "/opt/code/localstack/.venv/lib/python3.7/site-packages/localstack_ext/services/awslambda/lambda_launcher.py", line 217, in custom_image_execute_in_container
localstack_1      |   File "/opt/code/localstack/localstack/utils/docker.py", line 1383, in run_container
localstack_1      |     attach=not detach,
localstack_1      |   File "/opt/code/localstack/localstack/utils/docker.py", line 1257, in start_container
localstack_1      |     raise ContainerException()
localstack_1      | localstack.utils.docker.ContainerException

Am I doing anything wrong?

  • Are you using the community or pro version of localstack? Take a look at the feature differences between the two, particularly lambda layers and custom images. – Danielle M. Oct 13 '21 at 12:39
  • @DanielleM. I'm using pro version in localstack – Michael Pukshanski Oct 13 '21 at 13:16
  • Hi @MichaelPukshanski. Did you figure this out? I have exactly the same error. – David Brown Dec 15 '21 at 20:20
  • I have the same error with the Pro version of localstack on a Mac. The tmp file in the error is created by localstack in the `/tmp/localstack` directory of its container. The created Lambda container has a volume mount for /tmp -> /tmp/localstack. The container fails to start with "failed to create shim: OCI runtime create failed" because that tmp shell script doesn't exist. – Jeff Standen Jun 03 '22 at 20:59

1 Answers1

0

I faced the same error and the issue was in your dockerfile, the network name and the service name are both set to localstack. Can you give a unique name for the network (localstack_nw) and retry it

Ranjini M
  • 1
  • 1
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Steven-Carrot Jul 14 '22 at 21:26