Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#136 - Fixed issue with eventSourceArn if not a resource reference #180

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 26 additions & 24 deletions lib/stackops/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,31 +32,33 @@ module.exports = function(currentTemplate, aliasStackTemplates, currentAliasStac

// Make sure that the referenced resource is exported by the stageStack.
const resourceRef = utils.findAllReferences(_.get(subscription, 'Properties.EventSourceArn'));
// Build the export name
let resourceRefName = _.get(resourceRef, '[0].ref');
if (_.has(subscription.Properties, 'EventSourceArn.Fn::GetAtt')) {
const attribute = subscription.Properties.EventSourceArn['Fn::GetAtt'][1];
resourceRefName += attribute;
}
// Add the ref output to the stack if not already done.
stageStack.Outputs[resourceRefName] = {
Description: 'Alias resource reference',
Value: subscription.Properties.EventSourceArn,
Export: {
Name: `${stackName}-${resourceRefName}`
}
};
// Add the output to the referenced alias outputs
const aliasOutputs = JSON.parse(aliasStack.Outputs.AliasOutputs.Value);
aliasOutputs.push(resourceRefName);
aliasStack.Outputs.AliasOutputs.Value = JSON.stringify(aliasOutputs);
// Replace the reference with the cross stack reference
subscription.Properties.EventSourceArn = {};
if (resourceRef.length > 0) {
// Build the export name
let resourceRefName = _.get(resourceRef, '[0].ref');
if (_.has(subscription.Properties, 'EventSourceArn.Fn::GetAtt')) {
const attribute = subscription.Properties.EventSourceArn['Fn::GetAtt'][1];
resourceRefName += attribute;
}
// Add the ref output to the stack if not already done.
stageStack.Outputs[resourceRefName] = {
Description: 'Alias resource reference',
Value: subscription.Properties.EventSourceArn,
Export: {
Name: `${stackName}-${resourceRefName}`
}
};
// Add the output to the referenced alias outputs
const aliasOutputs = JSON.parse(aliasStack.Outputs.AliasOutputs.Value);
aliasOutputs.push(resourceRefName);
aliasStack.Outputs.AliasOutputs.Value = JSON.stringify(aliasOutputs);
// Replace the reference with the cross stack reference
subscription.Properties.EventSourceArn = {};

// Event source ARNs can be volatile - e.g. DynamoDB and must not be referenced
// with Fn::ImportValue which does not allow for changes. So we have to register
// them for delayed lookup until the base stack has been updated.
this.addDeferredOutput(`${stackName}-${resourceRefName}`, subscription.Properties, 'EventSourceArn');
// Event source ARNs can be volatile - e.g. DynamoDB and must not be referenced
// with Fn::ImportValue which does not allow for changes. So we have to register
// them for delayed lookup until the base stack has been updated.
this.addDeferredOutput(`${stackName}-${resourceRefName}`, subscription.Properties, 'EventSourceArn');
}

// Remove mapping from stage stack
delete stageStack.Resources[name];
Expand Down