Host a Web Service
Pod
provides a way to run arbitrary code on Beam. It’s an abstraction that lets you deploy a serverless container as a service, without the need to refactor your code to Beam’s Pythonic syntax.
This is especially useful when you want to bring your own container image or host generic webservers on Beam. It can be used for a variety of use cases, such as:
- Running arbitrary code in a serverless container.
- Hosting Jupyter Notebooks and Streamlit apps.
- Executing untrusted user code in a secure environment.
- Running a test suite in a CI/CD pipeline on a remote container.
…and much more (if you’ve got a cool use case, let us know!)
Running Arbitrary Code
You can run arbitrary code inline by specifying a container image, environment variables, and entry point directly from the command line.
Jupyter Notebooks
For example, the following command spins up a Jupyter notebook server on Beam:
When you run this command, Beam will build the container image, sync the files, and start the container. It will then print the URL of the notebook server to the console.
Parameters
Pods can be heavily customized to fit your needs.
Using Custom Images
You can customize the container image using the Image
object. This can be customized with Python packages, shell commands, Conda packages, and much more.
Specifying Entry Points
An entry point is the command or script that will run when the container starts. You can interact with Pods using the CLI or the Python SDK.
Passing Environment Variables
You can pass environment variables into your container for credentials or other parameters. Like entry points, environment variables can be defined in both the CLI or the Python SDK:
Terminating a Pod
Pod instances can be terminated directly using the terminate()
method. Alternatively, you can terminate the container the Pod is running on by using the beam container stop <container-id>
command.
Lifecycle
Timeouts
Pods are serverless and automatically scale-to-zero.
By default, pods will be terminated after 10 minutes without any active connections to the hosted URL or until the process exits by itself. Making a connection request (i.e. accessing the URL in your browser) will keep the container alive until the timeout is reached.
You can set a custom timeout by passing the keep-warm-seconds
parameter when creating a pod. By specifying -1, the pod will not spin down to due inactivity, and will remain up until either the entrypoint process exits, or you explicitly stop the container.
Keep Alive for 5 minutes
Keep Alive Indefinitely
List Running Pods
You can list all running Pods using the beam container list
command.
You can kill any container by running beam container stop <container-id>
.
Was this page helpful?