No longer need functionIdentifier in Handler definition
Realized that we can rely on watching for the final two dashes ('-') in the Lambda function name in order to get the stack name (which may contain dashes itself). Furthermore, if the stack name is long, the resource logical ID will be truncated and this breaks the old logic.
This commit is contained in:
parent
982064fa55
commit
3c9b3a1713
4 changed files with 19 additions and 15 deletions
|
@ -5,8 +5,8 @@ var Promise = require('bluebird'),
|
|||
dynamoDB = Promise.promisifyAll(new AWS.DynamoDB());
|
||||
|
||||
// Exposes the SNS.subscribe API method
|
||||
function PutItems(event, context, functionIdentifier) {
|
||||
base.Handler.call(this, event, context, functionIdentifier);
|
||||
function PutItems(event, context) {
|
||||
base.Handler.call(this, event, context);
|
||||
}
|
||||
PutItems.prototype = Object.create(base.Handler.prototype);
|
||||
PutItems.prototype.handleCreate = function() {
|
||||
|
@ -68,6 +68,6 @@ PutItems.prototype.handleDelete = function(referenceData) {
|
|||
}
|
||||
}
|
||||
exports.putItems = function(event, context) {
|
||||
handler = new PutItems(event, context, "DynamoDBPutItemsFunction");
|
||||
handler = new PutItems(event, context);
|
||||
handler.handle();
|
||||
}
|
||||
|
|
|
@ -5,8 +5,8 @@ var Promise = require('bluebird'),
|
|||
s3 = Promise.promisifyAll(new AWS.S3());
|
||||
|
||||
// Exposes the SNS.subscribe API method
|
||||
function PutObject(event, context, functionIdentifier) {
|
||||
base.Handler.call(this, event, context, functionIdentifier);
|
||||
function PutObject(event, context) {
|
||||
base.Handler.call(this, event, context);
|
||||
}
|
||||
PutObject.prototype = Object.create(base.Handler.prototype);
|
||||
PutObject.prototype.handleCreate = function() {
|
||||
|
@ -44,6 +44,6 @@ PutObject.prototype.handleDelete = function(referenceData) {
|
|||
});
|
||||
}
|
||||
exports.putObject = function(event, context) {
|
||||
handler = new PutObject(event, context, "S3PutObjectFunction");
|
||||
handler = new PutObject(event, context);
|
||||
handler.handle();
|
||||
}
|
||||
|
|
|
@ -5,8 +5,8 @@ var Promise = require('bluebird'),
|
|||
sns = Promise.promisifyAll(new AWS.SNS());
|
||||
|
||||
// Exposes the SNS.subscribe API method
|
||||
function Subscribe(event, context, functionIdentifier) {
|
||||
base.Handler.call(this, event, context, functionIdentifier);
|
||||
function Subscribe(event, context) {
|
||||
base.Handler.call(this, event, context);
|
||||
}
|
||||
Subscribe.prototype = Object.create(base.Handler.prototype);
|
||||
Subscribe.prototype.handleCreate = function() {
|
||||
|
@ -27,6 +27,6 @@ Subscribe.prototype.handleDelete = function(referenceData) {
|
|||
}
|
||||
}
|
||||
exports.subscribe = function(event, context) {
|
||||
handler = new Subscribe(event, context, "SnsSubscribeFunction");
|
||||
handler = new Subscribe(event, context);
|
||||
handler.handle();
|
||||
}
|
||||
|
|
16
lib/base.js
16
lib/base.js
|
@ -6,10 +6,9 @@ var Promise = require('bluebird'),
|
|||
AWS = require('aws-sdk'),
|
||||
dynamoDB = Promise.promisifyAll(new AWS.DynamoDB());
|
||||
|
||||
exports.Handler = function(event, context, functionIdentifier) {
|
||||
exports.Handler = function(event, context) {
|
||||
this.event = event;
|
||||
this.context = context;
|
||||
this.functionIdentifier = functionIdentifier;
|
||||
}
|
||||
|
||||
exports.Handler.prototype.handle = function() {
|
||||
|
@ -75,11 +74,16 @@ exports.Handler.prototype.error = function(message) {
|
|||
}
|
||||
|
||||
exports.Handler.prototype.getStackName = function() {
|
||||
var i = this.context.functionName.indexOf("-" + this.functionIdentifier);
|
||||
if (this.functionIdentifier && i >= 0)
|
||||
return this.context.functionName.substr(0, i);
|
||||
var functionName = this.context.functionName;
|
||||
// Assume functionName is: stackName-resourceLogicalId-randomString.
|
||||
// Per http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/resources-section-structure.html,
|
||||
// resourceLogicalId cannot include a '-'; randomString seems to also be alphanumeric.
|
||||
// Thus it seems safe to search for the two dashes in order to find the stackName.
|
||||
var i = functionName.lastIndexOf("-", functionName.lastIndexOf("-") - 1);
|
||||
if (i >= 0)
|
||||
return functionName.substr(0, i);
|
||||
else
|
||||
return this.context.functionName;
|
||||
return functionName;
|
||||
}
|
||||
|
||||
exports.Handler.prototype.getReferenceData = function() {
|
||||
|
|
Loading…
Add table
Reference in a new issue