Processing SFTP Events with Azure Function and Event Hub
Today, we are going to use the Azure Storage SFTP functionality and an Event Hub to trigger an Azure Function. The Azure Function will then process the Write Logs, and output the File name, SFTP Local User name, Agent header and the SFTP Client IP address to the host, from there you can do whatever you want with the data.
๐๏ธ Environment Overviewโ
So for my environment, I have a:
- A SFTP Hierarchical namespace-enabled storage account
- A Flex Consumption Azure Function App
- A Standard Event Hub Namespace with an event hub instance with 1 partition and 1 consumer group
These resources are hosted in the New Zealand North Azure region.
So I've already pre-created these resources, but is there some more information about the resource configuration that you can follow along with?
๐ฆ Storage Account Configurationโ
For the Azure Storage account with SFTP enabled, I'm using the following configuration:
-
Name: sftptestluketest
-
Location: New Zealand North
-
Performance: Standard
-
Redundancy: Locally-redundant storage (LRS)
-
Account kind: StorageV2 (general purpose v2)
-
Access tier: Hot
-
Key features enabled:
- Hierarchical namespace (HNS) โ
- SFTP support โ
- Local user authentication โ
-
Security settings:
- Minimum TLS version: 1.2
- Public blob access: Disabled
- Network access: Public (default action: Allow)
- HTTPS only: Enabled
- Azure services bypass: Enabled
- Shared key access: Enabled
-
Diagnostic settings:
- StorageWrite logs sent to Event Hub Namespace
- Configured to capture StorageWrite logs for all blob operations
The hierarchical namespace (HNS) is a prerequisite for SFTP support in Azure Storage. This enables the directory and subdirectory structure that SFTP clients expect when connecting.
With SFTP and local users enabled, you can create local SFTP users that can authenticate with password and/or SSH key authentication, and assign them permissions to specific containers and directories within your storage account.
๐ก Event Hub Namespace Configurationโ
For receiving and processing the Azure Storage SFTP events, I've set up an Event Hub Namespace with the following configuration:
- Name: sftpeventhub
- Location: New Zealand North
- Pricing tier: Standard
- Throughput capacity: 1 throughput unit (base capacity)
- Key features:
- Auto-inflate enabled โ
- Maximum throughput units: 5 (scales automatically as needed)
- Zone redundant โ
- Kafka support enabled โ
- Security settings:
- Minimum TLS version: 1.2
- Network access: Public
Within this namespace, I've created an Event Hub instance with a single partition and a dedicated consumer group that will be used by the Azure Function to process SFTP events.
โ๏ธ Function App Configurationโ
For processing the SFTP events from the Event Hub, I've set up an Azure Function App with the following configuration:
- Name: sftptest
- Location: Australia East (Different from Storage and Event Hub to demonstrate cross-region capability)
- Hosting plan: FlexConsumption (serverless)
- Runtime stack: PowerShell 7.4
- Operating system: Linux
- Key features:
- Application Insights enabled โ
- HTTPS only โ
- System-assigned managed identity โ
- Scaling configuration:
- Maximum instance count: 100
- Instance memory: 2048 MB
- Security settings:
- Public network access: Enabled
- Client certificate mode: Required