Skip to content

Commit c73bdfd

Browse files
author
Yves Richard
committed
Update for Node4.3 lamda env
1 parent 84be653 commit c73bdfd

5 files changed

Lines changed: 17 additions & 34 deletions

File tree

deploy.sh

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,12 @@
11
#!/usr/bin/env bash
22

33
# desc: zips up lambda function resources and uploads to aws
4-
# docs: http://docs.aws.amazon.com/cli/latest/reference/lambda/upload-function.html
4+
# docs: http://docs.aws.amazon.com/lambda/latest/dg/API_UpdateFunctionCode.html
55

66
zip -r function.zip package.json node_modules/* lib/* index.js
77

8-
aws lambda upload-function \
9-
--function-name pgexport \
10-
--function-zip function.zip \
11-
--runtime nodejs \
12-
--role arn:aws:iam::674223647607:role/pgexport_lambda_exec_role \
13-
--handler index.handler \
14-
--mode event \
15-
--timeout 60 \
16-
--memory-size 256 \
17-
--region us-east-1
18-
19-
# aws lambda update-function-code \
20-
# --function-name pgexport \
21-
# --zip-file fileb://function.zip
8+
aws lambda update-function-code \
9+
--function-name pgexport \
10+
--zip-file fileb://function.zip
2211

2312
rm function.zip

index.js

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,7 @@
11
'use strict';
2-
var aws = require('aws-sdk');
3-
var pgp = require('pg-promise')();
4-
var admZip = require('adm-zip');
5-
var Q = require('q');
6-
var _ = require('underscore');
72
var PGExport = require('./lib/pg-export');
8-
var RDSIngress = require('./lib/rds-ingress');
93

10-
exports.handler = function (event, context) {
4+
exports.handler = function (event, context, callback) {
115

126
var options = {
137
bucket: 'pgexport-awslambda',
@@ -34,7 +28,7 @@ exports.handler = function (event, context) {
3428
actions[event.action](event)
3529
.then(function (result) {
3630
console.log(event.action + ' succeeded ');
37-
context.done(null, result);
31+
callback(null, result);
3832
})
39-
.fail(context.done);
33+
.fail(callback);
4034
};

lib/pg-export.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,10 @@ PGExport.prototype.exportData = function (queries) {
9898
return self.put({Key: self.root + '/meta.json', Body: JSON.stringify(self.meta), ContentType: 'application/json'});
9999
})
100100
.then(function () {
101-
console.log(fileUrl);
102-
return fileUrl;
101+
console.log('saved archive to: ' + self.key);
102+
return {
103+
key: self.key
104+
};
103105
})
104106
.fail(function (e) {
105107
console.log('error in chain: ', e);

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55
"main": "index.js",
66
"dependencies": {
77
"archiver": "^0.14.4",
8+
"aws-sdk": "^2.18.0",
89
"csv-stringify": "0.0.8",
910
"pg-promise": "^1.0.7",
1011
"q": "^1.3.0",
1112
"request": "^2.55.0",
12-
"underscore": "^1.8.3",
13-
"underscore.string": "^3.0.3"
13+
"underscore": "^1.8.3"
1414
},
1515
"scripts": {
1616
"test": "test.js"

test.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,9 @@ var evt = {
2727
// "key": "yves.richard@tesera.com/reports/66f41e6a-d2e6-4f74-94b9-88d7888ece2d/strata.zip"
2828
// };
2929

30-
var context = {
31-
done: function(err, data) {
32-
if(err) console.log('lambda exited with errors: ', err)
33-
else console.log('lambda exited without errors ', data)
34-
}
30+
var callback = function(err, data) {
31+
if(err) console.log('lambda exited with errors: ', err)
32+
else console.log('lambda exited without errors ', data)
3533
};
3634

37-
lambda.handler(evt, context);
35+
lambda.handler(evt, {}, callback);

0 commit comments

Comments
 (0)