This project provides extensions for working with Azure Blob Storage in Azure Functions using Node.js. It simplifies the integration and interaction with Blob Storage, enabling developers to build scalable and efficient serverless applications.
- Blob Trigger: Automatically trigger Azure Functions when a blob is created or updated in a specified container.
- Blob Input Binding: Read blob content as input to your function.
- Cached Client Management: Optimized client reuse with intelligent caching
- Resource Management: Proper disposal patterns for Azure resource clients
- Performance Optimizations: Reduced overhead for blob operations
- Node.js (LTS version recommended)
- Azure Functions Core Tools
- An active Azure subscription
To install the required dependencies, run:
npm install @azure/functions-extensions-blob
-
Set up your Azure Blob Storage account:
- Create a storage account in the Azure portal.
- Create a container within the storage account.
-
Configure your function:
- Update the
function.json
file to include the appropriate bindings for Blob Storage.
- Update the
-
Import and initialize the extension:
import '@azure/functions-extensions-blob'; // Ensures at the top of the file
Using in Azure Functions
import "@azure/functions-extensions-blob"; // Ensures side effects run
import { StorageBlobClient } from "@azure/functions-extensions-blob";
import { app, InvocationContext } from "@azure/functions";
export async function storageBlobTrigger1(
blobStorageClient: StorageBlobClient,
context: InvocationContext
): Promise<void> {
context.log(
`Storage blob function processed blob "${context.triggerMetadata.name}"`
);
try {
// Use the cached client for better performance
const downloadBlockBlobResponse =
await blobStorageClient.blobClient.download();
// Additional operations...
}
}
app.storageBlob("storageBlobTrigger1", {
path: "snippets/SomeFolder/{name}",
connection: "AzureWebJobsStorage",
sdkBinding: true, //Ensure this is set to true
handler: storageBlobTrigger1,
});
- Run locally:
- Use the Azure Functions Core Tools to run your function locally:
bash func start
- Deploy to Azure:
- Deploy your function to Azure using the following command:
bash func azure functionapp publish <YourFunctionAppName>
Contributions are welcome! Please follow the contribution guidelines when submitting issues or pull requests.
This project is licensed under the MIT License.