From a04cdc2cb641622af79ded64f31c53da038ec4dc Mon Sep 17 00:00:00 2001 From: Andy Ballingall Date: Tue, 21 Mar 2017 13:59:11 +0000 Subject: [PATCH 1/2] Added 'runtime' option --- README.md | 27 +++++++++++++++++++++++++-- package.json | 2 +- test/unit/date_facade_test.js | 2 +- test/unit/deploy_task_test.js | 29 ++++++++++++++++++++++++++--- utils/deploy_task.js | 7 ++++++- 5 files changed, 59 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index cec1a5b..c523226 100644 --- a/README.md +++ b/README.md @@ -293,7 +293,7 @@ Default value: None - Required (if you havn't specified an ARN) ##### Proxy On Linux based hosts you can set proxy server for deploy task by specifying standard environment variable - https_proxy. -E.g: +E.g: env https_proxy=http://localhost:8080 grunt deploy ##### package @@ -382,6 +382,12 @@ Default value: `null` Sets the handler for your lambda function. If left null, the current setting will remain unchanged. +##### options.runtime +Type: `String` +Default value: `null` + +Sets the runtime for your lambda function. If left null, the current setting will remain unchanged. + ##### options.enableVersioning Type: `boolean` Default value: `false` @@ -469,6 +475,23 @@ grunt.initConfig({ }); ``` +##### Updating the Node.js runtime from 0.10 to 0.43 +In this example, an existing lambda function is updated to use the new +Node.js 4.3 runtime (replacing the 0.10 runtime which is deprecated). + +```js +grunt.initConfig({ + lambda_deploy: { + default: { + arn: 'arn:aws:lambda:us-east-1:123456781234:function:my-function', + options: { + runtime: "nodejs4.3" + } + } + } +}); +``` + ##### Example with a beta and prod deployment configuration Deploy to beta with `deploy` and to prod with `deploy_prod`: @@ -643,4 +666,4 @@ Adding more warnings for various failure cases * Added support for Node 4.3 runtime callback function - [pull request by bobhigs](https://github.com/Tim-B/grunt-aws-lambda/pull/76) * Added VPC support - [pull request by beeva-arturomartinez](https://github.com/Tim-B/grunt-aws-lambda/pull/71) -* Added local proxy support - [pull request by alekstr](https://github.com/Tim-B/grunt-aws-lambda/pull/66) \ No newline at end of file +* Added local proxy support - [pull request by alekstr](https://github.com/Tim-B/grunt-aws-lambda/pull/66) diff --git a/package.json b/package.json index aa9e517..4db803c 100644 --- a/package.json +++ b/package.json @@ -32,7 +32,7 @@ "mkdirp": "~0.5.0", "rimraf": "~2.2.8", "glob": "~4.3.0", - "aws-sdk": "~2.2.32", + "aws-sdk": "~2.29.0", "proxy-agent": "latest", "npm": "^2.10.0", "q": "^1.4.1" diff --git a/test/unit/date_facade_test.js b/test/unit/date_facade_test.js index 45e710d..a89ddf8 100644 --- a/test/unit/date_facade_test.js +++ b/test/unit/date_facade_test.js @@ -40,7 +40,7 @@ dateFacadeTest.testGetFormattedTimestamp = function(test) { dateFacadeTest.testGetHumanReadableTimestamp = function(test) { var fixedDate = new Date(2016, 2, 13, 14, 38, 13); - test.ok(dateFacade.getHumanReadableTimestamp(fixedDate).indexOf('Sun Mar 13 2016 14:38:13') > -1); + test.ok(dateFacade.getHumanReadableTimestamp(fixedDate).indexOf('3/13/2016, 2:38:13 PM') > -1); test.done(); }; module.exports = dateFacadeTest; diff --git a/test/unit/deploy_task_test.js b/test/unit/deploy_task_test.js index d584f18..75a080b 100644 --- a/test/unit/deploy_task_test.js +++ b/test/unit/deploy_task_test.js @@ -56,7 +56,8 @@ deployTaskTest.setUp = function(done) { Configuration: { timeout: 100, MemorySize: 128, - Handler: 'handler' + Handler: 'handler', + Runtime: 'nodejs4.3' } } }), @@ -82,7 +83,7 @@ deployTaskTest.setUp = function(done) { return lambdaAPIMock; } }; - + proxyAgentMock = sinon.spy(); fsMock.reset(); @@ -91,7 +92,7 @@ deployTaskTest.setUp = function(done) { fsMock.setFileContent('some-package.zip', 'abc123'); mockery.registerMock('aws-sdk', awsSDKMock); - + mockery.registerMock('proxy-agent', proxyAgentMock); var dateFacadeMock = { @@ -387,6 +388,28 @@ deployTaskTest.testHandler = function(test) { gruntMock.execute(deployTask.getHandler, harnessParams); }; +deployTaskTest.testRuntime = function(test) { + test.expect(4); + + var deployTask = require('../../utils/deploy_task'); + + var harnessParams = { + options: { + runtime: 'some-runtime' + }, + config: defaultGruntConfig, + callback: function(harness) { + test.equal(harness.status, true); + test.equal(harness.output.length, 3); + test.equal(harness.output[2], 'Config updated.'); + + test.ok(lambdaAPIMock.updateFunctionConfiguration.calledWithMatch({Runtime: 'some-runtime'})); + test.done(); + } + }; + gruntMock.execute(deployTask.getHandler, harnessParams); +}; + deployTaskTest.testEnableVersioning = function(test) { test.expect(5); diff --git a/utils/deploy_task.js b/utils/deploy_task.js index fd6c675..7ac7338 100644 --- a/utils/deploy_task.js +++ b/utils/deploy_task.js @@ -35,13 +35,14 @@ deployTask.getHandler = function (grunt) { timeout: null, memory: null, handler: null, + runtime: null, enableVersioning: false, aliases: null, enablePackageVersionAlias: false, subnetIds: null, securityGroupIds: null }); - + if (options.profile !== null) { var credentials = new AWS.SharedIniFileCredentials({profile: options.profile}); AWS.config.credentials = credentials; @@ -149,6 +150,10 @@ deployTask.getHandler = function (grunt) { configParams.Handler = options.handler; } + if (options.runtime !== null) { + configParams.Runtime = options.runtime; + } + if (options.subnetIds !== null && options.securityGroupIds !== null) { configParams.VpcConfig = { SubnetIds : options.subnetIds, From 1c413ac9515823b001d8d601e54ff154ffa0ebad Mon Sep 17 00:00:00 2001 From: Andy Ballingall Date: Tue, 21 Mar 2017 14:52:36 +0000 Subject: [PATCH 2/2] CI date fix --- test/unit/date_facade_test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/unit/date_facade_test.js b/test/unit/date_facade_test.js index a89ddf8..45e710d 100644 --- a/test/unit/date_facade_test.js +++ b/test/unit/date_facade_test.js @@ -40,7 +40,7 @@ dateFacadeTest.testGetFormattedTimestamp = function(test) { dateFacadeTest.testGetHumanReadableTimestamp = function(test) { var fixedDate = new Date(2016, 2, 13, 14, 38, 13); - test.ok(dateFacade.getHumanReadableTimestamp(fixedDate).indexOf('3/13/2016, 2:38:13 PM') > -1); + test.ok(dateFacade.getHumanReadableTimestamp(fixedDate).indexOf('Sun Mar 13 2016 14:38:13') > -1); test.done(); }; module.exports = dateFacadeTest;