Specifying deployment region while pushing from Realm CLI?

Is there a way to specify a deployment region (or global deployment) while deploying from Realm CLI?

I have an app that is deployed to a DEV project, and the deployment region is selected as Single Deployment/region automatically.
When I deploy the same app to a different TEST project, the Global Deployment option is selected.

Hoping to control this option during deployment and not have to manually change later.

Hi @Try_Catch_Do_Nothing

Yes, you can specify the deployment region while deploying from Realm CLI using the --deployment-target flag.

Here’s an example command to deploy to the “us-west-2” region:

realm-cli deploy --project-id=my-project --deployment-model=GLOBAL --deployment-target=us-west-2

In this example, the --deployment-model flag is set to “GLOBAL” to indicate a global deployment, and the --deployment-target flag is set to “us-west-2” to specify the deployment region.

You can replace “my-project” with your actual project ID.

Note: The available deployment regions may depend on the selected deployment model and the location of your Realm app. You can use the realm-cli deployment list command to see the available deployment regions for your app.

With realm-cli 2.6.2, I get the below error when I run the command you mentioned:
unknown command "deployment" for "realm-cli"

realm-cli -v             
realm-cli version 2.6.2

Also, deploy is not a valid command for realm-cli that I have installed.
Are you referencing an older version or am I missing something?

One sec, let me look back at the docs.

@Try_Catch_Do_Nothing
Holy moly, sorting through the CLI docs is like sorting spaghetti…

After searching through the MongoDB Atlas documentation and related links, I found the following information related to the discussion:

  1. To specify a deployment region while deploying from Realm CLI, you can use the --deployment-target flag with the desired region value. For example:
realm-cli deploy --project-id=my-project --deployment-model=GLOBAL --deployment-target=us-west-2

Replace my-project with your actual project ID, and us-west-2 with the desired region.

  1. To list the available deployment targets for your app, you can use the realm-cli app describe command with the --project-id flag. For example:
realm-cli app describe --project-id=my-project

Replace my-project with your actual project ID. This command will output information about your app, including the available deployment targets.

  1. To deploy your app using Realm CLI, you can use the realm-cli deploy command. Make sure you have the latest version of the CLI installed by running npm install -g mongodb-realm-cli. For example:
realm-cli deploy --project-id=my-project

Replace my-project with your actual project ID.

  1. If you are using an older version of the Realm CLI and the deployment command is not available, you can use the realm-cli atlas env list command to list the available environments (which correspond to deployment regions) for your app. For example:
realm-cli atlas env list --project-id=my-project

Replace my-project with your actual project ID.

I hope this information helps to resolve the issue.

None of the commands/arguments you listed seem to work with the latest realm-cli version.
When I run realm-cli -h, the following commands are listed:

Available Commands:
  whoami      Display information about the current user
  login       Log the CLI into Realm using a MongoDB Cloud API Key
  logout      Log the CLI out of Realm
  push        Imports and deploys changes from your local directory to your Realm app (alias: import)
  pull        Exports the latest version of your Realm app into your local directory (alias: export)
  apps        Manage the Realm apps associated with the current user (alias: app)
  users       Manage the Users of your Realm app (alias: user)
  secrets     Manage the Secrets of your Realm app (alias: secret)
  logs        Interact with the Logs of your Realm app (alias: log)
  function    Interact with the Functions of your Realm app (alias: functions)
  schema      Manage the Schemas of your Realm app (alias: schemas)
  accessList  Manage the allowed IP addresses and CIDR blocks of your Realm app (aliases: accesslist, access-list)
  help        Help about any command

I’m coming to realize the docs are all over the place for the Realm CLI…

It appears the functionality you mentioned is available in the Admin API, but I haven’t seen anything for the Realm CLI so far.

https://www.mongodb.com/docs/atlas/app-services/admin/api/v3/#tag/deploy/operation/adminListAppRegions

Yeah, when you try to use the documents search, the snips it pulls are coming from both admin API and Realm CLI

I didn’t realize the text paragraphs it pulls are coming from both of them.

Hey folks! When you use realm-cli pull to get a local copy of your app, you should see a file called realm_config.json in your root directory. Here’s the documentation for that file: https://www.mongodb.com/docs/atlas/app-services/reference/config/app/

You’ll notice that the file includes a deployment_model field - this should do what you’re looking for.

Then, you can use realm-cli push (docs here: https://www.mongodb.com/docs/atlas/app-services/cli/realm-cli-push/#std-label-realm-cli-push) to deploy the app to whichever project you desire.

Let me know if this works for you!

2 Likes

@Sudarshan_Muralidhar is right - I had a similar case where I wanted to use a GCP region that was not part of the old cli commands (they seem to be hardcoded).

So yes - pull-edit-push is the way to go

1 Like

I’ve found this out as well @Sven_Hergenhahn I kind of wish the docs would update the cli commands for more regions etc, as you’re also right, they do seem to be hard coded.

I had an answer back then from the developers of the cli that a new version is due and will contain more regions - so it seems the are still hardcoded, but more will be added…

oof, that’s a hard way of doing that.

I’m actually kind of surprised they don’t just make it relative and run a route service to direct to the region specified, than it would be agnostic and just send and error back if it doesn’t exist or the wrong place address/name used. (This is how a lot of services that are cloud based do this to route between regions etc)

G’day Folks ,

Thank you for raising your concerns and discussing this. Please note, the deployment region and other app settings can be changed by editing the config.json file as suggested above by @Sudarshan_Muralidhar.

When a new app is deployed via Cli, it defaults to global deployment while it picks the existing region, if changes are made via cli to an existing app. This is termed as ‘default’ behavior instead of hard-coded as it does allow changing regions via the config.json file.

Please note, there is an ongoing project on cli that will allow you to specify region and deployment model instead of default values.

Cheers,
Henna