This is an example of a Next.js application allowing you to upload photos to an Azure Storage Account.
Option 1: Use an existing Azure Storage Account
When running locally, the Azure.Identity
library expects a user signed in to the Azure CLI. This user needs to have the following permission
in the associated Azure Storage account: Storage Blob Data Contributor
Option 2: Create an Azure Storage Account
- Open the Azure CLI
- Type
az login
- Create a resource group with
az group create --name <resource group name> --location westus
- Create a storage account
az storage account create --name <account-name> --resource-group storage-resource-group --location westus --sku Standard_RAGRS --kind StorageV2
It's recommended practice to use a Service Principal account instead of your own when testing your applications against Azure. To create a Service Principal account, you can use the following commands in the Azure CLI
-
az login
-
Create the SP with the following command:
az ad sp create-for-rbac --name "<your SP name>" --role contributor --scopes "<your storage account resource id>"
-
Now login to the Azure CLI with the new SP credentials:
az login --service-pricipal --username APP_ID --password PASSWORD --tenant TENANT_ID
-
You can confirm that you're now signed in with the SP account by running this command:
az account show
You can find the Resource ID of your Storage Account in the Azure Portal > Storage Account > Endpoints or you can use the CLI
az storage account show --name <your storage account name> --query 'id'
yarn dev
– Starts the Next.js app atlocalhost:3000
.
For the infrastructure, you can use the webapp.bicep
file in the deployment directory to deploy an Azure Web App to run this Next.js app
Steps to deploy:
- In the Azure CLI, sign in with an account that has subscription
Contributor
role - Use the
webapp.bicep
file to deploy the Azure Infrastrucure - Then use the following command to deploy the bicep template:
az deployment group create --resource-group <your resource group name> --template-file webapp.bicep
To deploy the code, you can use the committed GitHub action or use one of these options in the official documentation