Skip to content

Commit

Permalink
feat(lambda): make node version configurable
Browse files Browse the repository at this point in the history
BREAKING CHANGE: remove support for `nodejs8.10`.
  • Loading branch information
Emanuel Kluge authored and herschel666 committed Jan 7, 2020
1 parent fb26424 commit 4a77c6d
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 13 deletions.
9 changes: 8 additions & 1 deletion packages/lambda/cloudformation.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@ Transform: AWS::Serverless-2016-10-31
Description: Hops Serverless Express Application / Powered by hops-lambda

Parameters:
Runtime:
Type: String
Description: Set the Node version of the Lambda runtime; supported versions are nodejs10.x and nodejs12.x
Default: nodejs12.x
AllowedValues:
- nodejs10.x
- nodejs12.x
LambdaMemorySize:
Type: Number
MinValue: 128
Expand Down Expand Up @@ -130,7 +137,7 @@ Resources:
Handler: node_modules/hops-lambda/lambda.handler
MemorySize: !Ref LambdaMemorySize
Role: !GetAtt LambdaExecutionRole.Arn
Runtime: nodejs8.10
Runtime: !Ref Runtime
Timeout: 30
Events:
KeepWarm:
Expand Down
17 changes: 17 additions & 0 deletions packages/lambda/lib/aws-config.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,25 @@
'use strict';

const { trimSlashes } = require('pathifist');
const semver = require('semver');

const getRuntimeNodeVersion = nodeVersion => {
const { major } = semver.coerce(nodeVersion);

switch (major) {
case 10:
return 'nodejs10.x';
case 12:
return 'nodejs12.x';
default:
throw new Error(`Node version ${nodeVersion} is not supported.`);
}
};

module.exports = function getAWSConfig(hopsConfig) {
const awsConfig = hopsConfig._aws || hopsConfig.aws || {};
const nodeVersion =
hopsConfig.node === 'current' ? process.version : hopsConfig.node;

const region =
awsConfig.region ||
Expand All @@ -14,6 +30,7 @@ module.exports = function getAWSConfig(hopsConfig) {
region,
stackName: awsConfig.uniqueName,
bucketName: awsConfig.uniqueName,
runtime: getRuntimeNodeVersion(nodeVersion),
memorySize: awsConfig.memorySize,
stageName: awsConfig.stageName,
domainName: awsConfig.domainName || '',
Expand Down
1 change: 1 addition & 0 deletions packages/lambda/lib/deploy.js
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ module.exports = function deploy(
var parameters = formatParameters(
Object.assign(
{
Runtime: awsConfig.runtime,
LambdaMemorySize: awsConfig.memorySize,
StageName: awsConfig.stageName,
BasePath: awsConfig.basePath,
Expand Down
22 changes: 10 additions & 12 deletions packages/lambda/mixin.core.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ const { trimSlashes } = require('pathifist');
const semver = require('semver');
const strip = require('strip-indent');

const MAX_NODE_VERSION = '8.10';
const {
engines: { node: nodeVersionRange },
} = require('./package.json');
const getAWSConfig = require('./lib/aws-config');

class LambdaMixin extends Mixin {
Expand Down Expand Up @@ -88,22 +90,18 @@ class LambdaMixin extends Mixin {

diagnose() {
const warnings = [];
const targetNodeVersion =
const { version: targetNodeVersion } = semver.coerce(
!this.config.node || this.config.node === 'current'
? process.version
: this.config.node;
: this.config.node
);

if (
semver.gt(
semver.coerce(targetNodeVersion),
semver.coerce(MAX_NODE_VERSION)
)
) {
if (!semver.intersects(targetNodeVersion, nodeVersionRange)) {
warnings.push(
[
`AWS Lambda only supports Node.js up to version: ${MAX_NODE_VERSION}.`,
'Please specify or use a Node.js version lower than or equal to this',
'version in your Hops config (hops.node) to tell Babel for which version',
`AWS Lambda only supports the Node.js version range "${nodeVersionRange}".`,
'Please specify or use a Node.js version intersecting this range',
'in your Hops config (hops.node) to tell Babel for which version',
'it should transpile for.',
].join('\n')
);
Expand Down

0 comments on commit 4a77c6d

Please sign in to comment.