@mapbox/cloudfriend 8.1.0-dev → 8.1.0-dev.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -61,8 +61,26 @@ class StreamLambda extends Lambda {
61
61
  StartingPosition
62
62
  }
63
63
  };
64
-
65
64
  if (FilterCriteria) {
65
+ if (Object.prototype.toString.call(FilterCriteria) !== '[object Object]'){
66
+ throw new Error('`FilterCriteria` must be a JSON-like object');
67
+ }
68
+ if (!(FilterCriteria.Filters && Array.isArray(FilterCriteria.Filters))){
69
+ throw new Error('`FilterCriteria` must contain property `Filter` of type array');
70
+ }
71
+ if (FilterCriteria.Filters.length > 5){
72
+ throw new Error('`FilterCriteria.Filter` cannot contain more than 5 items, you may request a quota increase with AWS support if required.');
73
+ }
74
+ for (const filter of FilterCriteria.Filters){
75
+ if (!filter.Pattern){
76
+ throw new Error('An object in `FilterCriteria.Filter` was missing the required property `Pattern`');
77
+ }
78
+ try {
79
+ JSON.parse(filter.Pattern);
80
+ } catch (error) {
81
+ throw new Error('An object in `FilterCriteria.Filter` contains a `Pattern` property that is not a JSON parseable string');
82
+ }
83
+ }
66
84
  this.Resources[`${this.LogicalName}EventSource`].Properties.FilterCriteria = FilterCriteria;
67
85
  }
68
86
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mapbox/cloudfriend",
3
- "version": "8.1.0-dev",
3
+ "version": "8.1.0-dev.2",
4
4
  "description": "Helper functions for assembling CloudFormation templates in JavaScript",
5
5
  "main": "index.js",
6
6
  "engines": {
@@ -167,6 +167,13 @@
167
167
  "Properties": {
168
168
  "BatchSize": 10000,
169
169
  "MaximumBatchingWindowInSeconds": 300,
170
+ "FilterCriteria": {
171
+ "Filters": [
172
+ {
173
+ "Pattern": "{\"eventName\":[\"INSERT\",\"MODIFY\"]}"
174
+ }
175
+ ]
176
+ },
170
177
  "Enabled": false,
171
178
  "EventSourceArn": "arn:aws:kinesis:us-east-1:123456789012:stream/fake",
172
179
  "FunctionName": {
@@ -177,4 +184,4 @@
177
184
  }
178
185
  },
179
186
  "Outputs": {}
180
- }
187
+ }
@@ -475,6 +475,13 @@ test('[shortcuts] stream-lambda', (assert) => {
475
475
  S3Key: 'path/to/code.zip'
476
476
  },
477
477
  EventSourceArn: 'arn:aws:kinesis:us-east-1:123456789012:stream/fake',
478
+ FilterCriteria: {
479
+ Filters: [
480
+ {
481
+ Pattern: JSON.stringify({ eventName: ['INSERT', 'MODIFY'] })
482
+ }
483
+ ]
484
+ },
478
485
  BatchSize: 10000,
479
486
  MaximumBatchingWindowInSeconds: 300,
480
487
  Enabled: false,
@@ -492,6 +499,123 @@ test('[shortcuts] stream-lambda', (assert) => {
492
499
  assert.end();
493
500
  });
494
501
 
502
+ test('[shortcuts] StreamLambda FilterCriteria', (assert) => {
503
+ assert.throws(
504
+ () => new cf.shortcuts.StreamLambda({
505
+ LogicalName: 'MyLambda',
506
+ Code: {
507
+ S3Bucket: 'my-code-bucket',
508
+ S3Key: 'path/to/code.zip'
509
+ },
510
+ EventSourceArn: 'arn:aws:kinesis:us-east-1:123456789012:stream/fake',
511
+ FilterCriteria: ['test']
512
+ }),
513
+ '`FilterCriteria` must be a JSON-like object',
514
+ );
515
+ assert.throws(
516
+ () => new cf.shortcuts.StreamLambda({
517
+ LogicalName: 'MyLambda',
518
+ Code: {
519
+ S3Bucket: 'my-code-bucket',
520
+ S3Key: 'path/to/code.zip'
521
+ },
522
+ EventSourceArn: 'arn:aws:kinesis:us-east-1:123456789012:stream/fake',
523
+ FilterCriteria: {}
524
+ }),
525
+ '`FilterCriteria` must contain property `Filter` of type array',
526
+ );
527
+ assert.throws(
528
+ () => new cf.shortcuts.StreamLambda({
529
+ LogicalName: 'MyLambda',
530
+ Code: {
531
+ S3Bucket: 'my-code-bucket',
532
+ S3Key: 'path/to/code.zip'
533
+ },
534
+ EventSourceArn: 'arn:aws:kinesis:us-east-1:123456789012:stream/fake',
535
+ FilterCriteria: {
536
+ Filter: 613
537
+ }
538
+ }),
539
+ '`FilterCriteria` must contain property `Filter` of type array',
540
+ );
541
+ assert.throws(
542
+ () => new cf.shortcuts.StreamLambda({
543
+ LogicalName: 'MyLambda',
544
+ Code: {
545
+ S3Bucket: 'my-code-bucket',
546
+ S3Key: 'path/to/code.zip'
547
+ },
548
+ EventSourceArn: 'arn:aws:kinesis:us-east-1:123456789012:stream/fake',
549
+ FilterCriteria: {
550
+ Filters: [
551
+ {
552
+ Pattern: JSON.stringify({ eventName: ['1'] })
553
+ },
554
+ {
555
+ Pattern: JSON.stringify({ eventName: ['2'] })
556
+ },
557
+ {
558
+ Pattern: JSON.stringify({ eventName: ['3'] })
559
+ },
560
+ {
561
+ Pattern: JSON.stringify({ eventName: ['4'] })
562
+ },
563
+ {
564
+ Pattern: JSON.stringify({ eventName: ['5'] })
565
+ },
566
+ {
567
+ Pattern: JSON.stringify({ eventName: ['6'] })
568
+ }
569
+ ]
570
+ }
571
+ }),
572
+ '`FilterCriteria.Filter` cannot contain more than 5 items, you may request a quota increase with AWS support if required.',
573
+ );
574
+ assert.throws(
575
+ () => new cf.shortcuts.StreamLambda({
576
+ LogicalName: 'MyLambda',
577
+ Code: {
578
+ S3Bucket: 'my-code-bucket',
579
+ S3Key: 'path/to/code.zip'
580
+ },
581
+ EventSourceArn: 'arn:aws:kinesis:us-east-1:123456789012:stream/fake',
582
+ FilterCriteria: {
583
+ Filters: [
584
+ {
585
+ NotPattern: JSON.stringify({ eventName: ['INSERT', 'MODIFY'] })
586
+ },
587
+ {
588
+ Pattern: JSON.stringify({ eventName: ['INSERT', 'MODIFY'] })
589
+ }
590
+ ]
591
+ }
592
+ }),
593
+ 'An object in `FilterCriteria.Filter` was missing the required property `Pattern`',
594
+ );
595
+ assert.throws(
596
+ () => new cf.shortcuts.StreamLambda({
597
+ LogicalName: 'MyLambda',
598
+ Code: {
599
+ S3Bucket: 'my-code-bucket',
600
+ S3Key: 'path/to/code.zip'
601
+ },
602
+ EventSourceArn: 'arn:aws:kinesis:us-east-1:123456789012:stream/fake',
603
+ FilterCriteria: {
604
+ Filters: [
605
+ {
606
+ Pattern: '{"eventName":["INSERT","MODIFY"]}'
607
+ },
608
+ {
609
+ Pattern: { eventName: ['INSERT', 'MODIFY'] }
610
+ }
611
+ ]
612
+ }
613
+ }),
614
+ 'An object in `FilterCriteria.Filter` contains a `Pattern` property that is not a JSON parseable string',
615
+ );
616
+ assert.end();
617
+ });
618
+
495
619
  test('[shortcuts] log-subscription-lambda', (assert) => {
496
620
  assert.throws(
497
621
  () => new cf.shortcuts.LogSubscriptionLambda(),