How to make Http trigger work on this azure function that works fine as timetrigger ?

Nuno Trigo 51 Reputation points
2022-10-13T20:51:27.983+00:00

def main(mytimer: func.TimerRequest) -> None:

default_credential= DefaultAzureCredential()  

# Create a Secret Client, so we can grab our Connection String.  
secret_client =SecretClient(  
    vault_url= "*******",  
    credential= default_credential  
    )  
# Grab the Blob Connection String, from our Azure Key Vault.  
blob_conn_string = secret_client.get_secret(       
    name='blob-storage-connection-string'  
    )  
# Connect to the Container.  
container_client = ContainerClient.from_connection_string(      
    conn_str=blob_conn_string.value,  
    container_name='****'  
 )  
  
my_blobs = container_client.list_blobs(name_starts_with="SS")  
container_client.delete_blobs(*my_blobs)  
     
table_01222 = "https://data.ssb.no/api********01222/"  
query_01222 =  {"query":[{"code":"Region","selection":{"filter":"agg:KommSummer","values":["K-0301"]}},{"code":"ContentsCode","selection":{"filter":"item","values":["Fodselsoverskudd4","Nettoinnflytting9"]}}],"response":{"format":"json-stat2"}}  

"#several api requests to several tables"

tables=[table_01222,table_03013,table_03014,table_03723,table_05327, table_07129,table_07221,table_08931,table_09030,  
        table_09031,table_09175,table_09189,table_09786, table_11618,table_11721]  
queries= [query_01222,query_03013,query_03014,query_03723,query_05327, query_07129,query_07221,query_08931,query_09030,  
          query_09031,query_09175,query_09189,query_09786, query_11618,query_11721]  
names=["table_01222","table_03013","table_03014","table_03723","table_05327", "table_07129","table_07221","table_08931","table_09030",  
       "table_09031","table_09175","table_09189","table_09786", "table_11618","table_11721"]  

  
ts=datetime.datetime.now()  

for i in range(len(tables)):  
    resultat = requests.post(tables[i], json = queries[i])  
    dataset = pyjstat.Dataset.read(resultat.text)  
    df = dataset.write('dataframe')  
    a=df.columns  
    #resultat.json()["updated"]  
    for name in df.columns:  
       if name == "kvartal":  
            df=df.pivot_table(index=name, columns='statistikkvariabel', values='value')  
       elif name == "år":  
           df=df.pivot_table(index=name, columns='statistikkvariabel', values='value')  
       elif name== "måned":  
           df=df.pivot_table(index=name, columns='statistikkvariabel', values='value')  
       else:  
           continue  
    #df.to_csv('SSB - %s opprettet %s - %s.csv'%(names[i],ts.month,ts.year))  
    container_client.upload_blob(name = 'SSB - %s opprettet %s - %s.csv'%(names[i],ts.month,ts.year),  
                                 data=df.to_csv())  

I want to trigger this using hhtp trigger so I can use this function on Azure Data factory! I am not interested in a response to the trigger, I just want that the trigger starts henting data from an API and deliver that on a blob !

thanks in advance.!

Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
4,679 questions
Azure Data Factory
Azure Data Factory
An Azure service for ingesting, preparing, and transforming data at scale.
10,199 questions
0 comments No comments
{count} votes

Accepted answer
  1. MughundhanRaveendran-MSFT 12,456 Reputation points
    2022-10-16T14:34:17.917+00:00

    Hi @Nuno Trigo ,

    Thanks for reaching out to Q&A.

    Since python functions are dynamically typed, you can use the same code inside the http triggered function template. You can return a simple success response to the ADF pipeline in case the code succeeds without any exceptions.

    Please review the timeout limitation : https://learn.microsoft.com/en-us/azure/data-factory/control-flow-azure-function-activity#timeout-and-long-running-functions

    Hope this helps! Feel free to reach out to me if you have any questions or concerns.


0 additional answers

Sort by: Most helpful