mirror of
https://github.com/serverless/serverless.git
synced 2026-01-18 14:58:43 +00:00
Merge pull request #6518 from serverless/event-bridge-partner-events
Fix support for EventBridge partner event sources
This commit is contained in:
commit
8a82c8a2cf
@ -2,7 +2,7 @@
|
||||
|
||||
function getEventBusName(eventBus) {
|
||||
if (eventBus && eventBus.startsWith('arn')) {
|
||||
return eventBus.split('/').pop();
|
||||
return eventBus.slice(eventBus.indexOf('/') + 1);
|
||||
}
|
||||
return eventBus;
|
||||
}
|
||||
|
||||
@ -119,7 +119,7 @@ class AwsCompileEventBridgeEvents {
|
||||
if (EventBus) {
|
||||
let eventBusName = EventBus;
|
||||
if (EventBus.startsWith('arn')) {
|
||||
eventBusName = EventBus.split('/').pop();
|
||||
eventBusName = EventBus.slice(EventBus.indexOf('/') + 1);
|
||||
}
|
||||
eventBusResource = {
|
||||
'Fn::Join': [
|
||||
|
||||
@ -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',
|
||||
@ -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: {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user