AI Skill Report Card
Developing Azure Functions
Azure Function Development
Quick Start
Pythonimport azure.functions as func import logging def main(req: func.HttpRequest) -> func.HttpResponse: logging.info('Python HTTP trigger function processed a request.') name = req.params.get('name') if not name: try: req_body = req.get_json() except ValueError: pass else: name = req_body.get('name') if name: return func.HttpResponse(f"Hello, {name}!") else: return func.HttpResponse( "Please pass a name on the query string or in the request body", status_code=400 )
Recommendation▾
Add concrete input/output examples showing actual HTTP requests and responses, not just code templates
Workflow
Progress:
- Set up function app structure (
func init) - Create function template (
func new) - Configure bindings in function.json
- Implement business logic
- Add error handling and logging
- Configure application settings
- Test locally (
func start) - Deploy to Azure (
func azure functionapp publish) - Monitor and optimize
Project Structure
MyFunctionApp/
├── host.json
├── local.settings.json
├── requirements.txt
├── HttpTrigger/
│ ├── __init__.py
│ └── function.json
└── TimerTrigger/
├── __init__.py
└── function.json
Recommendation▾
Include specific performance metrics and monitoring examples (e.g., 'Function execution time should be <2s')
Examples
Example 1: HTTP Trigger with Cosmos DB Output Input: REST API endpoint that saves user data
JSON{ "bindings": [ { "authLevel": "function", "type": "httpTrigger", "direction": "in", "name": "req", "methods": ["post"] }, { "type": "cosmosDB", "direction": "out", "name": "doc", "databaseName": "Users", "collectionName": "UserData", "connectionStringSetting": "CosmosDBConnection" } ] }
Example 2: Timer Trigger for Data Processing Input: Daily data cleanup job
Python@app.schedule(schedule="0 0 2 * * *", arg_name="myTimer", run_on_startup=False) def cleanup_old_data(myTimer: func.TimerRequest) -> None: logging.info('Cleanup function executed at %s', datetime.utcnow()) # Cleanup logic here
Example 3: Queue Trigger with Service Bus Input: Process messages from Service Bus queue
Python@app.service_bus_queue_trigger(arg_name="msg", queue_name="workitems", connection="ServiceBusConnection") def process_queue_message(msg: func.ServiceBusMessage): logging.info('Processing message: %s', msg.get_body().decode('utf-8'))
Recommendation▾
Provide template configurations for common scenarios like local.settings.json and host.json with actual values
Best Practices
Performance:
- Keep functions stateless and lightweight
- Use async/await for I/O operations
- Implement proper connection pooling
- Set appropriate timeout values
Configuration:
- Use Key Vault references for secrets
- Environment-specific settings in Application Settings
- Connection strings in configuration, not code
Error Handling:
Pythontry: # Function logic pass except Exception as e: logging.error(f"Function failed: {str(e)}") return func.HttpResponse( "Internal server error", status_code=500 )
Monitoring:
- Use Application Insights for telemetry
- Implement custom metrics and logs
- Set up alerts for failures and performance
Common Pitfalls
- Cold starts: Avoid large dependencies; use Premium or Dedicated plans for consistent performance
- Timeout issues: Default timeout is 5 minutes for Consumption plan
- Memory leaks: Don't store state in global variables
- Connection limits: Reuse HTTP clients and database connections
- Large payloads: Use blob storage for files >100MB
- Synchronous blocking: Always use async for external calls
- Missing error handling: Functions should never throw unhandled exceptions
- Hardcoded secrets: Use managed identity and Key Vault integration