Skip to content

Commit 45589b1

Browse files
committed
updated README
1 parent 8abd4bd commit 45589b1

File tree

3 files changed

+47
-24
lines changed

3 files changed

+47
-24
lines changed

README.md

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ This repository contains code and directions to run Haskell executables over [AW
2121
docker run -ti -v $(pwd):/build -w /build --name=haskell-build haskell-centos stack build --allow-different-user
2222
...
2323
CONTAINER_ID=$(docker ps -a | grep haskell-centos | head -1 | cut -d ' ' -f 1)
24-
docker run -t --volumes-from=$CONTAINER_ID busybox dd if=/build/.stack-work/install/x86_64-linux/ghc-7.10.3/7.10.3/bin/main > main
24+
docker run --volumes-from=$CONTAINER_ID busybox dd if=/build/.stack-work/install/x86_64-linux/ghc-7.10.3/7.10.3/bin/main > main
2525
```
2626
2727
* Build zip file containing Javascript wrapper and main app
@@ -33,12 +33,38 @@ This repository contains code and directions to run Haskell executables over [AW
3333
* Create function on Lambda:
3434
3535
```
36-
aws lambda create-function --function-name hello-test --runtime nodejs --zip-file fileb://./aws-lambda.zip --handler run.handle --role arn:aws:iam::259394719635:role/lambda
36+
$ aws lambda create-function --function-name hello-test --runtime nodejs4.3 --zip-file fileb://./aws-lambda.zip --handler run.handle --role arn:aws:iam::259394719635:role/lambda
37+
{
38+
"CodeSha256": "QYKOebaDN/fqEzb1nmaV3ByNDZK3JvD0kWX6YQnPpjE=",
39+
"FunctionName": "hello-test",
40+
"CodeSize": 265356,
41+
"MemorySize": 128,
42+
"FunctionArn": "arn:aws:lambda:eu-west-1:259394719635:function:hello-test",
43+
"Version": "$LATEST",
44+
"Role": "arn:aws:iam::259394719635:role/lambda",
45+
"Timeout": 20,
46+
"LastModified": "2016-05-23T10:32:38.126+0000",
47+
"Handler": "run.handle",
48+
"Runtime": "nodejs4.3",
49+
"Description": ""
50+
}
3751
```
3852
3953
* Run function on Lambda:
4054
55+
```
56+
$ aws lamdba invoke-function --function-name hello-test
57+
{
58+
"StatusCode": 200
59+
}
60+
$ cat test
61+
"child process exited with code 0"
62+
```
4163
64+
The provided `main.hs` simply output its input to its output. There should be an execution trace in the logs hosted on CloudWatch:
65+
66+
![](cloudwatch.png)
67+
4268
## Manifest
4369
4470
* `ghc-centos`: Docker container for building Haskell binaries compatible with [Amazon's Linux AMI](http://docs.aws.amazon.com/lambda/latest/dg/current-supported-versions.html). Does not seem to be a good idea in general as there are quite a few differences between CentOS and Linux AMI.

cloudwatch.png

184 KB
Loading

run.js

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,35 @@
1-
process.env[‘PATH’] = process.env[‘PATH’] + : + process.env[‘LAMBDA_TASK_ROOT’]
2-
31
const spawn = require('child_process').spawn;
4-
const main = spawn('./main');
5-
6-
main.stdout.on('data', (data) => {
7-
console.log(`stdout: ${data}`);
8-
});
9-
10-
main.stderr.on('data', (data) => {
11-
console.log(`stderr: ${data}`);
12-
});
2+
const main = spawn('./main', { stdio: ['pipe', 'pipe', process.stderr] });
133

14-
main.on('error', (err) => {
15-
console.error(`error: ${err}`);
16-
process.exit(1);
4+
main.stdout.on('data', function(data) {
5+
console.log('stdout: ' + data);
176
});
187

19-
main.on('close', (code) => {
20-
console.log(`child process pipes closed with code ${code}`);
21-
});
22-
23-
main.on('exit', (code) => {
24-
console.log(`child process exited with code ${code}`);
25-
process.exit(code);
8+
main.on('close', function(code) {
9+
console.log('child process pipes closed with code '+ code);
2610
});
2711

2812
var ctx;
2913

3014
/**
3115
* handler for AWS Lambda
3216
*/
33-
exports.handle = function(event, context) {
17+
exports.handle = function(event, context, callback) {
18+
process.env['PATH'] = process.env['PATH'] + ':' + process.env['LAMBDA_TASK_ROOT']
3419
ctx = context
20+
21+
console.log("sending data to main:\n" + JSON.stringify(event));
22+
console.log("main pid is " + main.pid);
3523

24+
main.on('exit', function(code){
25+
callback(null, 'child process exited with code ' + code);
26+
});
27+
28+
main.on('error', function(err) {
29+
console.error('error: ' + err);
30+
callback(err, 'child process exited with error: ' + err);
31+
});
32+
3633
main.stdin.write(JSON.stringify({
3734
'event': event,
3835
'context': context

0 commit comments

Comments
 (0)