wysknd-aws-cf-generator
Advanced tools
Comparing version 2.7.3 to 2.8.0
@@ -62,5 +62,10 @@ 'use strict'; | ||
*/ | ||
NetworkTemplates: require('./templates/network') | ||
NetworkTemplates: require('./templates/network'), | ||
/** | ||
* Reference to a sub library of cloud watch specific templates. | ||
*/ | ||
CloudWatchTemplates: require('./templates/cloudwatch') | ||
}; | ||
module.exports = index; | ||
module.exports = index; |
@@ -24,2 +24,7 @@ 'use strict'; | ||
/** | ||
* Reference to the request template builder for API gateway methods | ||
*/ | ||
RequestTemplateBuilder: require('./request-template-builder'), | ||
/** | ||
* Reference to the template abstraction for API gateway resources | ||
@@ -26,0 +31,0 @@ */ |
@@ -191,2 +191,4 @@ 'use strict'; | ||
* lambda. | ||
* @param {String} [lambdaFunctionSuffix=undefined] An optional suffix to | ||
* add to the lambda function. | ||
* | ||
@@ -196,9 +198,9 @@ * @return {Object} A reference to the template. Can be used to | ||
*/ | ||
setBackendLambda(lambdaFunction, role) { | ||
setBackendLambda(lambdaFunction, role, lambdaFunctionSuffix) { | ||
if (typeof lambdaFunction !== 'string' || lambdaFunction.length <= 0) { | ||
throw new Error('Invalid lambda function specified (arg #2)'); | ||
throw new Error('Invalid lambda function specified (arg #1)'); | ||
} | ||
role = role || '$REGION_<% lambda_invoke_role %>'; | ||
const integration = this._ensureProperty('Integration'); | ||
integration.Uri = _apiGatewayUtils.getLambdaIntegrationUri(lambdaFunction); | ||
integration.Uri = _apiGatewayUtils.getLambdaIntegrationUri(lambdaFunction, lambdaFunctionSuffix); | ||
integration.Credentials = _iamUtils.getRoleUri(role); | ||
@@ -205,0 +207,0 @@ |
@@ -12,3 +12,3 @@ 'use strict'; | ||
class FunctionTemplate extends Template { | ||
/** | ||
/** | ||
* @param {String} key A key that uniquely identifies the template | ||
@@ -18,16 +18,16 @@ * @param {String} functionName The name of the lambda function | ||
*/ | ||
constructor(key, functionName, handler) { | ||
if (typeof functionName !== 'string' || functionName.length <= 0) { | ||
throw new Error('Invalid functionName specified (arg #2)'); | ||
} | ||
if (typeof handler !== 'string' || handler.length <= 0) { | ||
throw new Error('Invalid handler specified (arg #3)'); | ||
} | ||
const tokens = handler.split('.'); | ||
const handlerName = tokens[tokens.length - 1]; | ||
// TODO: Add support for VPCs | ||
super(key, 'AWS::Lambda::Function', { | ||
FunctionName: functionName, | ||
Code: { | ||
/*esfmt-ignore-start*/ | ||
constructor(key, functionName, handler) { | ||
if (typeof functionName !== 'string' || functionName.length <= 0) { | ||
throw new Error('Invalid functionName specified (arg #2)'); | ||
} | ||
if (typeof handler !== 'string' || handler.length <= 0) { | ||
throw new Error('Invalid handler specified (arg #3)'); | ||
} | ||
const tokens = handler.split('.'); | ||
const handlerName = tokens[tokens.length - 1]; | ||
// TODO: Add support for VPCs | ||
super(key, 'AWS::Lambda::Function', { | ||
FunctionName: functionName, | ||
Code: { | ||
/*esfmt-ignore-start*/ | ||
ZipFile: [ | ||
@@ -39,33 +39,35 @@ `module.exports.${handlerName} = function(event, context, callback) {`, | ||
/*esfmt-ignore-end*/ | ||
}, | ||
Handler: handler, | ||
MemorySize: 128, | ||
Role: _iamUtils.getRoleUri('<% lambda_execute_role %>'), | ||
Description: '', | ||
Runtime: 'nodejs4.3', | ||
Timeout: 3 | ||
}); | ||
} | ||
}, | ||
Handler: handler, | ||
MemorySize: 128, | ||
Role: _iamUtils.getRoleUri('<% lambda_execute_role %>'), | ||
Description: '', | ||
Runtime: 'nodejs4.3', | ||
Timeout: 3 | ||
}); | ||
} | ||
/** | ||
* Sets the runtime of the lambda functions. | ||
* | ||
* @param {String} name of the lambda runtime. It has to be one of the following: 'python2.7', 'nodejs', 'nodejs4.3', 'nodejs6.10', or 'nodejs4.3-edge'. | ||
* | ||
* @return {Object} A reference to the template. Can be used to | ||
* chain multiple calls. | ||
*/ | ||
/** | ||
* Sets the runtime of the lambda functions. | ||
* | ||
* @param {String} name of the lambda runtime. It has to be one of the | ||
* following: 'python2.7', 'nodejs', 'nodejs4.3', 'nodejs6.10', or | ||
* 'nodejs4.3-edge'. | ||
* | ||
* @return {Object} A reference to the template. Can be used to | ||
* chain multiple calls. | ||
*/ | ||
setRuntime(runtime) { | ||
const permittedRuntimes = ['python2.7', 'python3.6', 'nodejs', 'nodejs4.3', 'nodejs6.10', 'nodejs4.3-edge']; | ||
if (permittedRuntimes.indexOf(runtime) === -1) { | ||
throw new Error( | ||
'Invalid runtime (arg #1). Runtime must be one of the following: python2.7, nodejs, nodejs4.3, nodejs6.10, or nodejs4.3-edge' | ||
); | ||
setRuntime(runtime) { | ||
const permittedRuntimes = ['python2.7', 'python3.6', 'nodejs', 'nodejs4.3', 'nodejs6.10', 'nodejs4.3-edge']; | ||
if (permittedRuntimes.indexOf(runtime) === -1) { | ||
throw new Error( | ||
'Invalid runtime (arg #1). Runtime must be one of the following: python2.7, nodejs, nodejs4.3, nodejs6.10, or nodejs4.3-edge' | ||
); | ||
} | ||
this.properties.Runtime = runtime; | ||
return this; | ||
} | ||
this.properties.Runtime = runtime; | ||
return this; | ||
} | ||
/** | ||
/** | ||
* Sets the memory size allocation for the lambda function. The input must | ||
@@ -79,12 +81,12 @@ * be a multiple of 64 that is > 128 and < 1536, | ||
*/ | ||
setMemorySize(memorySize) { | ||
if (typeof memorySize !== 'number' || memorySize < 128 || memorySize > 1536 || memorySize % 64 !== 0) { | ||
throw new Error('Invalid memorySize specified (arg #1). Must be a multiple of 64 between 127 and 1536.'); | ||
setMemorySize(memorySize) { | ||
if (typeof memorySize !== 'number' || memorySize < 128 || memorySize > 1536 || memorySize % 64 !== 0) { | ||
throw new Error('Invalid memorySize specified (arg #1). Must be a multiple of 64 between 127 and 1536.'); | ||
} | ||
this.properties.MemorySize = memorySize; | ||
return this; | ||
} | ||
this.properties.MemorySize = memorySize; | ||
return this; | ||
} | ||
/** | ||
/** | ||
* Sets the timeout duration for the lambdal function. The input must | ||
@@ -98,12 +100,12 @@ * be a positive integer. | ||
*/ | ||
setTimeout(timeout) { | ||
if (typeof timeout !== 'number' || timeout <= 0) { | ||
throw new Error('Invalid timeout specified (arg #1)'); | ||
setTimeout(timeout) { | ||
if (typeof timeout !== 'number' || timeout <= 0) { | ||
throw new Error('Invalid timeout specified (arg #1)'); | ||
} | ||
this.properties.Timeout = timeout; | ||
return this; | ||
} | ||
this.properties.Timeout = timeout; | ||
return this; | ||
} | ||
/** | ||
/** | ||
* Sets the description of the lambda function. | ||
@@ -116,12 +118,12 @@ * | ||
*/ | ||
setDescription(description) { | ||
if (typeof description !== 'string') { | ||
throw new Error('Invalid description specified (arg #1)'); | ||
setDescription(description) { | ||
if (typeof description !== 'string') { | ||
throw new Error('Invalid description specified (arg #1)'); | ||
} | ||
this.properties.Description = description; | ||
return this; | ||
} | ||
this.properties.Description = description; | ||
return this; | ||
} | ||
/** | ||
/** | ||
* Sets inline code for the lambda function. Invoking this method will | ||
@@ -135,13 +137,13 @@ * clear out any s3 file settings that may have been specified. | ||
*/ | ||
setInlineSourceCode(code) { | ||
if (typeof code !== 'string' || code.length <= 0) { | ||
throw new Error('Invalid code specified (arg #1)'); | ||
setInlineSourceCode(code) { | ||
if (typeof code !== 'string' || code.length <= 0) { | ||
throw new Error('Invalid code specified (arg #1)'); | ||
} | ||
this.properties.Code = { | ||
ZipFile: code | ||
}; | ||
return this; | ||
} | ||
this.properties.Code = { | ||
ZipFile: code | ||
}; | ||
return this; | ||
} | ||
/** | ||
/** | ||
* Sets a reference to an S3 file that contains the source code for the | ||
@@ -159,25 +161,25 @@ * lambda function. Invoking this method will clear out any previous zip | ||
*/ | ||
setSourceCode(bucket, key, version) { | ||
if (typeof bucket !== 'string' || bucket.length <= 0) { | ||
throw new Error('Invalid bucket specified (arg #1)'); | ||
} | ||
if (typeof key !== 'string' || key.length <= 0) { | ||
throw new Error('Invalid key specified (arg #2)'); | ||
} | ||
if (version !== undefined && (typeof version !== 'string' || version.length <= 0)) { | ||
throw new Error('Invalid version specified (arg #3)'); | ||
} | ||
setSourceCode(bucket, key, version) { | ||
if (typeof bucket !== 'string' || bucket.length <= 0) { | ||
throw new Error('Invalid bucket specified (arg #1)'); | ||
} | ||
if (typeof key !== 'string' || key.length <= 0) { | ||
throw new Error('Invalid key specified (arg #2)'); | ||
} | ||
if (version !== undefined && (typeof version !== 'string' || version.length <= 0)) { | ||
throw new Error('Invalid version specified (arg #3)'); | ||
} | ||
this.properties.Code = { | ||
S3Bucket: bucket, | ||
S3Key: key | ||
}; | ||
this.properties.Code = { | ||
S3Bucket: bucket, | ||
S3Key: key | ||
}; | ||
if (version) { | ||
this.properties.Code.S3ObjectVersion = version; | ||
if (version) { | ||
this.properties.Code.S3ObjectVersion = version; | ||
} | ||
return this; | ||
} | ||
return this; | ||
} | ||
/** | ||
/** | ||
* Sets the IAM role for lambda execution. | ||
@@ -187,12 +189,12 @@ * | ||
*/ | ||
setRole(role) { | ||
if (typeof role !== 'string' || role.length <= 0) { | ||
throw new Error('Invalid role specified (arg #1)'); | ||
setRole(role) { | ||
if (typeof role !== 'string' || role.length <= 0) { | ||
throw new Error('Invalid role specified (arg #1)'); | ||
} | ||
this.properties.Role = _iamUtils.getRoleUri(role); | ||
return this; | ||
} | ||
this.properties.Role = _iamUtils.getRoleUri(role); | ||
return this; | ||
} | ||
} | ||
module.exports = FunctionTemplate; |
@@ -20,5 +20,10 @@ 'use strict'; | ||
*/ | ||
EventSourceMappingTemplate: require('./event-source-mapping-template') | ||
EventSourceMappingTemplate: require('./event-source-mapping-template'), | ||
/** | ||
* Reference to the template abstraction for a lambda function permissions. | ||
*/ | ||
PermissionTemplate: require('./permission-template'), | ||
}; | ||
module.exports = index; |
@@ -21,3 +21,3 @@ 'use strict'; | ||
} | ||
if (typeof alias !== 'string') { | ||
if (typeof alias !== 'string' || alias.length <= 0) { | ||
alias = ''; | ||
@@ -24,0 +24,0 @@ } else { |
{ | ||
"name": "wysknd-aws-cf-generator", | ||
"version": "2.7.3", | ||
"version": "2.8.0", | ||
"description": "Code driven AWS cloudformation template generator", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
475836
54
7978