Utilizing Connection Strings in PHP/Nodejs/Next Js for App Service – The source code is Deployed in UAT and Production; both have different connection strings, for example. So that pipeline is deployed smoothly without any manual changes utilizing DevOps variables. Let’s take an example of using the same codebase and applying it on UAT and Prod. My UAT will apply UAT DB Connection String, and Production will apply the Production Connection string for the same Codebase.
As you can see, I am adding this MYSQLCONNSTR_ suffix for my connection string as its MYSQL; you can update the suffix accordingly. Application settings don’t need any suffixes. Also, you can retrieve secrets from the key vault to run them in the App service without exposing them.
At runtime, connection strings are available as environment variables, prefixed with the following connection types:
- SQLServer: SQLCONNSTR_
- MySQL: MYSQLCONNSTR_
- SQLAzure: SQLAZURECONNSTR_
- Custom: CUSTOMCONNSTR_
- PostgreSQL: POSTGRESQLCONNSTR_
For Retrieving from Key Vault, you need to specific the URI, and it will retrieve the latest version if the below format is used.
@Microsoft.KeyVault(SecretUri=https://az-az-pr-ause-kv.vault.azure.net/secrets/accesstoken/)
Utilizing Application Settings inside JSON in Azure Static Web Apps
To Retrieve from Azure Key Vault –
@Microsoft.KeyVault(SecretUri=https://az-az-pr-ause-kv.vault.azure.net/secrets/accesstoken/)
You can see Key vault Reference has been added.
System Assigned Identity is Turned On. To talk with key vault
Key Vault Reference
So that secret is not exposed even to the App Service Administrator for example.