Azure Developer CLI
Introduction
Section titled “Introduction”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.
Getting started
Section titled “Getting started”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.
Install the packages
Section titled “Install the packages”Run the following command to install the required packages:
pip install azlocalYou 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 in
Section titled “Sign in”Sign azd in to the emulator:
azdlocal auth loginLogged 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 a template
Section titled “Create a template”Create the following three files.
A configuration file called azure.yaml:
# yaml-language-server: $schema=https://raw.githubusercontent.com/Azure/azure-dev/main/schemas/v1.0/azure.yaml.json
name: simple-templateA template called 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:
{ "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentParameters.json#", "contentVersion": "1.0.0.0", "parameters": { "name": { "value": "${AZURE_ENV_NAME}" } }}Deploy the template
Section titled “Deploy the template”Create an environment that targets the emulator’s subscription:
azdlocal env new my-env --subscription 00000000-0000-0000-0000-000000000000 --location westeuropeThen deploy the template:
azdlocal upIf 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:
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:
lstk az start-interceptionaz group show --name my-env-rg --query "{name:name, state:properties.provisioningState, tags:tags}"{ "name": "my-env-rg", "state": "Succeeded", "tags": { "azd-env-name": "my-env" }}Clean up
Section titled “Clean up”Delete the resources without a confirmation prompt, and stop the interception:
azdlocal down --force --purgelstk az stop-interception