Reputation: 75
I am working on setting up an Azure Function with a Blob Storage trigger using Python. Despite following the documentation and ensuring my setup seems correct, the trigger is not firing when a new blob is added to the specified container.
Scenario: After adding a new Excel file to the container, the function needs to remove duplicates from the file and save the output file to the same container location.
function.json:
{
"bindings": [
{
"name": "inputblob",
"type": "blobTrigger",
"path": "gistest/gis sample data/{name}",
"connection": "gisfuntest_STORAGE",
"direction": "in"
},
{
"name": "outputblob",
"type": "blob",
"path": "gistest/gis sample data/output.csv",
"connection": "gisfuntest_STORAGE",
"direction": "out"
}
]
}
function_app.py
import logging
import azure.functions as func
import pandas as pd
from io import BytesIO
app = func.FunctionApp()
@app.blob_trigger(arg_name="inputblob",
path="gistest/gis sample data/{name}",
connection="gisfuntest_STORAGE")
@app.blob_output(arg_name="outputblob",
path="gistest/gis sample data/output.csv",
connection="gisfuntest_STORAGE")
def main(inputblob: func.InputStream, outputblob: func.Out[bytes]):
logging.info(f"Python blob trigger function processed blob \n"
f"Name: {inputblob.name}\n"
f"Blob Size: {inputblob.length} bytes")
# Read the Excel file from the input blob
try:
df = pd.read_excel(inputblob)
except Exception as e:
logging.error(f"Error reading Excel file: {e}")
return
# Remove duplicates
df = df.drop_duplicates()
# Convert the DataFrame to CSV
csv_data = df.to_csv(index=False)
# Save the CSV to the output blob
outputblob.set(csv_data.encode('utf-8'))
logging.info(f"Processed file saved to output blob with duplicates removed")
local.settings.json:
{
"IsEncrypted": false,
"Values": {
"FUNCTIONS_WORKER_RUNTIME": "python",
"AzureWebJobsFeatureFlags": "EnableWorkerIndexing",
"gisfuntest_STORAGE": "DefaultEndpointsPr---.windows.net"
}
}
host.json
{
"version": "2.0",
"logging": {
"applicationInsights": {
"samplingSettings": {
"isEnabled": true,
"excludedTypes": "Request"
}
}
},
"extensionBundle": {
"id": "Microsoft.Azure.Functions.ExtensionBundle",
"version": "[4.*, 5.0.0)"
}
}
I used the following run/test option to execute the function but didn't get any output (the output.csv was not generated in the correct location). Could you please help me resolve this issue and get the correct output?
Could you please help me resolve this issue and get the correct output?
Upvotes: 0
Views: 127
Reputation: 65461
You have you have a container name that contains blanks ("gis sample data"), this is not allowed.
Upvotes: 0