ECR Image Docker works locally but "The provided image is invalid" in Lambda

1

I'm doing some ML inference function with lambda. I am currently using PyTorch, PyTorch Geometric, and some saved models. The image size is ~7gb. I have increased my size limit for lambda fns to 10gb.

Using the exact commands provided in the ECR, I built and pushed my image to ECR. I also verified that the app.py handler code works and gives the expected output. So everything's building and running correctly on my location machine when I docker run and docker exec into my running container. great!

I am also able to successfully push to ECR. No complaints.

The problem arises when I try to make a lambda function that uses that image. Both are us-west-2, I think I have all the IAM roles correct (I've done this before for another ECR/Lambda pair that uses tensorflow). But when I try to create the function, it runs for <30s and then I see a "The provided image is invalid" error.

My questions are:

  • Is the problem with my Dockerfile?
    • If yes, what are the conditions necessary for a Docker image to build and run successfully locally, but not on lambda?
  • Could it be an IAM role issue?
  • Is there some reason that lambda doesn't support PyTorch Geometric?
  • What does ""The provided image is invalid"" mean? How can I find out more about the cause of this error?

The only thing I can think is possibly the problem is that sometimes you need to install torch-scatter first. But then the docker image should fail to build.

Here's my Dockerfile:

FROM public.ecr.aws/lambda/python:3.8 COPY app.py ${LAMBDA_TASK_ROOT} COPY . . RUN python3 -m pip install -r requirements.txt --target ${LAMBDA_TASK_ROOT}

In the directory I have some saved pytorch geometric models, pytorch models, and data files. (csvs, tensors).

Thank you!

3 Answers
0

Hi, don't you have a naming issue of your image like the one reported in https://github.com/serverless/serverless/issues/8636 when you use it in the Lambda ?

In this case, the user combined :latest with @sha and it creates a problem like yours

Best,

Didier

profile pictureAWS
EXPERT
answered 2 years ago
0

I'm experiencing the exact same issue. I’ve tried using different versions of the AWS Python base image, and the Python code only includes the handler returning a string. However, I keep encountering the The provided image is invalid error regardless. I’ve also tried increasing both the memory and storage allocations, but to no avail. Are Python images not supported for Lambda? Generally, AWS provides more meaningful error messages that can help resolve the issue, but this one is not very informative.

    FROM public.ecr.aws/lambda/python:3.11
    COPY lambda_function.py ${LAMBDA_TASK_ROOT}
    CMD [ "lambda_function.handler" ]

and the python lambda_function.py file has this. import sys def handler(event, context): return 'Hello from AWS Lambda using Python' + sys.version + '!'*

EDIT My machine: windows 10, using Podman and build with --platform linux/amd64

After looking to the state of the function, I found this.

    "State": "Failed",
    "StateReason": "ImageLayerFailure: UnsupportedImageLayerDetected - Layer Digest sha256:ac49b43c92d795a3c4559f8668db011267a10e7e3e3799b70050e887e4032d85",
    "StateReasonCode": "InvalidImage",
answered 8 months ago
0

Hi, I wanted to follow up on this issue. Was this resolved? If so, can you share the solution?

answered 6 months ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions