Skip to content
Get Started for Free

Azure Developer CLI

The Azure Developer CLI (azd) provisions Azure resources from templates and deploys application code to them. This guide shows you how to use it with the LocalStack Azure emulator.

This guide is designed for users who are new to the LocalStack Azure emulator and assumes basic knowledge of how ARM and Bicep templates work in Azure. It shows you how to create an Azure resource group from a Bicep template.

Run the following command to install the required packages:

Terminal window
pip install azlocal

You now have access to the following LocalStack tool:

CLI tool LocalStack tool Purpose
azd azdlocal Deploy ARM/Bicep templates

azdlocal is a wrapper around azd, so you keep the full functionality of the original tool. It redirects every command to the running emulator.

Sign azd in to the emulator:

Terminal window
azdlocal auth login
Output
Logged in to Azure as (any-app)

azdlocal signs in with a placeholder service principal that the emulator accepts, so no browser window opens. Without this step, azdlocal up stops at WARNING: You must be logged into Azure perform this action.

Create the following three files.

A configuration file called azure.yaml:

azure.yaml
# yaml-language-server: $schema=https://raw.githubusercontent.com/Azure/azure-dev/main/schemas/v1.0/azure.yaml.json
name: simple-template

A template called infra/main.bicep:

infra/main.bicep
targetScope = 'subscription'
@minLength(1)
@maxLength(64)
@description('Name of the environment which is used to generate a short unique hash used in all resources.')
param name string
var tags = { 'azd-env-name': name }
resource resourceGroup 'Microsoft.Resources/resourceGroups@2021-04-01' = {
name: '${name}-rg'
location: 'westeurope'
tags: tags
}

A parameter file called infra/main.parameters.json:

infra/main.parameters.json
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentParameters.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"name": {
"value": "${AZURE_ENV_NAME}"
}
}
}

Create an environment that targets the emulator’s subscription:

Terminal window
azdlocal env new my-env --subscription 00000000-0000-0000-0000-000000000000 --location westeurope

Then deploy the template:

Terminal window
azdlocal up

If you skip azdlocal env new, azdlocal up asks for the environment name, subscription and location, just like azd does with Azure.

When the deployment has finished, you should see output similar to the following:

Output
SUCCESS: Your up workflow to provision and deploy to Azure completed in 15 seconds.

You can now verify that the resource group exists using lstk az:

Terminal window
lstk az start-interception
az group show --name my-env-rg --query "{name:name, state:properties.provisioningState, tags:tags}"
Output
{
"name": "my-env-rg",
"state": "Succeeded",
"tags": {
"azd-env-name": "my-env"
}
}

Delete the resources without a confirmation prompt, and stop the interception:

Terminal window
azdlocal down --force --purge
lstk az stop-interception
Was this page helpful?