Skip to content

Latest commit

 

History

History
154 lines (106 loc) · 6.84 KB

File metadata and controls

154 lines (106 loc) · 6.84 KB

Azure CLI Deployment

This directory includes Bash scripts designed for deploying and testing the sample Function App utilizing the lstk CLI. Refer to the Azure Functions App with Managed Identity guide for details about the sample application.

Prerequisites

Before deploying this solution, ensure you have the following tools installed:

Installing lstk CLI

Deploying to LocalStack requires the lstk CLI, which routes Azure CLI commands to the emulator (run lstk az start-interception before deploying). Install it using Homebrew:

brew install localstack/tap/lstk

or npm:

npm install -g @localstack/lstk

Alternatively, download a pre-built binary from the lstk releases page. For more information, see the lstk CLI documentation and the lstk GitHub repository.

Architecture Overview

The user-managed-identity.sh and system-managed-identity.sh scripts create the following Azure resources using Azure CLI commands:

  1. Azure Storage Account: Provides blob storage with input and output containers for storing text blobs processed by the function app.
  2. Azure App Service Plan: Defines the compute resources (CPU, memory, and scaling options) that host the Azure Functions app.
  3. Azure Functions App: Hosts the serverless application that processes text blobs. The function app uses managed identity to securely access the Azure Storage Account without requiring explicit credentials.
  4. Managed Identity: Provides secure, credential-free authentication between the Azure Functions app and storage account. Supports both system-assigned and user-assigned identity types.
  5. Role Assignment: Grants the Azure Functions app's managed identity the Storage Blob Data Contributor and Storage Queue Data Contributor roles, enabling read/write access to blob containers and queues for processing text data.

For more information on the sample application, see Azure Functions App with Managed Identity.

Provisioning Scripts

This sample provides two Bash scripts to streamline the deployment process by automating the provisioning of Azure resources and the sample application:

  • user-managed-identity.sh: Configures the Azure Functions App to authenticate with Azure Storage using a user-assigned managed identity
  • system-managed-identity.sh: Configures the Azure Functions App to authenticate with Azure Storage using a system-assigned managed identity

These scripts eliminate manual configuration steps and enable one-command deployment of the entire infrastructure.

Note

You can use lstk az to proxy Azure CLI commands to the LocalStack for Azure emulator. Alternatively, run lstk az start-interception to automatically intercept and redirect all az commands to LocalStack. To revert back to the default behavior and send commands to the Azure cloud, run lstk az stop-interception.

Deployment

You can set up the Azure emulator by utilizing LocalStack for Azure Docker image. Before starting, ensure you have a valid LOCALSTACK_AUTH_TOKEN to access the Azure emulator. Refer to the Auth Token guide to obtain your Auth Token and specify it in the LOCALSTACK_AUTH_TOKEN environment variable. The Azure Docker image is available on the LocalStack Docker Hub. To pull the Azure Docker image, execute the following command:

docker pull localstack/localstack-azure

Start the LocalStack Azure emulator using the localstack CLI, execute the following command:

# Set the authentication token
export LOCALSTACK_AUTH_TOKEN=<your_auth_token>

# Start the LocalStack Azure emulator
IMAGE_NAME=localstack/localstack-azure localstack start -d
localstack wait -t 60

# Route all Azure CLI calls to the LocalStack Azure emulator
lstk az start-interception

Navigate to the scripts folder:

cd samples/function-app-managed-identity/python/scripts

Make the script executable:

chmod +x deploy.sh

Run the deployment script:

./deploy.sh

Validation

After deployment, you can use the validate.sh script to verify that all resources were created and configured correctly:

#!/bin/bash

# Variables
# Check resource group
az group show \
  --name local-rg \
  --output table

# List resources
az resource list \
  --resource-group local-rg \
  --output table

# Check function app status
az functionapp show  \
  --name local-func-test \
  --resource-group local-rg \
  --output table

# Check storage account properties
az storage account show \
  --name localstoragetest \
  --resource-group local-rg \
  --output table

# List storage containers
az storage container list \
  --account-name localstoragetest \
  --output table \
  --only-show-errors

Cleanup

To destroy all created resources:

# Delete resource group and all contained resources
az group delete --name local-rg --yes --no-wait

# Verify deletion
az group list --output table

This will remove all Azure resources created by the CLI deployment script.

Related Documentation