I need to monitor Azure Blob Storage and check if a blob is created in Python. In Logic Apps, this is how it looks:
Can you help me out and tell me how I should write this in Python?
Advertisement
Answer
One of the workarounds is to use Azure functions Blob trigger for python where you can able to retrieve the details for the blob once it has been added to the storage.
For checking if the blob is created/exists in blob storage you can check one of my answers from this SO Thread
JavaScriptx31311import logging
2import azure.functions as func from azure.storage.blob import
3BlockBlobService
4
5
6def main(req: func.HttpRequest) -> func.HttpResponse:
7logging.info('Python HTTP trigger function processed a request.')
8
9ContainerName="<YOUR_CONTAINER_NAME>";
10AccountName="<YOUR_ACCOUNT_NAME>";
11AccountKey="<ACCESS_KEY>";
12
13block_blob_service = BlockBlobService(account_name=AccountName, account_key=AccountKey)
14
15name = req.params.get('name')
16if not name:
17try:
18req_body = req.get_json()
19except ValueError:
20return func.HttpResponse(f"Enter the blob you are searching for")
21else:
22name = req_body.get('name')
23
24if block_blob_service.exists(container_name=ContainerName, blob_name=name):
25return func.HttpResponse(f"{name}, Is already Present in container")
26else:
27return func.HttpResponse(
28"{name}, Is not Present in container",
29status_code=200
30) ```
31
REFERENCES: