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

Add ability to give EventBridge events custom names #11690

Merged
merged 7 commits into from
Jan 19, 2023
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 16 additions & 0 deletions docs/providers/aws/events/event-bridge.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,22 @@ functions:
key1: value1
```

## Setting a custom name

**Note:** `eventBridge` events by default are named with the lambda function's name with a suffix for the rule position. Set the `name` property within `eventBridge` to change this functionality.

```yml
functions:
myFunction:
handler: index.handler
events:
- eventBridge:
name: event-bridge-custom-name
schedule: rate(10 minutes)
input:
key1: value1
```

## Setting up event pattern matching

```yml
Expand Down
12 changes: 8 additions & 4 deletions lib/plugins/aws/package/compile/events/event-bridge/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ class AwsCompileEventBridgeEvents {
],
},
schedule: { pattern: '^(?:cron|rate)\\(.+\\)$', type: 'string' },
name: { type: 'string', pattern: '[a-zA-Z0-9-_.]+', minLength: 1, maxLength: 64 },
enabled: { type: 'boolean' },
pattern: {
type: 'object',
Expand Down Expand Up @@ -154,14 +155,17 @@ class AwsCompileEventBridgeEvents {
const Pattern = event.eventBridge.pattern;
const Input = event.eventBridge.input;
const InputPath = event.eventBridge.inputPath;
let RuleName = event.eventBridge.name;
let InputTransformer = event.eventBridge.inputTransformer;
let RetryPolicy = event.eventBridge.retryPolicy;
let DeadLetterConfig;

const RuleName = makeAndHashRuleName({
functionName: FunctionName,
index: idx,
});
if (!RuleName) {
RuleName = makeAndHashRuleName({
functionName: FunctionName,
index: idx,
});
}

let State = 'ENABLED';
if (event.eventBridge.enabled === false) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -688,3 +688,42 @@ describe('EventBridgeEvents', () => {
);
});
});

describe('test/unit/lib/plugins/aws/package/compile/events/event-bridge/index.test.js', () => {
describe('regular configuration', () => {
let customNameEventBridgeResource;

before(async () => {
const { awsNaming, cfTemplate } = await runServerless({
fixture: 'function',
command: 'package',
configExt: {
functions: {
customName: {
handler: 'basic.handler',
name: 'custom-name-lambda',
medikoo marked this conversation as resolved.
Show resolved Hide resolved
events: [
{
eventBridge: {
eventBus: 'arn:aws:events:us-east-1:12345:event-bus/default',
schedule: 'rate(10 minutes)',
name: 'custom-event-name-test',
},
},
],
},
},
},
});

const customNameFunctionLogicalId =
awsNaming.getEventBridgeRuleLogicalId('Customnamelambdarule1');
customNameEventBridgeResource = cfTemplate.Resources[customNameFunctionLogicalId];
});

it('should correctly set event name when set', () => {
const customName = 'custom-event-name-test';
expect(customNameEventBridgeResource.Properties.Name).to.eq(customName);
});
});
});