@@ -70,41 +70,203 @@ The following snippets are examples of common SDK code. The AWS Lambda code maps
70
70
:::column-end:::
71
71
:::row-end:::
72
72
73
- | AWS Lambda code (SDK) | Azure Functions code (Trigger) |
74
- |---|---|
75
- | const AWS = require('aws-sdk'); const s3 = new AWS.S3(); <br><br> exports.handler = async (event) => { const params = { Bucket: 'my-bucket', Key: 'my-object.txt', <br> }; <br> const data = await s3.getObject(params).promise(); console.log('File content:', data.Body.toString()); <br> }; | import { app } from '@azure/functions'; <br><br> app.storageblob('blobTrigger', { <br> path: 'my-container/{blobName}', <br> connection: 'AzureWebJobsStorage', <br> }, async (context, myBlob) => { <br> context.log(` Blob content: ${myBlob.toString()}`); <br> }); |
76
-
77
73
**Writing to Amazon Simple Queue Service (SQS) versus Queue Storage**
78
74
79
- | AWS Lambda code (SDK) | Azure Functions code (Trigger) |
80
- |---|---|
81
- | const AWS = require('aws-sdk'); const sqs = new AWS.SQS(); exports.handler = async (event) => { const params = { QueueUrl : ' https://sqs.amazonaws.com/123456789012/MyQueue' , MessageBody: 'Hello, world!', }; await sqs.sendMessage(params).promise(); }; | import { app } from '@azure/functions'; app.queue('queueTrigger', { queueName: 'myqueue-items', connection: 'AzureWebJobsStorage', }, async (context, queueMessage) => { context.log(`Queue message: ${queueMessage}`); }); |
75
+ :::row:::
76
+ :::column span="":::
77
+
78
+ AWS Lambda code (SDK)
79
+
80
+ ` ` `
81
+ const AWS = require('aws-sdk');
82
+ const sqs = new AWS.SQS();
83
+
84
+ exports.handler = async (event) => {
85
+ const params = {
86
+ QueueUrl :
87
+ ' https://sqs.amazonaws.com/123456789012/MyQueue' ,
88
+ MessageBody : ' Hello, world!' ,
89
+ };
90
+ await
91
+ sqs.sendMessage(params).promise();
92
+ };
93
+ ` ` `
94
+
95
+ :::column-end:::
96
+ :::column span="":::
97
+
98
+ Azure Functions code (Trigger)
99
+
100
+ ` ` `
101
+ import { app } from '@azure/functions';
102
+
103
+ app.queue('queueTrigger', {
104
+ queueName : ' myqueue-items' ,
105
+ connection : ' AzureWebJobsStorage' ,
106
+ }, async (context, queueMessage) => {
107
+ context.log(`Queue message :
108
+ ${queueMessage}`);
109
+ });
110
+ ` ` `
111
+
112
+ :::column-end:::
113
+ :::row-end:::
82
114
83
115
**Writing to DynamoDB versus Azure Cosmos DB**
84
116
85
- | AWS Lambda code (SDK) | Azure Functions code (Trigger) |
86
- |---|---|
87
- | const AWS = require('aws-sdk'); const dynamoDb = new AWS.DynamoDB.DocumentClient(); exports.handler = async (event) => { const params = { TableName : ' my-table' , Key: { id: '123' }, }; const data = await dynamoDb.get(params).promise(); console.log('DynamoDB record:', data.Item); }; | import { app } from '@azure/functions'; app.cosmosDB('cosmosTrigger', { connectionStringSetting: 'CosmosDBConnection', databaseName: 'my-database', containerName: 'my-container', leaseContainerName: 'leases', }, async (context, documents) => { documents.forEach(doc => { context.log(`Cosmos DB document: ${JSON.stringify(doc)}`); }); }); |
117
+ :::row:::
118
+ :::column span="":::
119
+
120
+ AWS Lambda code (SDK)
121
+
122
+ ` ` `
123
+ const AWS = require('aws-sdk');
124
+ const dynamoDb = new AWS.DynamoDB.DocumentClient();
125
+
126
+ exports.handler = async (event) => {
127
+ const params = {
128
+ TableName : ' my-table' ,
129
+ Key : { id: '123' },
130
+ };
131
+ const data = await dynamoDb.get(params).promise();
132
+ console.log('DynamoDB record:', data.Item);
133
+ };
134
+ ` ` `
135
+
136
+ :::column-end:::
137
+ :::column span="":::
138
+
139
+ Azure Functions code (Trigger)
140
+
141
+ ` ` `
142
+ import { app } from '@azure/functions';
143
+
144
+ app.cosmosDB('cosmosTrigger', {
145
+ connectionStringSetting : ' CosmosDBConnection' ,
146
+ databaseName : ' my-database' ,
147
+ containerName : ' my-container' ,
148
+ leaseContainerName : ' leases' ,
149
+ }, async (context, documents) => {
150
+ documents.forEach(doc => {
151
+ context.log(`Cosmos DB document : ${JSON.stringify(doc)}`);
152
+ });
153
+ });
154
+ ` ` `
155
+
156
+ :::column-end:::
157
+ :::row-end:::
88
158
89
159
**Amazon CloudWatch Events versus Azure timer trigger**
90
160
91
- | AWS Lambda code (SDK) | Azure Functions code (Trigger) |
92
- |---|---|
93
- | exports.handler = async (event) => { console.log('Scheduled event:', event); }; | import { app } from '@azure/functions'; app.timer('timerTrigger', { schedule : ' 0 */5 * * * *' , // Runs every 5 minutes }, async (context, myTimer) => { if (myTimer.isPastDue) { context.log('Timer is running late!'); } context.log(Timer function executed at: ${new Date().toISOString()}); }); |
161
+ :::row:::
162
+ :::column span="":::
163
+
164
+ AWS Lambda code (SDK)
165
+
166
+ ` ` `
167
+ exports.handler = async (event) => {
168
+ console.log('Scheduled event:', event);
169
+ };
170
+ ` ` `
171
+
172
+ :::column-end:::
173
+ :::column span="":::
174
+
175
+ Azure Functions code (Trigger)
176
+
177
+ ` ` `
178
+ import { app } from '@azure/functions';
179
+
180
+ app.timer('timerTrigger', { schedule : ' 0 */5 * * * *' , // Runs every 5 minutes }, async (context, myTimer) => { if (myTimer.isPastDue) { context.log('Timer is running late!'); } context.log(Timer function executed at: ${new Date().toISOString()}); });
181
+ ` ` `
182
+
183
+ :::column-end:::
184
+ :::row-end:::
94
185
95
186
**Amazon Simple Notification Service (SNS) versus Azure Event Grid Trigger**
96
187
97
- | AWS Lambda code (SDK) | Azure Functions code (Trigger) |
98
- |---|---|
99
- | const AWS = require('aws-sdk'); const sns = new AWS.SNS(); exports.handler = async (event) => { const params = { Message : ' Hello, Event Grid!' , TopicArn: 'arn:aws:sns:us-east-1:123456789012:MyTopic', }; await sns.publish(params).promise(); }; | import { app } from '@azure/functions'; app.eventGrid('eventGridTrigger', {}, async (context, eventGridEvent) => { context.log(`Event Grid event: ${JSON.stringify(eventGridEvent)}`); }); |
188
+ :::row:::
189
+ :::column span="":::
190
+
191
+ AWS Lambda code (SDK)
192
+
193
+ ` ` `
194
+ const AWS = require('aws-sdk');
195
+ const sns = new AWS.SNS();
196
+
197
+ exports.handler = async (event) => {
198
+ const params = {
199
+ Message : ' Hello, Event Grid!' ,
200
+ TopicArn : ' arn:aws:sns:us-east-1:123456789012:MyTopic' ,
201
+ };
202
+ await sns.publish(params).promise();
203
+ };
204
+ ` ` `
205
+
206
+ :::column-end:::
207
+ :::column span="":::
208
+
209
+ Azure Functions code (Trigger)
210
+
211
+ ` ` `
212
+ import { app } from '@azure/functions';
213
+
214
+ app.eventGrid('eventGridTrigger', {},
215
+ async (context, eventGridEvent) => {
216
+
217
+ context.log(`Event Grid event :
218
+ ${JSON.stringify(eventGridEvent)}`);
219
+
220
+ });
221
+ ` ` `
222
+
223
+ :::column-end:::
224
+ :::row-end:::
100
225
101
226
**Amazon Kinesis vs Azure Event Hubs trigger**
102
227
103
- | AWS Lambda code (SDK) | Azure Functions code (Trigger) |
104
- |---|---|
105
- | const AWS = require('aws-sdk'); const kinesis = new AWS.Kinesis(); exports.handler = async (event) => { const records = event.Records.map(record => Buffer.from(record.kinesis.data, 'base64').toString()); console.log('Kinesis records:', records); }; | import { app } from '@azure/functions'; app.eventHub('eventHubTrigger', { connection : ' EventHubConnection' , eventHubName: 'my-event-hub', }, async (context, eventHubMessages) => { eventHubMessages.forEach(message => { context.log(`Event Hub message: ${message}`); }); }); |
228
+ :::row:::
229
+ :::column span="":::
230
+
231
+ AWS Lambda code (SDK)
232
+
233
+ ` ` `
234
+ const AWS = require('aws-sdk');
235
+ const kinesis = new AWS.Kinesis();
236
+
237
+ exports.handler = async (event) => {
238
+ const records =
239
+ event.Records.map(record =>
240
+ Buffer.from(record.kinesis.data,
241
+ ' base64' ).toString());
242
+ console.log('Kinesis records:', records);
243
+ };
244
+ ` ` `
245
+
246
+ :::column-end:::
247
+ :::column span="":::
248
+
249
+ Azure Functions code (Trigger)
250
+
251
+ ` ` `
252
+ import { app } from '@azure/functions';
253
+ app.eventHub('eventHubTrigger', {
254
+ connection : ' EventHubConnection' ,
255
+ eventHubName : ' my-event-hub' ,
256
+ }, async (context, eventHubMessages) =>
257
+ {
258
+ eventHubMessages.forEach(message =>
259
+ {
260
+ context.log(`Event Hub message :
261
+ ${message}`);
262
+ });
263
+ });
264
+ ` ` `
265
+
266
+ :::column-end:::
267
+ :::row-end:::
106
268
107
- See the following GitHub repositories to compare AWS Lambda code and Azure Functions code.
269
+ See the following GitHub repositories to compare AWS Lambda code and Azure Functions code.
108
270
109
271
- [AWS Lambda code](https://github.com/MadhuraBharadwaj-MSFT/TestLambda)
110
272
0 commit comments