Skip to content

Commit

Permalink
Add nodejs10.x runtime (#26)
Browse files Browse the repository at this point in the history
Add nodejs10.x runtime
  • Loading branch information
styfle authored Jun 20, 2019
2 parents b6796d8 + 0638907 commit ba3aeda
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ implemented are:
* `nodejs` for Node.js Lambda functions using the system `node` binary
* `nodejs6.10` for Node.js Lambda functions using a downloaded Node v6.10.0 binary
* `nodejs8.10` for Node.js Lambda functions using a downloaded Node v8.10.0 binary
* `nodejs10.x` for Node.js Lambda functions using a downloaded Node v10.15.3 binary
* `python` for Python Lambda functions using the system `python` binary
* `python2.7` for Python Lambda functions using a downloaded Python v2.7.12 binary
* `python3.6` for Python Lambda functions using a downloaded Python v3.6.8 binary
Expand Down
2 changes: 2 additions & 0 deletions src/runtimes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { Runtime } from './types';
import * as go1x from './runtimes/go1.x';
import * as nodejs6 from './runtimes/nodejs6.10';
import * as nodejs8 from './runtimes/nodejs8.10';
import * as nodejs10 from './runtimes/nodejs10.x';
import * as python27 from './runtimes/python2.7';
import * as python36 from './runtimes/python3.6';
import * as python37 from './runtimes/python3.7';
Expand Down Expand Up @@ -45,6 +46,7 @@ createRuntime(runtimes, 'go1.x', go1x);
createRuntime(runtimes, 'nodejs');
createRuntime(runtimes, 'nodejs6.10', nodejs6);
createRuntime(runtimes, 'nodejs8.10', nodejs8);
createRuntime(runtimes, 'nodejs10.x', nodejs10);
createRuntime(runtimes, 'python');
createRuntime(runtimes, 'python2.7', python27);
createRuntime(runtimes, 'python3.6', python36);
Expand Down
9 changes: 9 additions & 0 deletions src/runtimes/nodejs10.x/bootstrap
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash
set -euo pipefail

# Ensure the downloaded Node.js version is used
export PATH="$LAMBDA_RUNTIME_DIR/bin:$PATH"

# Execute the "nodejs" runtime bootstrap
export LAMBDA_RUNTIME_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}")"/../nodejs >/dev/null 2>&1 && pwd )"
exec "$LAMBDA_RUNTIME_DIR/bootstrap" "$@"
6 changes: 6 additions & 0 deletions src/runtimes/nodejs10.x/bootstrap.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { join } from 'path';
import { spawn } from 'child_process';

const nodeBin = join(__dirname, 'bin', 'node');
const bootstrap = join(__dirname, '..', 'nodejs', 'bootstrap.js');
spawn(nodeBin, [bootstrap], { stdio: 'inherit' });
10 changes: 10 additions & 0 deletions src/runtimes/nodejs10.x/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { Runtime } from '../../types';
import { installNode } from '../../install-node';
import { runtimes, initializeRuntime } from '../../runtimes';

export async function init({ cacheDir }: Runtime): Promise<void> {
await Promise.all([
initializeRuntime(runtimes.nodejs),
installNode(cacheDir, '10.15.3')
]);
}
2 changes: 1 addition & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export interface LambdaParams {
FunctionName?: string;
Code: { ZipFile?: Buffer | string; Directory?: string };
Handler: string;
Runtime: string; // nodejs | nodejs4.3 | nodejs6.10 | nodejs8.10 | java8 | python2.7 | python3.6 | python3.7 | dotnetcore1.0 | dotnetcore2.0 | dotnetcore2.1 | nodejs4.3-edge | go1.x | ruby2.5 | provided
Runtime: string; // nodejs | nodejs4.3 | nodejs6.10 | nodejs8.10 | nodejs10.x | java8 | python2.7 | python3.6 | python3.7 | dotnetcore1.0 | dotnetcore2.0 | dotnetcore2.1 | nodejs4.3-edge | go1.x | ruby2.5 | provided
Provider?: string; // native | docker
Environment?: { Variables: object };
MemorySize?: number; // The amount of memory that your function has access to. Increasing the function's memory also increases it's CPU allocation. The default value is 128 MB. The value must be a multiple of 64 MB.
Expand Down
16 changes: 16 additions & 0 deletions test/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,22 @@ export const test_nodejs810_exit_in_handler = testInvoke(
}
);

// `nodejs10.x` runtime
export const test_nodejs10_version = testInvoke(
() =>
createFunction({
Code: {
Directory: __dirname + '/functions/nodejs-version'
},
Handler: 'handler.handler',
Runtime: 'nodejs10.x'
}),
async fn => {
const versions = await fn({ hello: 'world' });
assert.equal(versions.node, '10.15.3');
}
);

// `go1.x` runtime
export const test_go1x_echo = testInvoke(
() =>
Expand Down

0 comments on commit ba3aeda

Please sign in to comment.