- Newest
- Most votes
- Most comments
The error you're encountering suggests that there's a mismatch between how SageMaker expects to run your container and how your Dockerfile is configured.
For SageMaker endpoints, including serverless ones, the container needs to be set up slightly differently. SageMaker expects to be able to run your container with a 'serve' argument, which your current ENTRYPOINT doesn't accommodate.
To resolve this, you should modify your Dockerfile in the following way:
-
Instead of directly running uvicorn in the ENTRYPOINT, create a separate script (e.g., 'serve.py') that will start your FastAPI application.
-
Make this script executable and use it as your ENTRYPOINT.
Here's how you can modify your Dockerfile:
FROM python:3.11 WORKDIR /opt/ml/code COPY inference.py requirements.txt serve.py ./ RUN pip install --no-cache-dir -r requirements.txt RUN chmod +x serve.py EXPOSE 8080 ENTRYPOINT ["python", "serve.py"]
Then, create a 'serve.py' file with the following content:
import subprocess import sys if __name__ == "__main__": subprocess.run(["uvicorn", "inference:app", "--host", "0.0.0.0", "--port", "8080"])
This setup allows SageMaker to run your container with the 'serve' argument, which it will ignore, while still starting your FastAPI application correctly.
Remember to ensure that your 'inference.py' file contains a FastAPI app named 'app', as that's what the uvicorn command in 'serve.py' expects.
Also, make sure your container can respond to health check requests on the '/ping' endpoint and handle inference requests on the '/invocations' endpoint, as these are required by SageMaker.
By making these changes, your container should be compatible with SageMaker's expectations for serverless endpoints.
Sources
Custom Inference Code with Hosting Services - Amazon SageMaker AI
Sagemaker endpoint creation failing | AWS re:Post
answered 2 years ago
Relevant content
asked 5 years ago
asked 2 years ago
