beam serve functions like an Ngrok server that live-reloads as you work. Beam monitors changes in your local file system and forwards the remote container logs to your local shell.
Serve is great for prototyping. You can develop in a containerized cloud environment in real-time, with adjustable CPU, memory, GPU resources.
It’s also great for testing an app before deploying it. Served functions are orchestrated identically to deployments, which means you can test your Beam workflow end-to-end before deploying.
Creating a Deployment Preview
To start an ephemeral
serve session, you’ll use the
beam serve app.py
Sessions end automatically after 10 minutes of inactivity.
By default, Beam will sync all the files in your working directory to the remote container. This allows you to use the files you have locally while developing. If you want to prevent some files from getting uploaded, you can create a
Calling the API
When you run this command, you’ll see a URL printed in your shell. Serve URLs are public and authenticated with your Beam credentials.
user@MacBook stable-diffusion-gpu % beam serve app.py i Using cached image. ✓ App initialized. i Uploading files... ✓ Container scheduled, logs will appear below. ✓ 🏁 Started gateway server at https://apps.beam.cloud/serve/6g3j7/64ef83a30038cd00089945b8
When you call the API, you’ll see the logs stream to your terminal:
user@MacBook stable-diffusion-gpu % beam serve app.py i Using cached image. ✓ App initialized. i Uploading files... ✓ Container scheduled, logs will appear below. ✓ 🏁 Started gateway server at https://apps.beam.cloud/serve/6g3j7/64ef83a30038cd00089945b8 INFO: | Starting app... INFO: | Loading handler in 'app.py:generate_image'... INFO: | Ready for tasks. INFO: | Received task: aa7cfe01-5a7a-42a0-84ea-f0bd00e1249b INFO: | Running task: aa7cfe01-5a7a-42a0-84ea-f0bd00e1249b Loading pipeline components...: 100%|##########| 7/7 [00:12<00:00, 1.51s/it] Saved Image: <PIL.Image.Image image mode=RGB size=512x512 at 0x7F3EA30FAEB0> INFO: | Task complete: aa7cfe01-5a7a-42a0-84ea-f0bd00e1249b, duration: 18.756892204284668s
Viewing Previews in the Web Dashboard
You can view all your Deployment Previews in the web dashboard, on the Previews Page.
When you click on a Preview, you’ll see a command to reconnect to the session, as well as an API request to invoke your function.