Skip to content

Commit 80bd154

Browse files
committed
Add Docker images.
1 parent 91680a5 commit 80bd154

17 files changed

+1557
-953
lines changed

.gitignore

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
.DS_Store
2+
13
build
24
dist
3-
node_modules
5+
node_modules
6+
7+
docker/*.js

config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import * as aws from "@pulumi/aws";
22
import * as pulumi from "@pulumi/pulumi";
33

4+
export const account = aws.getCallerIdentity().then(x => x.accountId);
45
export const project = pulumi.getProject();
56
export const region = aws.config.requireRegion().toString();
67
export const stack = pulumi.getStack();

docker.sh

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/bin/bash
2+
3+
NAME=lambda-benchmarks
4+
REGION=us-east-1
5+
STAGE=main
6+
7+
AWS_ACCOUNT_ID=`aws sts get-caller-identity --query "Account" --output text`
8+
9+
ECR=$AWS_ACCOUNT_ID.dkr.ecr.$REGION.amazonaws.com
10+
11+
npx tsc --project ./docker
12+
13+
cd docker
14+
15+
docker build -t $NAME-x64:latest -f Dockerfile.x64 .
16+
docker build -t $NAME-arm64:latest -f Dockerfile.arm64 .
17+
18+
docker tag $NAME-x64:latest $ECR/$NAME-$STAGE-x64:latest
19+
docker tag $NAME-arm64:latest $ECR/$NAME-$STAGE-arm64:latest
20+
21+
cd ..
22+
23+
echo aws configure set default.region $REGION
24+
aws configure set default.region $REGION
25+
26+
aws ecr get-login-password --region $REGION | docker login --username AWS --password-stdin $ECR
27+
28+
docker push $ECR/$NAME-$STAGE-x64:latest
29+
docker push $ECR/$NAME-$STAGE-arm64:latest

docker/Dockerfile.arm64

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
FROM public.ecr.aws/lambda/nodejs:14-arm64
2+
3+
RUN yum -y groupinstall "Development Tools" \
4+
&& yum -y install wget \
5+
&& yum -y install glib2 glib2-devel \
6+
&& yum -y install expat expat-devel
7+
RUN yum -y install libjpeg-devel
8+
RUN wget https://github.com/libvips/libvips/releases/download/v8.11.3/vips-8.11.3.tar.gz \
9+
&& tar xf vips-8.11.3.tar.gz \
10+
&& cd vips-8.11.3 \
11+
&& ./configure \
12+
&& make \
13+
&& make install \
14+
&& echo "/usr/local/lib" > /etc/ld.so.conf.d/usrlocal.conf \
15+
&& /sbin/ldconfig -v \
16+
&& cd .. \
17+
&& rm -rf vips-8.11.3 \
18+
&& rm vips-8.11.3.tar.gz
19+
20+
COPY index.js image.jpeg package.json ${LAMBDA_TASK_ROOT}
21+
22+
RUN npm install --production && npm run init:arm64
23+
24+
CMD [ "index.handler" ]

docker/Dockerfile.x64

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
FROM public.ecr.aws/lambda/nodejs:14-x86_64
2+
3+
RUN yum -y groupinstall "Development Tools" \
4+
&& yum -y install wget \
5+
&& yum -y install glib2 glib2-devel \
6+
&& yum -y install expat expat-devel
7+
RUN yum -y install libjpeg-devel
8+
RUN wget https://github.com/libvips/libvips/releases/download/v8.11.3/vips-8.11.3.tar.gz \
9+
&& tar xf vips-8.11.3.tar.gz \
10+
&& cd vips-8.11.3 \
11+
&& ./configure \
12+
&& make \
13+
&& make install \
14+
&& echo "/usr/local/lib" > /etc/ld.so.conf.d/usrlocal.conf \
15+
&& /sbin/ldconfig -v \
16+
&& cd .. \
17+
&& rm -rf vips-8.11.3 \
18+
&& rm vips-8.11.3.tar.gz
19+
20+
COPY index.js image.jpeg package.json ${LAMBDA_TASK_ROOT}
21+
22+
RUN npm install --production && npm run init:x64
23+
24+
CMD [ "index.handler" ]

docker/image.jpeg

265 KB
Loading

docker/index.ts

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
import axios from 'axios';
2+
import { Handler } from 'aws-lambda';
3+
import * as b from 'benny';
4+
import * as express from 'express';
5+
import * as os from 'os';
6+
import * as sharp from 'sharp';
7+
8+
type Request = {
9+
time?:number;
10+
};
11+
12+
export const handler:Handler<Request> = (event, context, callback) => {
13+
const time = event.time || 10;
14+
15+
const threads = os.cpus().length;
16+
17+
sharp.cache(false);
18+
sharp.concurrency(threads);
19+
20+
const app = express();
21+
22+
app.post('/', (req, res) => {
23+
res.json(req.body);
24+
});
25+
26+
const server = app.listen();
27+
28+
console.log(`Using ${threads} threads`);
29+
30+
const suite = b.suite('Lambda benchmark',
31+
b.add('express', () => {
32+
const runner = async () => {
33+
await axios.post(`http://localhost:${server.address()!['port']}/`, {});
34+
};
35+
36+
return runner;
37+
}, {
38+
maxTime: time,
39+
}),
40+
b.add('sharp', () => {
41+
const runner = async () => {
42+
if (parseInt(context.memoryLimitInMB) < 256) {
43+
return;
44+
}
45+
46+
await sharp('./image.jpeg')
47+
.resize(640, 400)
48+
.jpeg({ quality: 80 })
49+
.toBuffer();
50+
};
51+
52+
return runner;
53+
}, {
54+
maxTime: time,
55+
}),
56+
b.cycle(),
57+
);
58+
59+
suite
60+
.then((s) => {
61+
callback(null, s);
62+
})
63+
.catch((err) => {
64+
callback(err);
65+
})
66+
.finally(() => {
67+
server.close();
68+
});
69+
};

0 commit comments

Comments
 (0)