Skip to content

Commit

Permalink
Add nodejs8.10 runtime, add isFatal handling
Browse files Browse the repository at this point in the history
Add AWS_EXECUTION_ENV for Go runtime
Update .NET build to SDK 2.1.4
Clean up JS style
  • Loading branch information
mhart committed Apr 3, 2018
1 parent 77a96fe commit 81c9d6c
Show file tree
Hide file tree
Showing 35 changed files with 512 additions and 173 deletions.
34 changes: 14 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ same library versions that exist on AWS Lambda and then deploy using
the [AWS CLI](https://aws.amazon.com/cli/).

This project consists of a set of Docker images for each of the supported Lambda runtimes
(Node.js 0.10, 4.3 and 6.10, Python 2.7 and 3.6, Java 8, .NET Core 2.0, and Go 1.x).
(Node.js 0.10, 4.3, 6.10 and 8.10, Python 2.7 and 3.6, Java 8, .NET Core 2.0, and Go 1.x).

There are also a set of build images that include packages like gcc-c++, git,
zip and the aws-cli for compiling and deploying.
Expand All @@ -34,14 +34,11 @@ You can run your Lambdas from local directories using the `-v` arg with
`docker run` – logging goes to stderr and the callback result goes to stdout:

```sh
# Test an index.handler function from the current directory on Node.js v4.3
docker run --rm -v "$PWD":/var/task lambci/lambda
# Test an index.handler function from the current directory on Node.js v8.10
docker run --rm -v "$PWD":/var/task lambci/lambda:nodejs8.10

# If using a function other than index.handler, with a custom event
docker run --rm -v "$PWD":/var/task lambci/lambda index.myHandler '{"some": "event"}'

# Use the original Node.js v0.10 runtime
docker run --rm -v "$PWD":/var/task lambci/lambda:nodejs
docker run --rm -v "$PWD":/var/task lambci/lambda:nodejs8.10 index.myHandler '{"some": "event"}'

# Use the Node.js v6.10 runtime
docker run --rm -v "$PWD":/var/task lambci/lambda:nodejs6.10
Expand All @@ -66,11 +63,11 @@ docker run --rm -v "$PWD":/var/task lambci/lambda:java8 org.myorg.MyHandler
# a class named Function with a FunctionHandler method, and a custom event
docker run --rm -v "$PWD":/var/task lambci/lambda:dotnetcore2.0 test::test.Function::FunctionHandler '{"some": "event"}'

# Run custom commands on the default container
docker run --rm --entrypoint node lambci/lambda -v
# Run custom commands
docker run --rm --entrypoint node lambci/lambda:nodejs8.10 -v

# For large events you can pipe them into stdin if you set DOCKER_LAMBDA_USE_STDIN (on any runtime)
echo '{"some": "event"}' | docker run --rm -v "$PWD":/var/task -i -e DOCKER_LAMBDA_USE_STDIN=1 lambci/lambda
echo '{"some": "event"}' | docker run --rm -v "$PWD":/var/task -i -e DOCKER_LAMBDA_USE_STDIN=1 lambci/lambda:nodejs8.10
```

You can see more examples of how to build docker images and run different
Expand All @@ -80,10 +77,7 @@ To use the build images, for compilation, deployment, etc:

```sh
# To compile native deps in node_modules (runs `npm rebuild`)
docker run --rm -v "$PWD":/var/task lambci/lambda:build

# To use a different runtime from the default Node.js v4.3
docker run --rm -v "$PWD":/var/task lambci/lambda:build-nodejs6.10
docker run --rm -v "$PWD":/var/task lambci/lambda:build-nodejs8.10

# To resolve dependencies on go1.x (working directory is /go/src/handler, will run `dep ensure`)
docker run --rm -v "$PWD":/go/src/handler lambci/lambda:build-go1.x
Expand All @@ -93,7 +87,7 @@ docker run --rm -v "$PWD":/go/src/handler lambci/lambda:build-go1.x
docker run --rm -v "$PWD":/var/task lambci/lambda:build-dotnetcore2.0 dotnet publish -c Release -o pub

# Run custom commands on a build container
docker run --rm lambci/lambda:build aws --version
docker run --rm lambci/lambda:build-python2.7 aws --version

# To run an interactive session on a build container
docker run -it lambci/lambda:build-python3.6 bash
Expand All @@ -117,7 +111,7 @@ lambdaCallbackResult = dockerLambda({dockerImage: 'lambci/lambda:nodejs6.10'})
Create your own Docker image for finer control:

```dockerfile
FROM lambci/lambda:build
FROM lambci/lambda:build-nodejs8.10

ENV AWS_DEFAULT_REGION us-east-1

Expand Down Expand Up @@ -180,17 +174,17 @@ Documentation
------------

Docker tags (follow the Lambda runtime names):
- `latest` / `nodejs4.3`
- `nodejs`
- `nodejs4.3`
- `nodejs6.10`
- `nodejs8.10`
- `python2.7`
- `python3.6`
- `java8`
- `go1.x`
- `dotnetcore2.0`
- `build` / `build-nodejs4.3`
- `build-nodejs`
- `build-nodejs4.3`
- `build-nodejs6.10`
- `build-nodejs8.10`
- `build-python2.7`
- `build-python3.6`
- `build-java8`
Expand Down
32 changes: 18 additions & 14 deletions base/diff.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash

RUNTIMES="nodejs4.3 nodejs6.10 python2.7 python3.6 java8 go1.x"
RUNTIMES="nodejs4.3 nodejs6.10 nodejs8.10 python2.7 python3.6 java8 go1.x dotnetcore2.0"

rm -rf diff
mkdir -p diff
Expand All @@ -25,24 +25,28 @@ done

docker run --rm --entrypoint find lambci/lambda:nodejs4.3 / | sed 's/^\///' | sort > ./diff/nodejs4.3/fs.docker.txt

# cd diff/nodejs4.3
# diff docker/var/runtime/node_modules/awslambda/index.js lambda/var/runtime/node_modules/awslambda/index.js
# diff -qr docker lambda | grep -v '/var/runtime/node_modules/aws-sdk'
cd diff/nodejs4.3
diff fs.docker.txt fs.lambda.txt | grep -v '^< dev/' | grep -v '^< proc/' | grep -v '^< sys/' | grep -v 'var/runtime/'
diff docker/var/runtime/node_modules/awslambda/index.js lambda/var/runtime/node_modules/awslambda/index.js
diff -qr docker lambda | grep -v '/var/runtime/node_modules/aws-sdk'

cd ../nodejs6.10
diff docker/var/runtime/node_modules/awslambda/index.js lambda/var/runtime/node_modules/awslambda/index.js
diff -qr docker lambda | grep -v '/var/runtime/node_modules/aws-sdk'

cd ../python2.7
diff docker/var/runtime/awslambda/bootstrap.py lambda/var/runtime/awslambda/bootstrap.py
diff -qr docker lambda | grep -v '/var/runtime/boto'

# cd ../python3.6
# diff docker/var/runtime/awslambda/bootstrap.py lambda/var/runtime/awslambda/bootstrap.py
# diff -qr docker lambda | grep -v '/var/runtime/boto' | grep -v __pycache__
cd ../python3.6
diff docker/var/runtime/awslambda/bootstrap.py lambda/var/runtime/awslambda/bootstrap.py
diff -qr docker lambda | grep -v '/var/runtime/boto' | grep -v __pycache__

# cd ../nodejs6.10
# diff docker/var/runtime/node_modules/awslambda/index.js lambda/var/runtime/node_modules/awslambda/index.js
# diff -qr docker lambda | grep -v '/var/runtime/node_modules/aws-sdk'
cd ../java8
diff -qr docker lambda

# cd ../java
# diff -qr docker lambda
cd ../go1.x
diff -qr docker lambda

# cd ../go1.x
# diff -qr docker lambda
cd ../dotnetcore2.0
diff -qr docker lambda
89 changes: 89 additions & 0 deletions base/dump-nodejs810.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
var fs = require('fs')
var childProcess = require('child_process')
var AWS = require('aws-sdk')
var s3 = new AWS.S3()

exports.handler = function(event, context, cb) {
var filename = 'nodejs8.10.tgz'
var cmd = 'tar -cpzf /tmp/' + filename +
' --numeric-owner --ignore-failed-read /var/runtime /var/lang'

var child = childProcess.spawn('sh', ['-c', event.cmd || cmd])
child.stdout.setEncoding('utf8')
child.stderr.setEncoding('utf8')
child.stdout.on('data', console.log.bind(console))
child.stderr.on('data', console.error.bind(console))
child.on('error', cb)

child.on('close', function() {
if (event.cmd) return cb()

console.log('Zipping done! Uploading...')

s3.upload({
Bucket: 'lambci',
Key: 'fs/' + filename,
Body: fs.createReadStream('/tmp/' + filename),
ACL: 'public-read',
}, function(err, data) {
if (err) return cb(err)

console.log('Uploading done!')

console.log(process.execPath)
console.log(process.execArgv)
console.log(process.argv)
console.log(process.cwd())
console.log(__filename)
console.log(process.env)
console.log(context)

cb(null, data)
})
})
}

// /var/lang/bin/node
// [ '--max-old-space-size=1229', '--max-semi-space-size=76', '--max-executable-size=153', '--expose-gc' ]
// [ '/var/lang/bin/node', '/var/runtime/node_modules/awslambda/index.js' ]
// /var/task
// /var/task/index.js
// {
// PATH: '/var/lang/bin:/usr/local/bin:/usr/bin/:/bin',
// LANG: 'en_US.UTF-8',
// LD_LIBRARY_PATH: '/var/lang/lib:/lib64:/usr/lib64:/var/runtime:/var/runtime/lib:/var/task:/var/task/lib',
// LAMBDA_TASK_ROOT: '/var/task',
// LAMBDA_RUNTIME_DIR: '/var/runtime',
// AWS_REGION: 'us-east-1',
// AWS_DEFAULT_REGION: 'us-east-1',
// AWS_LAMBDA_LOG_GROUP_NAME: '/aws/lambda/dump-node810',
// AWS_LAMBDA_LOG_STREAM_NAME: '2017/03/23/[$LATEST]c079a84d433534434534ef0ddc99d00f',
// AWS_LAMBDA_FUNCTION_NAME: 'dump-node810',
// AWS_LAMBDA_FUNCTION_MEMORY_SIZE: '1536',
// AWS_LAMBDA_FUNCTION_VERSION: '$LATEST',
// _AWS_XRAY_DAEMON_ADDRESS: '169.254.79.2',
// _AWS_XRAY_DAEMON_PORT: '2000',
// AWS_XRAY_DAEMON_ADDRESS: '169.254.79.2:2000',
// AWS_XRAY_CONTEXT_MISSING: 'LOG_ERROR',
// _X_AMZN_TRACE_ID: 'Root=1-dc99d00f-c079a84d433534434534ef0d;Parent=91ed514f1e5c03b2;Sampled=0',
// AWS_EXECUTION_ENV: 'AWS_Lambda_nodejs8.10',
// NODE_PATH: '/var/runtime:/var/task:/var/runtime/node_modules',
// AWS_ACCESS_KEY_ID: 'ASIA...C37A',
// AWS_SECRET_ACCESS_KEY: 'JZvD...BDZ4L',
// AWS_SESSION_TOKEN: 'FQoDYXdzEMb//////////...0oog7bzuQU='
// }
// {
// callbackWaitsForEmptyEventLoop: [Getter/Setter],
// done: [Function: done],
// succeed: [Function: succeed],
// fail: [Function: fail],
// logGroupName: '/aws/lambda/dump-node810',
// logStreamName: '2017/03/23/[$LATEST]c079a84d433534434534ef0ddc99d00f',
// functionName: 'dump-node810',
// memoryLimitInMB: '1536',
// functionVersion: '$LATEST',
// getRemainingTimeInMillis: [Function: getRemainingTimeInMillis],
// invokeid: '1fcdc383-a9e8-4228-bc1c-8db17629e183',
// awsRequestId: '1fcdc383-a9e8-4228-bc1c-8db17629e183',
// invokedFunctionArn: 'arn:aws:lambda:us-east-1:879423879432:function:dump-node810'
// }
2 changes: 1 addition & 1 deletion dotnetcore2.0/build/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ FROM lambci/lambda-base:build
ENV PATH=/var/lang/bin:/usr/local/bin:/usr/bin/:/bin \
LD_LIBRARY_PATH=/var/lang/lib:/lib64:/usr/lib64:/var/runtime:/var/runtime/lib:/var/task:/var/task/lib \
AWS_EXECUTION_ENV=AWS_Lambda_dotnetcore2.0 \
DOTNET_SDK_VERSION=2.1.3 \
DOTNET_SDK_VERSION=2.1.4 \
DOTNET_CLI_TELEMETRY_OPTOUT=1 \
NUGET_XMLDOC_MODE=skip

Expand Down
17 changes: 17 additions & 0 deletions dotnetcore2.0/run/MockBootstraps/MockBootstraps.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2017
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MockBootstraps", "MockBootstraps.csproj", "{8AD9356B-231B-4B42-B168-D06497B769AF}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{8AD9356B-231B-4B42-B168-D06497B769AF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{8AD9356B-231B-4B42-B168-D06497B769AF}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8AD9356B-231B-4B42-B168-D06497B769AF}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8AD9356B-231B-4B42-B168-D06497B769AF}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal
2 changes: 1 addition & 1 deletion dotnetcore2.0/run/MockBootstraps/MockLambdaContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace MockLambdaRuntime
{
public class MockLambdaContext
{
static Random random = new Random();
static readonly Random random = new Random();

/// Creates a mock context from a given Lambda handler and event
public MockLambdaContext(string handler, string eventBody)
Expand Down
1 change: 0 additions & 1 deletion dotnetcore2.0/run/MockBootstraps/Program.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using System.Runtime.Loader;
Expand Down
Binary file modified dotnetcore2.0/run/MockBootstraps/lib/Bootstrap.dll
Binary file not shown.
2 changes: 1 addition & 1 deletion examples/docker-file/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM lambci/lambda
FROM lambci/lambda:nodejs8.10

ENV AWS_LAMBDA_FUNCTION_NAME=docker-build \
AWS_LAMBDA_FUNCTION_VERSION=2 \
Expand Down
2 changes: 1 addition & 1 deletion examples/nodejs-native-module/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"version": "1.0.0",
"main": "index.js",
"scripts": {
"build": "docker run --rm -v \"$PWD\":/var/task lambci/lambda:build",
"build": "docker run --rm -v \"$PWD\":/var/task lambci/lambda:build-nodejs4.3",
"test": "node test.js"
},
"dependencies": {
Expand Down
4 changes: 2 additions & 2 deletions examples/nodejs-native-module/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ var dockerLambda = require('../..')

var match = dockerLambda({event: {password: 'lambda-docker'}})

console.log(match == 'Matches!' ? 'Match Passed' : 'Match Failed: ' + match)
console.log(match === 'Matches!' ? 'Match Passed' : 'Match Failed: ' + match)


var nonMatch = dockerLambda({event: {password: 'lambda-mocker'}})

console.log(nonMatch == 'NopeNopeNope' ? 'Non-Match Passed' : 'Non-Match Failed: ' + nonMatch)
console.log(nonMatch === 'NopeNopeNope' ? 'Non-Match Passed' : 'Non-Match Failed: ' + nonMatch)
2 changes: 2 additions & 0 deletions examples/nodejs/index.js → examples/nodejs6.10/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// docker run --rm -v "$PWD":/var/task lambci/lambda:nodejs4.3
// OR
// docker run --rm -v "$PWD":/var/task lambci/lambda:nodejs6.10
// OR
// docker run --rm -v "$PWD":/var/task lambci/lambda:nodejs8.10

exports.handler = function(event, context, cb) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
"version": "1.0.0",
"main": "index.js",
"scripts": {
"test": "docker run --rm -v \"$PWD\":/var/task lambci/lambda:nodejs4.3 index.handler '{\"some\": \"event\"}'"
"test": "docker run --rm -v \"$PWD\":/var/task lambci/lambda:nodejs6.10 index.handler '{\"some\": \"event\"}'"
}
}
26 changes: 26 additions & 0 deletions examples/nodejs8.10/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Just a test lambda, run with:
// docker run --rm -v "$PWD":/var/task lambci/lambda:nodejs8.10

exports.handler = async(event, context) => {
console.log(process.execPath)
console.log(process.execArgv)
console.log(process.argv)
console.log(process.cwd())
console.log(process.mainModule.filename)
console.log(__filename)
console.log(process.env)
console.log(process.getuid())
console.log(process.getgid())
console.log(process.geteuid())
console.log(process.getegid())
console.log(process.getgroups())
console.log(process.umask())

console.log(event)

console.log(context)

context.callbackWaitsForEmptyEventLoop = false

console.log(context.getRemainingTimeInMillis())
}
8 changes: 8 additions & 0 deletions examples/nodejs8.10/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"name": "docker-run",
"version": "1.0.0",
"main": "index.js",
"scripts": {
"test": "docker run --rm -v \"$PWD\":/var/task lambci/lambda:nodejs8.10 index.handler '{\"some\": \"event\"}'"
}
}
3 changes: 2 additions & 1 deletion go1.x/build/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ FROM lambci/lambda-base:build

ENV GOLANG_VERSION=1.10 \
GOPATH=/go \
PATH=/go/bin:/usr/local/go/bin:$PATH
PATH=/go/bin:/usr/local/go/bin:$PATH \
AWS_EXECUTION_ENV=AWS_Lambda_go1.x

WORKDIR /go/src/handler

Expand Down
4 changes: 3 additions & 1 deletion go1.x/run/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
FROM golang:1
WORKDIR /go/src/github.com/lambci/docker-lambda
RUN curl -sSL -o /usr/local/bin/dep https://github.com/golang/dep/releases/download/v0.3.2/dep-linux-amd64 && chmod +x /usr/local/bin/dep
RUN curl -sSL -o /usr/local/bin/dep https://github.com/golang/dep/releases/download/v0.4.1/dep-linux-amd64 && chmod +x /usr/local/bin/dep
COPY aws-lambda-mock.go Gopkg.toml Gopkg.lock ./
RUN dep ensure
RUN GOARCH=amd64 GOOS=linux go build aws-lambda-mock.go


FROM lambci/lambda-base

ENV AWS_EXECUTION_ENV=AWS_Lambda_go1.x

RUN rm -rf /var/runtime /var/lang && \
curl https://lambci.s3.amazonaws.com/fs/go1.x.tgz | tar -zx -C /

Expand Down
6 changes: 3 additions & 3 deletions go1.x/run/Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 81c9d6c

Please sign in to comment.