Skip to content

Commit

Permalink
feat(event-source): ignore cache directories and only process created…
Browse files Browse the repository at this point in the history
… and deleted events
  • Loading branch information
mmalenic committed Oct 29, 2024
1 parent 4a3807f commit b751e5f
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 11 deletions.
3 changes: 3 additions & 0 deletions config/stacks/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,12 @@ const getEventSourceConstructProps = (stage: AppStage): EventSourceProps => {
rules: [
{
bucket: oncoanalyserBucket[stage],
eventTypes: ['Object Created', 'Object Deleted'],
},
{
bucket: icav2PipelineCacheBucket[stage],
eventTypes: ['Object Created', 'Object Deleted'],
key: [{ 'anything-but': { wildcard: 'byob-icav2/*/cache/*' } }],
},
],
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,18 @@ export type EventSourceRule = {
* Bucket to receive events from. If not specified, captures events from all buckets.
*/
bucket?: string;

/**
* The types of events to capture for the bucket. If not specified, captures all events.
* This should be from the list S3 EventBridge events:
* https://docs.aws.amazon.com/AmazonS3/latest/userguide/EventBridge.html
*/
eventTypes?: string[];

/**
* A prefix of the objects that are matched when receiving events from the buckets.
* Rules matching specified keys in buckets.
*/
prefix?: string;
key?: { [key: string]: any }[];
};

/**
Expand All @@ -33,13 +35,15 @@ export type EventSourceProps = {
* The name of the queue to construct.
*/
queueName: string;

/**
* The maximum number of times a message can be unsuccessfully received before
* pushing it to the DLQ.
*/
maxReceiveCount: number;

/**
* A set of EventBridge rules to define..
* A set of EventBridge rules to define.
*/
rules: EventSourceRule[];
};
Expand Down Expand Up @@ -80,13 +84,9 @@ export class EventSourceConstruct extends Construct {
name: [prop.bucket],
},
}),
...(prop.prefix && {
...(prop.key && {
object: {
key: [
{
prefix: prop.prefix,
},
],
key: prop.key,
},
}),
},
Expand Down
7 changes: 5 additions & 2 deletions test/stateful/shared/eventSourceConstruct.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,14 @@ test('Test EventSourceConstruct created props with event types', () => {
});
});

test('Test EventSourceConstruct created props with prefix', () => {
test('Test EventSourceConstruct created props with key rule', () => {
new EventSourceConstruct(stack, 'TestEventSourceConstruct', {
queueName: 'queue',
maxReceiveCount: 100,
rules: [
{
bucket: 'bucket',
prefix: 'prefix',
key: [{ 'anything-but': { wildcard: 'wildcard/*' } }, { prefix: 'prefix' }],
},
],
});
Expand All @@ -94,6 +94,9 @@ test('Test EventSourceConstruct created props with prefix', () => {
detail: {
object: {
key: [
{
'anything-but': { wildcard: 'wildcard/*' },
},
{
prefix: 'prefix',
},
Expand Down

0 comments on commit b751e5f

Please sign in to comment.