Blob + Event Grid on Azure: event-driven processing
Blob + Event Grid on Azure allows you to automatically process files as soon as they are uploaded to Azure Blob Storage. This connection is useful for event-driven scenarios, such as file transformation, indexing, or real-time notifications.
Prerequisites
- Azure account with permissions to create resources (Resource Group, Storage Account, Function App).
- Azure CLI installed and authenticated (az login).
- zip (or another way to package files) and Node.js locally to create the function (JavaScript example).
Step 1: Create Resource Group and Storage Account
Create a Resource Group, a Storage Account and a container where you will upload the files. Replace <storageaccountname> with a unique all-lowercase name.
RESOURCE_GROUP="rg-eventgrid-demo"
LOCATION="northeurope"
STORAGE_ACCOUNT="<storageaccountname>" # nome único, minúsculas
az group create -n $RESOURCE_GROUP -l $LOCATION
az storage account create -n $STORAGE_ACCOUNT -g $RESOURCE_GROUP --sku Standard_LRS --kind StorageV2
az storage container create -n uploads --account-name $STORAGE_ACCOUNT
Step 2: Create an Azure Function App (Node.js)
Create a Function App in a Consumption Plan that will contain the function with an Event Grid binding. Use a unique name for the Function App.
FUNCTION_APP="funevdemo"
az functionapp create -g $RESOURCE_GROUP -n $FUNCTION_APP \
--storage-account $STORAGE_ACCOUNT --runtime node --functions-version 4 \
--consumption-plan-location $LOCATION
Step 3: Create and deploy the function with an Event Grid trigger
Create a simple function that receives events from Event Grid. Minimal local structure:
BlobEventListener/
index.js
function.json
index.js:
module.exports = async function (context, eventGridEvent) {
context.log('EventGrid event received:', JSON.stringify(eventGridEvent));
const data = eventGridEvent.data || {};
context.log('Blob URL:', data.url || data.blobUrl || data.url);
};
function.json:
{
"bindings": [
{
"type": "eventGridTrigger",
"name": "eventGridEvent",
"direction": "in"
}
]
}
Package and deploy:
zip -r function.zip BlobEventListener
az functionapp deployment source config-zip -g $RESOURCE_GROUP -n $FUNCTION_APP --src function.zip
Step 4: Create the Storage Event Grid subscription to the Function
Create a subscription that sends events of type Microsoft.Storage.BlobCreated to the Function. Obtain the id of the Storage Account and the id of the Function (endpoint).
STORAGE_ID=$(az storage account show -n $STORAGE_ACCOUNT -g $RESOURCE_GROUP --query id -o tsv)
SUB_ID=$(az account show --query id -o tsv)
FUNCTION_ENDPOINT="/subscriptions/$SUB_ID/resourceGroups/$RESOURCE_GROUP/providers/Microsoft.Web/sites/$FUNCTION_APP/functions/BlobEventListener"
az eventgrid event-subscription create \
--name BlobCreateToFunction \
--source-resource-id $STORAGE_ID \
--endpoint-type azurefunction \
--endpoint "$FUNCTION_ENDPOINT" \
--included-event-types Microsoft.Storage.BlobCreated
Note: the platform automatically validates the endpoint. If you receive a validation error, confirm that the function is deployed and the function name (BlobEventListener) matches.
Step 5: Test — upload a file and view logs
Upload a file to the container and observe the Function logs in real time.
echo "teste" > test.txt
az storage blob upload --account-name $STORAGE_ACCOUNT -c uploads -n test.txt --file ./test.txt
# View Function logs (in a separate terminal)
az functionapp log tail -g $RESOURCE_GROUP -n $FUNCTION_APP
You should see a line with "EventGrid event received" and the blob URL. If it does not appear, check the subscription with az eventgrid event-subscription show.
Verify the result
Confirm the flow is working:
- The file upload (az storage blob upload) triggers a Microsoft.Storage.BlobCreated event.
- The Azure Function logs the event (see az functionapp log tail) and shows the blob URL.
- If needed, check the subscription with az eventgrid event-subscription list --source-resource-id $STORAGE_ID.
Conclusion
By connecting Azure Blob Storage to an Azure Function via Event Grid you have created a simple event-driven pipeline useful for automatic file processing. Next steps: read the blob inside the function (use @azure/storage-blob), filter events by prefix/suffix in the subscription and add retries/Dead Letter. Tip: if endpoint validation fails, confirm that the function responds and that the function route/name are correct — want to try filtering by extension (.csv) before processing?