SOLVED

Azure Static Web App-CLI script to create plus add location: eastus2

Copper Contributor

Hi,

I am a beginner using Azure, have set up a basic free account to try creating a static web app, using the SWA CLI tool. Found a useful command line script (https://edi.wang/post/2022/11/17/deploy-to-azure-static-web-app-from-local-machine-without-github-ac...), adapted it for the SWA CLI: swa deploy ./build --env production, successfully creating a static web app from a "build" folder on my desktop. All good except I would prefer, if possible, the location/region to be eastus2 (closer to me and potential users) rather than the default which is westusa2. Appears that once created in a specific region, it cannot be changed. So, I need to figure out how to add a different location using the CLI and a script, and create a new version.

 

Tried, with no success: swa deploy ./build --env production --location "eastus2"

SWA CLI error that there is no such command line option. Maybe my syntax is wrong? Or maybe, no such option in the SWA CLI?

 

Tried Cloud Power Shell for my account: az config set defaults.location=eastus2 and, separately, az configure --defaults location=useast2

To test, created new static web apps, and no joy: location, using either command was still westus2.

 

Is there a way to use the SWA CLI and set the location to eastus2, while creating the static web app? I read a little about setting up an SWA environment variable for a parameter, like location, but as a beginner, it was complex and not sure what the steps are to achieve it, where to start.

 

Hoping someone can help, provide leads, suggestions for a beginner like me to get the new static web app with an eastus2 location.

 

Thank you in advance for your help.

 

2 Replies
best response confirmed by saratogacoach (Copper Contributor)
Solution

@saratogacoach 

 

There are no options for specifying deployment location or region yet. Because Azure Static Web app uses Global infrastructure it will automatically distribute your app files to closest datacenter to your customers, only resource group is regional, in your case, I will show you how to deploy to a regional resource group.

 

1. Go to Azure portal first and create a new static web app in your desired location, in your case East US 2. Make sure you select "Other" in Deployment details - source. Wait for 5 minutes (important, otherwise you will not see this app in step 2).

 

2. Use SWA to deploy your code, it will list existing static web apps which were created from Azure portal in the previous step. Select the app you created in step 1.

ediwang_0-1676953281879.png

 

3. This time your code will be deployed to East US 2 resource group.

Hi Edi,

OK, this worked: I was able to create a new static web app plus its resource group in the eastus2 region.

Thank you, Edi, very much!

Best Wishes,
saratogacoach

1 best response

Accepted Solutions
best response confirmed by saratogacoach (Copper Contributor)
Solution

@saratogacoach 

 

There are no options for specifying deployment location or region yet. Because Azure Static Web app uses Global infrastructure it will automatically distribute your app files to closest datacenter to your customers, only resource group is regional, in your case, I will show you how to deploy to a regional resource group.

 

1. Go to Azure portal first and create a new static web app in your desired location, in your case East US 2. Make sure you select "Other" in Deployment details - source. Wait for 5 minutes (important, otherwise you will not see this app in step 2).

 

2. Use SWA to deploy your code, it will list existing static web apps which were created from Azure portal in the previous step. Select the app you created in step 1.

ediwang_0-1676953281879.png

 

3. This time your code will be deployed to East US 2 resource group.

View solution in original post