Interactive Development with Ray Client

Learn how to deploy a simple Ray Serve application to Anyscale for development or testing.

You can deploy your Ray Serve application to Anyscale for testing and development using Ray Client.

First, install the necessary dependencies for Ray Serve locally:

pip install "ray[serve]"

Then, create an Anyscale project for the application.

$ mkdir hello_world
$ cd hello_world
$ anyscale init
Project name: hello_world
Project prj_6SCoYQrJU4BYzpcpj0mKxk created. View at https://api.anyscale.com/projects/prj_6SCoYQrJU4BYzpcpj0mKxk

Write and run a simple "hello world" Ray Serve application. For this example, we will accept all internet traffic to our Serve deployment for testing purposes. See Restricting Internet Traffic for more information on how to keep Serve deployments private to internet traffic.

deploy.py
import ray
from ray import serve

ray.init("anyscale://my_cluster", allow_public_internet_traffic=True, autosuspend=-1)

serve.start(detached=True)

@serve.deployment
def hello(request):
   name = request.query_params["name"]
   return f"Hello {name}!"

hello.deploy()

After the script runs, you should see a link to the cluster like this:

> python deploy.py
...
Url to head node of cluster is: https://session-9mhabpzb13x3up3qad4co.i.anyscaleuserdata.com

Your function is now deployed at https://serve-session-9mhabpzb13x3up3qad4co.i.anyscaleuserdata.com. Use the code snippet below to test your Serve deployment, replacing 9mhabpzb13x3up3qad4co in the URL with your own id.

import requests

resp = requests.get(
   "https://serve-session-9mhabpzb13x3up3qad4co.i.anyscaleuserdata.com"
   "/hello?name=Anyscale")
print(resp.text)
# output: Hello Anyscale!

To update your application, simply re-run the deployment script on the cluster again. Your local directory will automatically be synced to the cluster each time you run the script.

Last updated

Was this helpful?