Get Started
Introduction
This guide will walk you through the essential steps to set up your serverless environment on Snowcell. You'll learn how to create and deploy a Docker image, and how to execute serverless functions that leverage the power of GPUs. By the end of this tutorial, you'll be able to customize deployments for your specific needs.
Prerequisites
Before you begin, make sure you have the following:
- Basic familiarity with terminal commands.
- A Snowcell account and your API key for authenticating requests.
- Docker installed on your machine for building and managing container images.
Setting Up Docker
To deploy a serverless function using Snowcell, you first need to build a Docker image. This image will package your code and its dependencies, ensuring that everything runs smoothly on Snowcell's infrastructure.
Steps to get started with Docker:
-
Install Docker: If you haven’t installed Docker yet, follow the Docker installation guide.
-
Create a Docker Hub Account: You’ll need a Docker registry to store and push your container images. Sign up at Docker Hub if you don’t have an account.
-
Clone the Worker Template: Snowcell provides a worker template as a starting point for your deployments. Run the following command to clone it:
git clone https://github.com/snowcell/serverless-worker-template
-
Navigate to the Template Directory: Use the terminal to navigate to the project folder:
cd serverless-worker-template
Building and Pushing Your Docker Image
Now, we’ll build the Docker image that will be deployed to Snowcell:
-
Build the Docker Image: Run the following command to create an image from the template:
docker build --platform linux/amd64 --tag <your-dockerhub-username>/<image-name>:<tag> .
-
Push the Image to Your Docker Registry: Once the image is built, you’ll need to push it to your Docker Hub account:
docker push <your-dockerhub-username>/<image-name>:<tag>
Tip: If you're using a machine with a different architecture (like an ARM-based chip), make sure to specify the platform linux/amd64
in the build command. This ensures compatibility with Snowcell's servers.
Deploying a Serverless Endpoint on Snowcell
With your Docker image ready, it's time to deploy it on Snowcell and create a serverless endpoint:
-
Login to Snowcell Console: Head over to the Snowcell Dashboard and sign in with your credentials.
-
Create a New Endpoint: Navigate to the "Endpoints" section and click Create New Endpoint.
-
Configure Your Endpoint:
- Choose a unique name for your endpoint.
- Select the GPU configuration that suits your workload (e.g., 16 GB, 24 GB GPU).
- Set the number of workers you need to handle the load.
- Optionally enable Quick Start to reduce initialization time for containers.
- Input the Docker image name in the format
<your-dockerhub-username>/<image-name>:<tag>
.
-
Allocate Resources: Specify the memory, CPU, and GPU resources required to run your container.
-
Deploy: After configuring, click Deploy to launch your serverless function. Your endpoint will be live within a few moments, ready to receive requests.
Sending a Request to Your Endpoint
Once your serverless endpoint is live, you can start sending requests:
-
API Key Authentication: Make sure your Snowcell API key is available, as it will be used to authenticate your requests.
-
Send a Request: You can send requests using
curl
,Postman
, or any HTTP client. For example, usingcurl
:curl -X POST https://api.snowcell.io/v1/your-endpoint-id/run \
-H "Authorization: Bearer <your-api-key>" \
-H "Content-Type: application/json" \
-d '{"input": {"prompt": "Generate a high-resolution image of a futuristic city."}}' -
Check Job Status: You’ll receive a response with a job ID. Use this ID to check the status of your job:
curl https://api.snowcell.io/v1/your-endpoint-id/status/<job-id> \
-H "Authorization: Bearer <your-api-key>"
- Retrieve Output: Once the job is complete, you’ll receive a JSON response with the result, including any generated images or data.
Summary
You have now successfully built and deployed a serverless function on Snowcell using Docker. You’re able to trigger the function with API requests and retrieve the output through Snowcell’s serverless infrastructure.
This guide only scratches the surface of what Snowcell can do. Explore additional customization options, such as advanced GPU configurations, job queueing, and more in the Snowcell documentation.