Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
GitHub Copilot for Azure plugin providing Azure service management and development assistance inside Claude Code and IDEs.
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
references/services/functions/lambda-to-functions.md
1# AWS Lambda to Azure Functions Migration23Detailed guidance for migrating AWS Lambda functions to Azure Functions.45## Overview67| AWS Service | Azure Equivalent |8|-------------|------------------|9| Lambda | Azure Functions |10| API Gateway | Azure Functions HTTP Trigger / API Management |11| S3 | Azure Blob Storage |12| S3 Event | Azure Blob Storage + Event Grid |13| DynamoDB | Cosmos DB |14| SQS | Azure Service Bus / Storage Queue |15| SNS | Azure Event Grid |16| EventBridge | Azure Event Grid |17| CloudWatch | Application Insights / Azure Monitor |18| IAM Roles | Managed Identity + Azure RBAC |19| CloudFormation / SAM | Bicep / ARM Templates |20| Rekognition | Azure AI Computer Vision (Image Analysis) |2122## Programming Model Mapping2324| AWS Lambda | Azure Functions |25|------------|-----------------|26| `exports.handler` | `app.http()`, `app.storageBlob()`, etc. (v4) |27| `event` object | `request` / `blob` / trigger-specific param |28| `context` object | `context` (InvocationContext) |29| `callback` | Return value |30| `function.json` (v1-v3) | Inline bindings in code (v4 JS, v2 Python) |3132## Trigger Mapping3334| AWS Trigger | Azure Trigger | Notes |35|-------------|---------------|-------|36| API Gateway (REST/HTTP) | `app.http()` | Direct equivalent |37| S3 Event | `app.storageBlob()` | Use `source: 'EventGrid'` for reliability |38| SQS | `app.storageQueue()` or `app.serviceBusQueue()` | Service Bus for advanced scenarios |39| SNS | `app.eventGrid()` | Event Grid is push-based |40| EventBridge | `app.eventGrid()` | Map event patterns to filters |41| CloudWatch Events (Scheduled) | `app.timer()` | NCRONTAB expressions |42| DynamoDB Streams | Cosmos DB Change Feed trigger | Via `app.cosmosDB()` |4344## Runtime-Specific Migration Patterns4546For language-specific migration rules, correct/incorrect patterns, and code examples, see the runtime reference for the target language:4748| Runtime | Migration Patterns |49|---------|-------------------|50| JavaScript (Node.js v4) | [runtimes/javascript.md — Lambda Migration Rules](runtimes/javascript.md#lambda-migration-rules) |51| Python (v2) | [runtimes/python.md — Lambda Migration Rules](runtimes/python.md#lambda-migration-rules) |52| TypeScript (v4) | [runtimes/typescript.md](runtimes/typescript.md) |53| C# (Isolated Worker) | [runtimes/csharp.md](runtimes/csharp.md) |54| Java | [runtimes/java.md](runtimes/java.md) |55| PowerShell | [runtimes/powershell.md](runtimes/powershell.md) |5657## Project Structure5859```60REQUIRED for Azure Functions:61src/62├── app.js (or function_app.py) # Main entry point63├── host.json # Function host configuration64├── local.settings.json # Local development settings65├── package.json (or requirements.txt)66├── [helper-modules] # Business logic67└── tests/ # Test files6869❌ NEVER create:70├── [functionName]/ # No individual function directories71│ ├── function.json # No function.json (JS v4, Python v2)72│ └── index.js73```7475## Environment Variables7677```78✅ Use managed identity connections for Azure Functions storage:79AzureWebJobsStorage__blobServiceUri80AzureWebJobsStorage__queueServiceUri81AzureWebJobsStorage__tableServiceUri8283✅ Use specific endpoint variables for other services:84COMPUTER_VISION_ENDPOINT85STORAGE_ACCOUNT_URL86SOURCE_CONTAINER_NAME8788❌ Avoid:89CONNECTION_STRING (use managed identity)90API_KEY (use managed identity)91```9293## Reference Links9495- [AWS Lambda vs Azure Functions comparison](https://aka.ms/AWSLambda)96- [AWS to Azure services comparison](https://learn.microsoft.com/en-us/azure/architecture/aws-professional/)97- [Supported language runtimes](https://learn.microsoft.com/en-us/azure/azure-functions/supported-languages)98- [Triggers and bindings overview](https://learn.microsoft.com/en-us/azure/azure-functions/functions-triggers-bindings)99- [Functions quickstart JS (azd)](https://github.com/Azure-Samples/functions-quickstart-javascript-azd/tree/main/infra)100- [Functions quickstart .NET Event Grid (azd)](https://github.com/Azure-Samples/functions-quickstart-dotnet-azd-eventgrid-blob/tree/main/infra)101102## Flex Consumption + Blob Trigger with EventGrid Source103104> **⚠️ CRITICAL**: When deploying blob triggers with `source: 'EventGrid'` on Flex Consumption, there are three infrastructure requirements that are NOT automatically handled and will cause silent trigger failures if missed.105106### 1. Always-Ready Instances (Bootstrap Problem)107108On Flex Consumption, trigger groups only start when there's work to do. But the blob extension needs to be running to create the Event Grid subscription that would deliver work — a chicken-and-egg problem.109110**Solution**: Configure `alwaysReady` for the blob trigger group in the function app's `scaleAndConcurrency`:111112```bicep113// In api.bicep — functionAppConfig section114scaleAndConcurrency: {115alwaysReady: [116{117name: 'blob'118instanceCount: 1119}120]121instanceMemoryMB: 2048122maximumInstanceCount: 100123}124```125126Without this, the trigger group never starts → Event Grid subscription never gets created → no events are delivered → function never triggers.127128### 2. Queue Endpoint Required129130The blob extension internally uses Storage Queues for poison-message tracking when `source: 'EventGrid'` is configured. Without the queue endpoint, the function fails to index with:131132```133Unable to find matching constructor while trying to create an instance of QueueServiceClient.134Expected: serviceUri. Found: credential, clientId, blobServiceUri135```136137**Solution**: Always enable the queue endpoint alongside blob when using EventGrid source:138139```bicep140// In identity-based storage configuration141AzureWebJobsStorage__blobServiceUri: storageAccount.properties.primaryEndpoints.blob142AzureWebJobsStorage__queueServiceUri: storageAccount.properties.primaryEndpoints.queue // REQUIRED for EventGrid source143AzureWebJobsStorage__credential: 'managedidentity'144AzureWebJobsStorage__clientId: managedIdentityClientId145```146147Also assign **Storage Queue Data Contributor** RBAC role to the UAMI.148149### 3. Event Grid Subscription via Bicep (Not CLI)150151Do **NOT** create Event Grid event subscriptions via CLI. The `az eventgrid system-topic event-subscription create` command requires a webhook validation handshake that consistently fails on Flex Consumption with "response code Unknown" (timeout during cold start).152153**Solution**: Deploy the Event Grid system topic and event subscription as Bicep resources. ARM handles the webhook validation internally and reliably:154155```bicep156// eventGrid.bicep157resource systemTopic 'Microsoft.EventGrid/systemTopics@2024-06-01-preview' = {158name: 'evgt-${storageAccountName}'159location: location160properties: {161source: storageAccount.id162topicType: 'Microsoft.Storage.StorageAccounts'163}164}165166resource eventSubscription 'Microsoft.EventGrid/systemTopics/eventSubscriptions@2024-06-01-preview' = {167parent: systemTopic168name: 'blob-trigger-sub'169properties: {170destination: {171endpointType: 'WebHook'172properties: {173// ARM resolves system key and handles validation at deployment time174endpointUrl: 'https://${functionApp.properties.defaultHostName}/runtime/webhooks/blobs?functionName=${functionName}&code=${listKeys('${functionApp.id}/host/default', '2023-12-01').systemKeys.blobs_extension}'175}176}177filter: {178includedEventTypes: [ 'Microsoft.Storage.BlobCreated' ]179subjectBeginsWith: '/blobServices/default/containers/${sourceContainerName}/'180}181}182}183```184185**RBAC requirement**: Assign **EventGrid EventSubscription Contributor** role to the UAMI.186187## User Assigned Managed Identity (UAMI) Auth Patterns188189### DefaultAzureCredential with UAMI190191When using UAMI, `DefaultAzureCredential()` without arguments tries SystemAssigned first and fails. Always pass the client ID:192193```javascript194const { DefaultAzureCredential } = require('@azure/identity');195196const credential = new DefaultAzureCredential({197managedIdentityClientId: process.env.AZURE_CLIENT_ID198});199```200201Add `AZURE_CLIENT_ID` as an app setting pointing to the UAMI client ID:202203```bicep204appSettings: {205AZURE_CLIENT_ID: managedIdentity.outputs.clientId206}207```208209### Identity-Linked Storage Connection210211```bicep212AzureWebJobsStorage__credential: 'managedidentity'213AzureWebJobsStorage__clientId: managedIdentityClientId214AzureWebJobsStorage__blobServiceUri: storageAccount.properties.primaryEndpoints.blob215AzureWebJobsStorage__queueServiceUri: storageAccount.properties.primaryEndpoints.queue216```217218### Required RBAC Roles for Face Blur Pattern219220| Role | Scope | Purpose |221|------|-------|---------|222| Storage Blob Data Owner | Storage Account | Read source blobs, write destination blobs |223| Storage Queue Data Contributor | Storage Account | Poison-message queue for blob extension |224| EventGrid EventSubscription Contributor | Resource Group | Create/manage Event Grid subscriptions |225| Cognitive Services User | Cognitive Services Account | Call Computer Vision API |226| Monitoring Metrics Publisher | Application Insights | Emit telemetry |227228## AWS Rekognition → Azure AI Computer Vision229230| AWS | Azure |231|-----|-------|232| `@aws-sdk/client-rekognition` | `@azure-rest/ai-vision-image-analysis` |233| `DetectFaces` | Image Analysis `People` feature |234| `FaceDetails[].BoundingBox` (relative 0-1) | `peopleResult.values[].boundingBox` (pixel coordinates) |235236> **⚠️ Package version**: `@azure-rest/ai-vision-image-analysis` is still in beta. The `^1.0.0` semver does NOT resolve. Pin explicitly: `"@azure-rest/ai-vision-image-analysis": "1.0.0-beta.3"`237238### Coordinate Conversion239240AWS Rekognition returns relative coordinates (0-1). Azure AI returns pixel coordinates. Convert for consistent face processing:241242```javascript243const sharp = require('sharp');244const metadata = await sharp(imageBuffer).metadata();245246const faces = result.body.peopleResult.values.map(person => ({247BoundingBox: {248Width: person.boundingBox.width / metadata.width,249Height: person.boundingBox.height / metadata.height,250Left: person.boundingBox.x / metadata.width,251Top: person.boundingBox.y / metadata.height252}253}));254```255256### Auth: Use UAMI (No API Keys)257258```bicep259// computerVision.bicep260resource computerVision 'Microsoft.CognitiveServices/accounts@2024-10-01' = {261kind: 'ComputerVision'262properties: {263disableLocalAuth: true // Enterprise policy compliance — no API keys264}265}266```267