Skip to content

Commit 0c3f0da

Browse files
author
Teun Willems
committed
feat: add a failure destination to the Kafka configuration
1 parent 2d70134 commit 0c3f0da

File tree

5 files changed

+47
-0
lines changed

5 files changed

+47
-0
lines changed

lib/plugins/aws/package/compile/events/kafka.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,9 @@ class AwsCompileKafkaEvents {
9494
topic: {
9595
type: 'string',
9696
},
97+
onFailureDestination: {
98+
type: 'string',
99+
},
97100
consumerGroupId: {
98101
type: 'string',
99102
maxLength: 200,
@@ -286,6 +289,15 @@ class AwsCompileKafkaEvents {
286289
};
287290
}
288291

292+
const onFailureDestination = event.kafka.onFailureDestination;
293+
if (onFailureDestination) {
294+
kafkaResource.Properties.DestinationConfig = {
295+
OnFailure: {
296+
Destination: onFailureDestination,
297+
},
298+
};
299+
}
300+
289301
const provisionedPollerConfig = event.kafka.provisionedPollerConfig;
290302
if (provisionedPollerConfig) {
291303
kafkaResource.Properties.ProvisionedPollerConfig = {

lib/plugins/aws/package/compile/events/msk/index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ class AwsCompileMSKEvents {
4444
startingPositionTimestamp: {
4545
type: 'number',
4646
},
47+
onFailureDestination: {
48+
type: 'string',
49+
},
4750
topic: {
4851
type: 'string',
4952
},

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@
113113
"mocha": "^9.2.2",
114114
"mock-require": "^3.0.3",
115115
"ncjsm": "^4.3.2",
116+
"nyc": "^17.1.0",
116117
"pkg": "^5.8.1",
117118
"prettier": "^2.8.8",
118119
"proxyquire": "^2.1.3",

test/unit/lib/plugins/aws/package/compile/events/kafka.test.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -550,6 +550,36 @@ describe('test/unit/lib/plugins/aws/package/compile/events/kafka.test.js', () =>
550550
});
551551
});
552552

553+
describe('onFailureDestination', () => {
554+
it('should correctly compile EventSourceMapping resource properties for onFailureDestination', async () => {
555+
const { awsNaming, cfTemplate } = await runServerless({
556+
fixture: 'function',
557+
configExt: {
558+
functions: {
559+
basic: {
560+
role: { 'Fn::ImportValue': 'MyImportedRole' },
561+
events: [
562+
{
563+
kafka: {
564+
topic,
565+
bootstrapServers: ['abc.xyz:9092'],
566+
accessConfigurations: { saslScram256Auth: saslScram256AuthArn },
567+
onFailureDestination: 'arn:aws:sqs:eu-central-1:000000000000:some-queue'
568+
},
569+
},
570+
],
571+
},
572+
},
573+
},
574+
command: 'package',
575+
});
576+
577+
const eventSourceMappingResource =
578+
cfTemplate.Resources[awsNaming.getKafkaEventLogicalId('basic', 'TestingTopic')];
579+
expect(eventSourceMappingResource.Properties.DestinationConfig.OnFailure.Destination).to.equal('arn:aws:sqs:eu-central-1:000000000000:some-queue');
580+
});
581+
});
582+
553583
describe('startingPositionTimestamp', () => {
554584
it('should fail to compile EventSourceMapping resource properties for startingPosition AT_TIMESTAMP with no startingPositionTimestamp', async () => {
555585
await expect(

types/index.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,7 @@ export interface AWS {
384384
topic: string;
385385
consumerGroupId?: string;
386386
filterPatterns?: FilterPatterns;
387+
onFailureDestination?: string;
387388
};
388389
}
389390
| {

0 commit comments

Comments
 (0)