Skip to content

Latest commit

 

History

History
54 lines (37 loc) · 2.39 KB

File metadata and controls

54 lines (37 loc) · 2.39 KB
title Azure CLI Script Sample - Rotate storage account access keys
description Create an Azure Storage account, then retrieve and rotate its account access keys.
services storage
author stevenmatthew
ms.service azure-storage
ms.devlang azurecli
ms.topic sample
ms.date 03/02/2022
ms.author shaas
ms.custom devx-track-azurecli

Create a storage account and rotate its account access keys

This script creates an Azure Storage account, displays the new storage account's access keys, then renews (rotates) the keys.

[!INCLUDE quickstarts-free-trial-note]

[!INCLUDE azure-cli-prepare-your-environment.md]

Sample script

[!INCLUDE cli-launch-cloud-shell-sign-in.md]

Run the script

:::code language="azurecli" source="~/azure_cli_scripts/storage/rotate-storage-account-keys/rotate-storage-account-keys.sh" id="FullScript":::

Clean up resources

[!INCLUDE cli-clean-up-resources.md]

az group delete --name $resourceGroup

Sample reference

This script uses the following commands to create the storage account and retrieve and rotate its access keys. Each item in the table links to command-specific documentation.

Command Notes
az group create Creates a resource group in which all resources are stored.
az storage account create Creates an Azure Storage account in the specified resource group.
az storage account keys list Displays the storage account access keys for the specified account.
az storage account keys renew Regenerates the primary or secondary storage account access key.

Next steps

For more information on the Azure CLI, see Azure CLI documentation.

Additional storage CLI script samples can be found in the Azure CLI samples for Azure Blob storage.