This repository contains an azd template that uses Aspire as the application orchestrator. The template includes:
- Azure Key Vault for app secrets
- Azure App Configuration for app settings
- Azure Service Bus or RabbitMQ for messaging
- two sample ASP.NET applications that use the above services
The architecture of the template is depicted below:
The template supports both local and hybrid development mode (see below for details).
To enable this, messaging between apps is abstracted using Rebus 🚌.
To prove connectivity to Azure Key Vault, the WebApp1:AppKey and WebApp2:AppKey secrets are used.
Similarly, for Azure App Configuration, the WebApp1:AppName and WebApp2:AppName settings are used.
You can create these using the portal or the following az commands:
az keyvault secret set `
--vault-name <keyvault> `
--name WebApp1--AppKey `
--value MyAppKey1 `
--output none
az appconfig kv set `
--name <appconfig> `
--key WebApp1:AppName `
--value MyWebApp1 `
--yes `
--output none
The bicep template used to provision the Azure resources takes the following parameters:
environmentName: corresponds toAZURE_ENV_NAMEand is set byazdlocation: corresponds toAZURE_LOCATIONand is set byazdhybridEnvironment: corresponds toHYBRID_ENVIRONMENTand must be set manually (can be eithertrueorfalse)principalId: corresponds toAZURE_PRINCIPAL_IDand must be set manually (it's the ID of the developer, i.e. you)
The principal specified above will be given appropriate permissions to access the provisioned resources, e.g. create secrets in the key vault.
In this mode no resources are provisioned and all apps and services run locally:
- app secrets are stored in the project's user secrets
- app settings are stored in the project's
appsettings.Development.json - a RabbitMQ container, which includes the management portal, is used for messaging between the apps
Since no resources need to be provisioned, there are no pre-requisites to use local development:
- to run the application in Visual Studio, select the Development profile and hit F5
- in VS Code, use:
dotnet run --project .\src\AzdAspire.AppHost\AzdAspire.AppHost.csproj --launch-profile Development
In this mode only a few service resources are provisioned and all apps run locally:
- app secrets are stored in Azure Key Vault
- app settings are stored in Azure App Configuration
- Azure Service Bus is used for messaging between the apps
Hybrid development is enabled as follows:
- create a new
azdenvironment using the commandazd env new <environment>, where<environment>is your chosen environment name - locate the newly created file
.azure\<environment>\.envand append the lineHYBRID_ENVIRONMENT="true" - create the service resources by running
azd provision(you can use the--previewflag to preview the changes without creating any resources) - locate the
Productionprofile in thelaunchSettings.jsonof the Aspire host project - in the above profile, set the
DOTNET_ENVIRONMENTvariable to<environment> - to run the application in Visual Studio, select the Production profile and hit F5
- in VS Code, use:
dotnet run --project .\src\AzdAspire.AppHost\AzdAspire.AppHost.csproj --launch-profile Production
In this mode all the required resources are provisioned and all apps and services run in the cloud.
To create a fully provisioned runtime environment, follow these steps:
- download the template with
azd init -t fabio-marini/azd-aspire-basic -b master - login to Azure with
azd auth login - create the service resources by running
azd provision - deploy the applications by running
azd deploy
To test that everything is wired up correctly, use the POST /echo endpoint of WebApp1, e.g.
Invoke-WebRequest -Uri https://localhost:7099/echo `
-Method POST `
-Headers @{ "Content-Type" = "application/json" } `
-Body '{ "message": "Hello World! :)" }'
Take a look at the logs for WebApp2 to confirm connectivity to the message bus. They should show that an EchoRequest was received:
Received AzdAspire.ServiceDefaults.EchoRequest with message: Hello World! :) and headers [x-appkey, LocalKey1], [x-appname, LocalApp1]
And the logs for WebApp1 should show that an EchoResponse was received:
Received AzdAspire.ServiceDefaults.EchoResponse with message: Hello World! :) and headers [x-appkey, LocalKey2], [x-appname, LocalApp2]
The messages headers will contain the values of the AppName and AppKey settings and will confirm the connectivity to Key Vault and App config (for hybrid environments).
