Azure Logic Apps and Azure Functions are powerful tools for creating workflows and serverless applications. Here's an overview and sample code for both:
Azure Logic Apps is a cloud-based platform for automating workflows and integrating apps, data, and services.
- Automating workflows (e.g., file processing, approvals).
- Integration with SaaS applications (e.g., Office 365, Salesforce).
- Data transformation and ETL processes.
- Go to the Azure Portal.
- Create a new Logic App.
- Use the designer to build workflows with pre-built connectors and triggers.
Below is an example of a Logic App JSON template that triggers when an HTTP request is received and sends an email using Office 365.
{
"definition": {
"$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
"actions": {
"Send_an_email": {
"inputs": {
"body": {
"To": "recipient@example.com",
"Subject": "Hello from Logic Apps",
"Body": "This is a test email sent by a Logic App."
},
"host": {
"connection": {
"name": "@parameters('$connections')['office365']['connectionId']"
}
},
"method": "post",
"path": "/v2/Mail/Send"
},
"runAfter": {},
"type": "ApiConnection"
}
},
"triggers": {
"manual": {
"inputs": {},
"metadata": {},
"type": "Request"
}
}
},
"parameters": {
"$connections": {
"defaultValue": {},
"type": "Object"
}
}
}
Deploy using the Azure CLI:
az deployment group create \
--resource-group <resource-group-name> \
--template-file logicapp.json
Azure Functions is a serverless compute service that lets you run code on demand.
- Event-driven applications.
- Data processing and transformation.
- Backend services for APIs and mobile apps.
Azure Functions support multiple languages like C#, Python, JavaScript, etc.
module.exports = async function (context, req) {
context.log('HTTP trigger function processed a request.');
const name = req.query.name || (req.body && req.body.name);
if (name) {
context.res = {
body: `Hello, ${name}!`
};
} else {
context.res = {
status: 400,
body: "Please pass a name on the query string or in the request body"
};
}
};
import logging
def main(myblob: bytes):
logging.info(f"Blob trigger function processed blob of size: {len(myblob)} bytes")
-
Create a Function App:
- In Azure Portal, create a Function App.
- Choose your runtime stack (e.g., Node.js, Python, etc.).
-
Develop Locally: Use Azure Functions Core Tools:
func init myFunctionApp --javascript cd myFunctionApp func new --template "HTTP trigger" --name HttpTrigger
-
Deploy to Azure:
func azure functionapp publish <function-app-name>
Azure Logic Apps can call Azure Functions to extend workflows.
- Logic App Trigger: HTTP Request.
- Action: Call Azure Function to process data.
- Action: Store processed data in a database.
{
"definition": {
"triggers": {
"manual": {
"inputs": {},
"metadata": {},
"type": "Request"
}
},
"actions": {
"Call_Function": {
"inputs": {
"body": {
"name": "@triggerBody()?['name']"
},
"method": "post",
"uri": "https://<your-function-app>.azurewebsites.net/api/HttpTrigger"
},
"runAfter": {},
"type": "Http"
}
}
}
}
- Use Connectors to simplify integrations.
- Leverage Error Handling: Add retries and run-after conditions.
- Split complex workflows into Child Logic Apps.
- Optimize cold start performance using Premium Plan or Always On.
- Use App Insights for monitoring.
- Secure HTTP-triggered functions with API Keys or Azure AD.
Let me know if you need deeper examples or more detailed walkthroughs!