Skip to content

Commit 0723c2d

Browse files
authored
AWS Lambda Python vs. Node.js performance benchmark (antonputra#96)
1 parent 2354450 commit 0723c2d

14 files changed

+1705
-0
lines changed

Diff for: docs/contents.md

+1
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,4 @@
5757
- [123 - Creating a Linux service with systemd](../lessons/123)
5858
- [124 - AWS Lambda Go vs. Node.js performance benchmark](../lessons/124)
5959
- [125 - How to create EKS Cluster using Terraform MODULES?](../lessons/125)
60+
- [126 - AWS Lambda Python vs. Node.js performance benchmark](../lessons/126)

Diff for: lessons/126/README.md

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# AWS Lambda Python vs. Node.js performance benchmark
2+
3+
You can find tutorial [here](https://antonputra.com/python/python-vs-nodejs-benchmark/).

Diff for: lessons/126/functions/nodejs/function.js

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
const aws = require('aws-sdk');
2+
const s3 = new aws.S3();
3+
const ddb = new aws.DynamoDB({ apiVersion: '2012-08-10' });
4+
5+
// Download the S3 object and print content
6+
const getS3Object = (bucket, key, callback) => {
7+
const params = {
8+
Bucket: bucket,
9+
Key: key
10+
};
11+
12+
s3.getObject(params, (err, data) => {
13+
if (err) return err;
14+
console.log(data);
15+
callback(data.LastModified);
16+
});
17+
};
18+
19+
// Save the item to the DynamoDB table
20+
const save = (table, date, callback) => {
21+
const modifiedDate = date.toISOString()
22+
const params = {
23+
TableName: table,
24+
Item: { 'LastModified': { S: modifiedDate } }
25+
};
26+
27+
ddb.putItem(params, (err, data) => {
28+
if (err) return err;
29+
callback(null, 200);
30+
});
31+
};
32+
33+
// Returns a random number between min and max
34+
const getRandomInt = (min, max) => {
35+
return Math.random() * (max - min) + min;
36+
};
37+
38+
exports.lambda_handler = (event, context, callback) => {
39+
const bucket = process.env.BUCKET_NAME;
40+
const key = 'thumbnail.png';
41+
const table = 'Meta';
42+
43+
getS3Object(bucket, key, (date) => {
44+
const randomNumberOfDays = getRandomInt(0, 100000);
45+
date.setDate(date.getDate() + randomNumberOfDays);
46+
save(table, date, callback);
47+
});
48+
};

0 commit comments

Comments
 (0)