Azure Functions
Azure Functions is a serverless computing platform that runs code in response to events and automatically manages the compute resources required by that code.
Features
Feature Name | Supported | Notes |
---|---|---|
Capture deletes | check | softDelete field in its response. |
History mode | ||
Custom data | check | |
Data blocking | check | |
Column hashing | check | |
Re-sync | check | |
API configurable | check | API configuration |
Priority-first sync | ||
Fivetran data models | ||
Private networking | check | |
Authorization via API | check |
Supported languages
Azure Functions supports the following languages:
- C#
- JavaScript
- F#
- Java *
- PowerShell *
- Python *
- TypeScript *
* Supported in Microsoft's Azure Functions 2.x and later. For more information about supported languages, see Supported languages in Azure Functions.
Function request and response
Fivetran uses HTTP requests for the Azure Functions connector. For more information about how Fivetran syncs data from your cloud function, see our Sync overview documentation.
Request format
Fivetran's request has a standard format. It is a JSON object with following root fields:
agent
is an informational object.state
is a JSON object that contains cursors from the previous successful function execution. It is key to performing incremental updates. A cursor is a bookmark that marks the data Fivetran has already synced, for example, a timestamp, ID, or index. For the initial sync,state
is an empty JSON object {}. Fivetran expects an updatedstate
object in every response.For more information about the
state
object, see How to Use the state Object.secrets
(optional) is a JSON object that contains access keys or API keys for the upstream APIs. Secrets allow you to store information (API tokens or database passwords) that you don’t want to maintain in your code. We use encryption at rest to store the secrets. We pass the secrets into your function every time we call the function. Enter your secrets using a JSON format in the connector setup form.IMPORTANT: For Azure Functions connectors created on or after August 9, 2023, in the connector setup form, click + Add secrets and then specify the key-value pairs. For example, if you want to pass the
secrets
as{'apiKey': 'yourApiKey', 'consumerKey': 'test'}
, add a key-value pair for each entry in the JSON structure. From all the key-value pairs, we construct the JSON object and then pass it to the Azure function. For example, if you add('apiKey', 'yourApiKey'), ('consumerKey': 'test')
as key-value pairs in the setup form, Fivetran passessecrets: {'apiKey': 'yourApiKey', 'consumerKey': 'test'}
to the Azure function.NOTE: For Azure Functions connectors created before August 9, 2023, in the connector setup form, modify your secrets using a JSON format if it is already configured, otherwise use + Add secrets. For more information about the
secrets
object, see How to Use the secrets Object.customPayload
(optional) is a JSON object as a set of key-value pairs that can be used to specify custom information. We pass the custom payloads into your function every time we call the function.setup_test
(optional) is a boolean that lets the function know that Fivetran has invoked the function for the setup tests. The function runs a lightweight job to test the connectivity and returns a JSON object with thehasMore
field set tofalse
.NOTE: We don't add this field to the request during syncs.
sync_id
(optional) is the Fivetran sync identifier (UUID). You can find thesync_id
in your connector's dashboard logs and use it to debug and link function logs with connector logs.IMPORTANT: When the
setup_test
field is set totrue
, we add thesetup-test
value to thesync_id
field in the request. We call the function once with thesync_id
, and if we get an error, we then call the function without thesync_id
.
Example request
{
"agent" : "Fivetran Azure Functions Connector/<external_id>/<schema>",
"state": {
"cursor": "2020-01-01T00:00:00Z"
},
"secrets": {
"apiToken": "abcdefghijklmnopqrstuvwxyz_0123456789"
},
"customPayload": {
"samplePayload": "payload_value"
},
"sync_id": "468b681-c376-4117-bbc0-25d8ae02ace1"
}
In this example,
external_id
is the unique ID tied to your connector. You can find the ID in your connector setup form.schema
is the destination schema name you enter when you first set up your connector.
Response format
The response is a JSON object with following root fields:
state
contains the updated state value(s).insert
specifies the entities and records to be inserted. Fivetran reads the data and infers the data type and the number of columns.delete
(optional) specifies the entities and records to be deleted. Use this field to mark records as deleted. Fivetran doesn't delete the record; instead it marks the record as deleted by setting_fivetran_deleted
column value totrue
. If you specify the delete field, you must also specify the schema field.Fivetran creates the
_fivetran_deleted
column in the destination table, only if your function response has thedelete
field.schema
(optional) specifies primary key columns for each entity. You must be very consistent with the schema field and the primary key columns to avoid any unwanted behavior. If you don’t specify the schema, Fivetran appends the data.hasMore
is an indicator for Fivetran to make a follow-up call for fetching the next set of data. Fivetran keeps making repeated calls until it receiveshasMore = false
.For more information about the
hasMore
field, see How to Use the hasMore Object.softDelete
(optional) specifies the list of entities to be soft deleted. Fivetran marks the records of these entities as deleted by setting the value of the_fivetran_deleted
column totrue
. We recommend that you use this field if you do not want to specify the individual records to be deleted in thedelete
field. If table is specified in bothdelete
andsoftDelete
, delete section will be of no effect.
Example response
{
"state": {
"transaction": "2020-01-02T00:00:00Z",
},
"insert": {
"transaction": [
{"id":1, "amount": 100},
{"id":3, "amount": 50}
],
},
"delete": {
"transaction": [
{"id":2},
],
},
"schema" : {
"transaction": {
"primary_key": ["id"]
},
},
"hasMore" : false,
"softDelete" : ["transaction"]
}
In this example,
state
contains thetransaction
cursor.transaction
is an entity. Fivetran creates theTRANSACTION
table withid
andamount
columns.The function inserts records
1
and3
into theTRANSACTION
table.The function marks record
2
as deleted from theTRANSACTION
table.hasMore
is set tofalse
to indicate that there are no more records.softDelete
marks all the records of theTRANSACTION
table as deleted by setting the value of its_fivetran_deleted
column totrue
.
IMPORTANT: Make sure to add the
"Content-Type"
as"application/json"
in the response header. For more information about adding"Content-Type"
to the response header, see our sample function request.
Custom error handling
Cloud functions may fail due to various reasons, including code execution errors, runtime issues, or internal errors. Add an error handling mechanism in your Azure function response to report an error on your Fivetran dashboard.
Design your Azure function to report an error:
Use the
errorMessage
field in your response to indicate function execution errors. Fivetran creates an Error on the connector dashboard with your custom error message. For example, for the following response, Fivetran creates aThis is an error
Error on your dashboard:{ "errorMessage": "This is an error" }
Use the
errorType
andstackTrace
fields to pass additional information about the error. You must specify theerrorMessage
field to use theerrorType
andstackTrace
fields. For example, for the following response, Fivetran creates an Error alert on your dashboard with the error type and stack trace details:{ "errorMessage": "name 'response' is not defined", "errorType": "NameError", "stackTrace": [ [ "/var/task/azure_function.py", 35, "azure_handler", "response['errorMessage'] = \"This is an error\"" ] ] }
The following sample function demonstrates how you can use custom error handling:
import json
import requests
import azure.functions as func
def main(req: func.HttpRequest) -> func.HttpResponse:
try:
url = "https://api.example.com/resource"
data = {"key1": "value1", "key2": "value2"}
response = requests.get(url, data=data)
response.raise_for_status() # Raise an exception for non-200 status codes
# Process successful response data here
except requests.exceptions.RequestException as e:
response = {}
response["errorMessage"] = "name 'response' is not defined"
response["errorType"] = "NameError"
response["stackTrace"] = "--Stack trace of the error--"
return response
Setup guide
Follow our step-by-step Azure Functions setup guide to connect Azure Functions with your destination using Fivetran connectors.
View function logs
You can access detailed logs about your function and request processing. You can use these logs to track and debug errors:
- Access and analyze function logs in Azure Monitor. For more information, see Monitor executions in Azure Functions.
- Use Fivetran's Azure Monitor log service to connect and stream Fivetran log events.
- Fivetran generates and logs several types of data related to your account and destinations. You can use these logs to monitor your connectors, track your usage, and audit changes. Use the Fivetran Platform Connector to deliver your logs to a schema in your destination.
Frequently asked questions
For more information about cloud functions, see the following: