Skip to content

Commit

Permalink
Fix support for EventBridge partner event sources
Browse files Browse the repository at this point in the history
  • Loading branch information
pmuens committed Aug 9, 2019
1 parent 4943e60 commit 26cc941
Show file tree
Hide file tree
Showing 3 changed files with 134 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

function getEventBusName(eventBus) {
if (eventBus && eventBus.startsWith('arn')) {
return eventBus.split('/').pop();
const separatorIndex = eventBus.indexOf('/');
return separatorIndex === -1 ? eventBus : eventBus.slice(separatorIndex + 1);
}
return eventBus;
}
Expand Down
4 changes: 3 additions & 1 deletion lib/plugins/aws/package/compile/events/eventBridge/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,9 @@ class AwsCompileEventBridgeEvents {
if (EventBus) {
let eventBusName = EventBus;
if (EventBus.startsWith('arn')) {
eventBusName = EventBus.split('/').pop();
const separatorIndex = EventBus.indexOf('/');
eventBusName =
separatorIndex === -1 ? EventBus : EventBus.slice(separatorIndex + 1);
}
eventBusResource = {
'Fn::Join': [
Expand Down
130 changes: 129 additions & 1 deletion lib/plugins/aws/package/compile/events/eventBridge/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ describe('AwsCompileEventBridgeEvents', () => {
);
});

it('should create the necessary resources when using an event bus arn', () => {
it('should create the necessary resources when using an own event bus arn', () => {
awsCompileEventBridgeEvents.serverless.service.functions = {
first: {
name: 'first',
Expand Down Expand Up @@ -485,6 +485,134 @@ describe('AwsCompileEventBridgeEvents', () => {
);
});

it('should create the necessary resources when using a partner event bus arn', () => {
awsCompileEventBridgeEvents.serverless.service.functions = {
first: {
name: 'first',
events: [
{
eventBridge: {
eventBus: 'arn:aws:events:us-east-1:12345:event-bus/aws.partner/partner.com/12345',
pattern: {
source: ['aws.partner/partner.com/12345'],
detail: {
event: ['My Event'],
type: ['track'],
},
},
},
},
],
},
};

return expect(awsCompileEventBridgeEvents.compileEventBridgeEvents()).to.be.fulfilled.then(
() => {
const {
Resources,
} = awsCompileEventBridgeEvents.serverless.service.provider.compiledCloudFormationTemplate;

expect(addCustomResourceToServiceStub).to.have.been.calledOnce;
expect(addCustomResourceToServiceStub.args[0][1]).to.equal('eventBridge');
expect(addCustomResourceToServiceStub.args[0][2]).to.deep.equal([
{
Action: ['events:CreateEventBus', 'events:DeleteEventBus'],
Effect: 'Allow',
Resource: {
'Fn::Join': [
':',
[
'arn:aws:events',
{
Ref: 'AWS::Region',
},
{
Ref: 'AWS::AccountId',
},
'event-bus/aws.partner/partner.com/12345',
],
],
},
},
{
Action: [
'events:PutRule',
'events:RemoveTargets',
'events:PutTargets',
'events:DeleteRule',
],
Effect: 'Allow',
Resource: {
'Fn::Join': [
':',
[
'arn:aws:events',
{
Ref: 'AWS::Region',
},
{
Ref: 'AWS::AccountId',
},
'rule/aws.partner/partner.com/12345/first-rule-1',
],
],
},
},
{
Action: ['lambda:AddPermission', 'lambda:RemovePermission'],
Effect: 'Allow',
Resource: {
'Fn::Join': [
':',
[
'arn:aws:lambda',
{
Ref: 'AWS::Region',
},
{
Ref: 'AWS::AccountId',
},
'function',
'first',
],
],
},
},
]);
expect(Resources.FirstCustomEventBridge1).to.deep.equal({
Type: 'Custom::EventBridge',
Version: 1,
DependsOn: [
'FirstLambdaFunction',
'CustomDashresourceDasheventDashbridgeLambdaFunction',
],
Properties: {
ServiceToken: {
'Fn::GetAtt': ['CustomDashresourceDasheventDashbridgeLambdaFunction', 'Arn'],
},
FunctionName: 'first',
EventBridgeConfig: {
EventBus: 'arn:aws:events:us-east-1:12345:event-bus/aws.partner/partner.com/12345',
Input: undefined,
InputPath: undefined,
InputTransformer: undefined,
Pattern: {
detail: {
event: ['My Event'],
type: ['track'],
},

source: ['aws.partner/partner.com/12345'],
},
Schedule: undefined,
RuleName: 'first-rule-1',
},
},
});
}
);
});

it('should create the necessary resources when using an input configuration', () => {
awsCompileEventBridgeEvents.serverless.service.functions = {
first: {
Expand Down

0 comments on commit 26cc941

Please sign in to comment.