@mapbox/cloudfriend 8.1.0 → 8.3.0-1

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.
Files changed (28) hide show
  1. package/.github/workflows/test.yml +33 -0
  2. package/.nyc_output/cf1b942d-c570-4151-b3cf-60d4790a8b7d.json +1 -0
  3. package/.nyc_output/d0b51d11-b445-4c4c-ac71-72c66d87f527.json +1 -0
  4. package/.nyc_output/processinfo/{d9683579-e4df-4a8c-916b-585093031713.json → cf1b942d-c570-4151-b3cf-60d4790a8b7d.json} +1 -1
  5. package/.nyc_output/processinfo/{c5b5c951-37d5-4058-a3e4-939c91352f33.json → d0b51d11-b445-4c4c-ac71-72c66d87f527.json} +1 -1
  6. package/.nyc_output/processinfo/index.json +1 -1
  7. package/CODEOWNERS +1 -1
  8. package/changelog.md +16 -2
  9. package/lib/intrinsic.js +8 -2
  10. package/lib/shortcuts/api.md +1 -0
  11. package/lib/shortcuts/lambda.js +4 -2
  12. package/package.json +2 -1
  13. package/test/fixtures/shortcuts/hookshot-github-secret-ref.json +2 -2
  14. package/test/fixtures/shortcuts/hookshot-github-secret-string.json +2 -2
  15. package/test/fixtures/shortcuts/hookshot-github.json +2 -2
  16. package/test/fixtures/shortcuts/hookshot-passthrough-access-log-format.json +2 -2
  17. package/test/fixtures/shortcuts/hookshot-passthrough-alarms.json +2 -2
  18. package/test/fixtures/shortcuts/hookshot-passthrough-enhanced-logging.json +2 -2
  19. package/test/fixtures/shortcuts/hookshot-passthrough-full-blown-logging.json +2 -2
  20. package/test/fixtures/shortcuts/hookshot-passthrough-logging.json +2 -2
  21. package/test/fixtures/shortcuts/hookshot-passthrough.json +2 -2
  22. package/test/fixtures/shortcuts/lambda-full.json +1 -1
  23. package/test/fixtures/shortcuts/stream-lambda-no-defaults.json +8 -8
  24. package/test/index.test.js +1 -0
  25. package/test/shortcuts.test.js +2 -1
  26. package/.nyc_output/c5b5c951-37d5-4058-a3e4-939c91352f33.json +0 -1
  27. package/.nyc_output/d9683579-e4df-4a8c-916b-585093031713.json +0 -1
  28. package/.travis.yml +0 -10
package/changelog.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # Changelog
2
2
 
3
+ ## 8.3.0
4
+
5
+ - Support a default value for cf.findInMap (Fn::FindInMap).
6
+
7
+ ## 8.2.0
8
+
9
+ - Add `LogRetentionInDays` option to Lambda shortcuts
10
+
3
11
  ## 8.1.0
4
12
 
5
13
  - Allow `FilterCriteria` property to be defined for Stream Lambda shortcuts
@@ -25,7 +33,7 @@ When you make this update, you will no longer see a trigger on your scheduled la
25
33
  ## 7.1.0
26
34
 
27
35
  - Add support for `Fn::ForEach`. With `Fn::ForEach`, you can replicate parts of your templates with minimal lines of code, as per the [official AWS announcement](https://aws.amazon.com/about-aws/whats-new/2023/07/accelerate-cloudformation-authoring-experience-looping-function/) and [the documentation](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference-foreach.html).
28
-
36
+
29
37
  ## v7.0.1
30
38
 
31
39
  - Fixes `hookshot.Passthrough` and `hookshot.Github` shortcuts where inline code lambdas were using AWS SDK v2 while the lambda default runtime is `nodejs18.x`, by switching to AWS SDK v3.
@@ -47,23 +55,29 @@ When you make this update, you will no longer see a trigger on your scheduled la
47
55
  - Dependency updates to avoid security vulnerabilities (minimist).
48
56
 
49
57
  ## v5.1.0
58
+
50
59
  - Lambda shortcuts now support custom Docker images.
51
60
 
52
61
  ## v5.0.2
62
+
53
63
  - Fixes handling custom access log formats in hookshot shortcuts.
54
64
 
55
65
  ## v5.0.1
66
+
56
67
  - Improves data type mappings between Glue and Presto when using the `GluePrestoView` shortcut.
57
68
 
58
69
  ## v5.0.0
70
+
59
71
  - The Lambda shortcuts now use `nodejs12.x` as the default runtime.
60
72
  - There is no longer any constraint on the useable Lambda runtimes.
61
73
 
62
74
  ## v4.6.0
75
+
63
76
  - Adds top-level `Rules` section support to `cf.merge`. Each key in `Rules` must have a unique name.
64
77
  - Adds rule-specific intrinsic functions: `contains`, `eachMemberEquals`, `eachMemberIn`, `refAll`, `valueOf`, `valueOfAll`
65
78
 
66
79
  ## v4.5.1
80
+
67
81
  - Fixes a bug present in v4.4.0 and v4.5.0 where Lambda shortcuts' Conditions were not passed to the generated IAM Roles.
68
82
 
69
83
  ## v4.5.0
@@ -174,7 +188,7 @@ When you make this update, you will no longer see a trigger on your scheduled la
174
188
  ## v2.8.0
175
189
 
176
190
  - Allows Hookshot callers to bring their own webhook secret. This is used for
177
- signature-verification in the `.Github()` case.
191
+ signature-verification in the `.Github()` case.
178
192
 
179
193
  ## v2.7.0
180
194
 
package/lib/intrinsic.js CHANGED
@@ -48,10 +48,16 @@ intrinsic.cidr = (ipBlock, count, cidrBits) => {
48
48
  * key-value pairs.
49
49
  * @param {string} attr - The second-level key name, which is set to one of the
50
50
  * keys from the list assigned to key.
51
+ * @param {string} defaultValue - The value that will resolve to if the key and/or attr can not be found from the mapping map.
52
+ * This field is optional and requires AWS::LanguageExtensions to be defined in the template.
51
53
  * @returns The value that is assigned to SecondLevelKey.
52
54
  */
53
- intrinsic.findInMap = (mapping, key, attr) => {
54
- return { 'Fn::FindInMap': [mapping, key, attr] };
55
+ intrinsic.findInMap = (mapping, key, attr, defaultValue) => {
56
+ const lookup = [mapping, key, attr];
57
+ if (defaultValue) {
58
+ lookup.push({ DefaultValue: defaultValue });
59
+ }
60
+ return { 'Fn::FindInMap': lookup };
55
61
  };
56
62
 
57
63
  /**
@@ -422,6 +422,7 @@ Log Group, a Role, an Alarm on function errors, and the Lambda Function itself.
422
422
  | [options.EvaluateLowSampleCountPercentile] | <code>String</code> | | See [AWS documentation](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-cw-alarm.html#cfn-cloudwatch-alarms-evaluatelowsamplecountpercentile). |
423
423
  | [options.ExtendedStatistic] | <code>String</code> | | See [AWS documentation](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-cw-alarm.html#cfn-cloudwatch-alarms-extendedstatistic)] |
424
424
  | [options.OKActions] | <code>Array.&lt;String&gt;</code> | | See [AWS documentation](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-cw-alarm.html#cfn-cloudwatch-alarms-okactions). |
425
+ | [options.LogRetentionInDays] | <code>Number</code> | <code>14</code> | How long to retain CloudWatch logs for this Lambda function. See [AWS Documentation](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-logs-loggroup.html) for allowed values. |
425
426
 
426
427
  **Example**
427
428
  ```js
@@ -46,6 +46,7 @@ const ServiceRole = require('./service-role');
46
46
  * @param {String} [options.EvaluateLowSampleCountPercentile=undefined] - See [AWS documentation](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-cw-alarm.html#cfn-cloudwatch-alarms-evaluatelowsamplecountpercentile).
47
47
  * @param {String} [options.ExtendedStatistic=undefined] - See [AWS documentation](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-cw-alarm.html#cfn-cloudwatch-alarms-extendedstatistic)]
48
48
  * @param {Array<String>} [options.OKActions=undefined] - See [AWS documentation](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-cw-alarm.html#cfn-cloudwatch-alarms-okactions).
49
+ * @param {Number} [options.LogRetentionInDays=14] - How long to retain CloudWatch logs for this Lambda function. See [AWS Documentation](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-logs-loggroup.html) for allowed values.
49
50
  *
50
51
  * @example
51
52
  * const cf = require('@mapbox/cloudfriend');
@@ -104,7 +105,8 @@ class Lambda {
104
105
  TreatMissingData = 'notBreaching',
105
106
  EvaluateLowSampleCountPercentile,
106
107
  ExtendedStatistic,
107
- OKActions
108
+ OKActions,
109
+ LogRetentionInDays = 14
108
110
  } = options;
109
111
 
110
112
  if (options.EvaluationPeriods < Math.ceil(Timeout / Period))
@@ -138,7 +140,7 @@ class Lambda {
138
140
  LogGroupName: {
139
141
  'Fn::Sub': ['/aws/lambda/${name}', { name: FunctionName }]
140
142
  },
141
- RetentionInDays: 14
143
+ RetentionInDays: LogRetentionInDays
142
144
  }
143
145
  },
144
146
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mapbox/cloudfriend",
3
- "version": "8.1.0",
3
+ "version": "8.3.0-1",
4
4
  "description": "Helper functions for assembling CloudFormation templates in JavaScript",
5
5
  "main": "index.js",
6
6
  "engines": {
@@ -11,6 +11,7 @@
11
11
  "lint": "eslint index.js test lib bin cloudformation",
12
12
  "lint:fix": "npm run lint -- --fix",
13
13
  "test": "nyc tape test/*.test.js | tap-spec",
14
+ "test:update": "UPDATE=1 npm run test",
14
15
  "coverage": "nyc --reporter html tape test/*.test.js && opener coverage/index.html",
15
16
  "build-ci-template": "bin/build-template.js cloudformation/ci.template.js > cloudformation/ci.template.json",
16
17
  "shortcuts-api-doc": "jsdoc2md lib/shortcuts/*.js > lib/shortcuts/api.md"
@@ -28,7 +28,7 @@
28
28
  "Type": "AWS::ApiGateway::Stage",
29
29
  "Properties": {
30
30
  "DeploymentId": {
31
- "Ref": "PassDeploymentac7cb6b9"
31
+ "Ref": "PassDeployment2a35d33e"
32
32
  },
33
33
  "StageName": "hookshot",
34
34
  "RestApiId": {
@@ -47,7 +47,7 @@
47
47
  ]
48
48
  }
49
49
  },
50
- "PassDeploymentac7cb6b9": {
50
+ "PassDeployment2a35d33e": {
51
51
  "Type": "AWS::ApiGateway::Deployment",
52
52
  "DependsOn": "PassMethod",
53
53
  "Properties": {
@@ -24,7 +24,7 @@
24
24
  "Type": "AWS::ApiGateway::Stage",
25
25
  "Properties": {
26
26
  "DeploymentId": {
27
- "Ref": "PassDeploymentac7cb6b9"
27
+ "Ref": "PassDeployment2a35d33e"
28
28
  },
29
29
  "StageName": "hookshot",
30
30
  "RestApiId": {
@@ -43,7 +43,7 @@
43
43
  ]
44
44
  }
45
45
  },
46
- "PassDeploymentac7cb6b9": {
46
+ "PassDeployment2a35d33e": {
47
47
  "Type": "AWS::ApiGateway::Deployment",
48
48
  "DependsOn": "PassMethod",
49
49
  "Properties": {
@@ -24,7 +24,7 @@
24
24
  "Type": "AWS::ApiGateway::Stage",
25
25
  "Properties": {
26
26
  "DeploymentId": {
27
- "Ref": "PassDeploymentac7cb6b9"
27
+ "Ref": "PassDeployment2a35d33e"
28
28
  },
29
29
  "StageName": "hookshot",
30
30
  "RestApiId": {
@@ -43,7 +43,7 @@
43
43
  ]
44
44
  }
45
45
  },
46
- "PassDeploymentac7cb6b9": {
46
+ "PassDeployment2a35d33e": {
47
47
  "Type": "AWS::ApiGateway::Deployment",
48
48
  "DependsOn": "PassMethod",
49
49
  "Properties": {
@@ -24,7 +24,7 @@
24
24
  "Type": "AWS::ApiGateway::Stage",
25
25
  "Properties": {
26
26
  "DeploymentId": {
27
- "Ref": "PassDeploymentac7cb6b9"
27
+ "Ref": "PassDeployment2a35d33e"
28
28
  },
29
29
  "StageName": "hookshot",
30
30
  "RestApiId": {
@@ -52,7 +52,7 @@
52
52
  }
53
53
  }
54
54
  },
55
- "PassDeploymentac7cb6b9": {
55
+ "PassDeployment2a35d33e": {
56
56
  "Type": "AWS::ApiGateway::Deployment",
57
57
  "DependsOn": "PassMethod",
58
58
  "Properties": {
@@ -24,7 +24,7 @@
24
24
  "Type": "AWS::ApiGateway::Stage",
25
25
  "Properties": {
26
26
  "DeploymentId": {
27
- "Ref": "PassDeploymentac7cb6b9"
27
+ "Ref": "PassDeployment2a35d33e"
28
28
  },
29
29
  "StageName": "hookshot",
30
30
  "RestApiId": {
@@ -43,7 +43,7 @@
43
43
  ]
44
44
  }
45
45
  },
46
- "PassDeploymentac7cb6b9": {
46
+ "PassDeployment2a35d33e": {
47
47
  "Type": "AWS::ApiGateway::Deployment",
48
48
  "DependsOn": "PassMethod",
49
49
  "Properties": {
@@ -24,7 +24,7 @@
24
24
  "Type": "AWS::ApiGateway::Stage",
25
25
  "Properties": {
26
26
  "DeploymentId": {
27
- "Ref": "PassDeploymentac7cb6b9"
27
+ "Ref": "PassDeployment2a35d33e"
28
28
  },
29
29
  "StageName": "hookshot",
30
30
  "RestApiId": {
@@ -43,7 +43,7 @@
43
43
  ]
44
44
  }
45
45
  },
46
- "PassDeploymentac7cb6b9": {
46
+ "PassDeployment2a35d33e": {
47
47
  "Type": "AWS::ApiGateway::Deployment",
48
48
  "DependsOn": "PassMethod",
49
49
  "Properties": {
@@ -24,7 +24,7 @@
24
24
  "Type": "AWS::ApiGateway::Stage",
25
25
  "Properties": {
26
26
  "DeploymentId": {
27
- "Ref": "PassDeploymentac7cb6b9"
27
+ "Ref": "PassDeployment2a35d33e"
28
28
  },
29
29
  "StageName": "hookshot",
30
30
  "RestApiId": {
@@ -43,7 +43,7 @@
43
43
  ]
44
44
  }
45
45
  },
46
- "PassDeploymentac7cb6b9": {
46
+ "PassDeployment2a35d33e": {
47
47
  "Type": "AWS::ApiGateway::Deployment",
48
48
  "DependsOn": "PassMethod",
49
49
  "Properties": {
@@ -24,7 +24,7 @@
24
24
  "Type": "AWS::ApiGateway::Stage",
25
25
  "Properties": {
26
26
  "DeploymentId": {
27
- "Ref": "PassDeploymentac7cb6b9"
27
+ "Ref": "PassDeployment2a35d33e"
28
28
  },
29
29
  "StageName": "hookshot",
30
30
  "RestApiId": {
@@ -43,7 +43,7 @@
43
43
  ]
44
44
  }
45
45
  },
46
- "PassDeploymentac7cb6b9": {
46
+ "PassDeployment2a35d33e": {
47
47
  "Type": "AWS::ApiGateway::Deployment",
48
48
  "DependsOn": "PassMethod",
49
49
  "Properties": {
@@ -24,7 +24,7 @@
24
24
  "Type": "AWS::ApiGateway::Stage",
25
25
  "Properties": {
26
26
  "DeploymentId": {
27
- "Ref": "PassDeploymentac7cb6b9"
27
+ "Ref": "PassDeployment2a35d33e"
28
28
  },
29
29
  "StageName": "hookshot",
30
30
  "RestApiId": {
@@ -43,7 +43,7 @@
43
43
  ]
44
44
  }
45
45
  },
46
- "PassDeploymentac7cb6b9": {
46
+ "PassDeployment2a35d33e": {
47
47
  "Type": "AWS::ApiGateway::Deployment",
48
48
  "DependsOn": "PassMethod",
49
49
  "Properties": {
@@ -28,7 +28,7 @@
28
28
  }
29
29
  ]
30
30
  },
31
- "RetentionInDays": 14
31
+ "RetentionInDays": 30
32
32
  }
33
33
  },
34
34
  "MyLambda": {
@@ -167,21 +167,21 @@
167
167
  "Properties": {
168
168
  "BatchSize": 10000,
169
169
  "MaximumBatchingWindowInSeconds": 300,
170
+ "Enabled": false,
171
+ "EventSourceArn": "arn:aws:kinesis:us-east-1:123456789012:stream/fake",
172
+ "FunctionName": {
173
+ "Ref": "MyLambda"
174
+ },
175
+ "StartingPosition": "TRIM_HORIZON",
170
176
  "FilterCriteria": {
171
177
  "Filters": [
172
178
  {
173
179
  "Pattern": "{\"eventName\":[\"INSERT\",\"MODIFY\"]}"
174
180
  }
175
181
  ]
176
- },
177
- "Enabled": false,
178
- "EventSourceArn": "arn:aws:kinesis:us-east-1:123456789012:stream/fake",
179
- "FunctionName": {
180
- "Ref": "MyLambda"
181
- },
182
- "StartingPosition": "TRIM_HORIZON"
182
+ }
183
183
  }
184
184
  }
185
185
  },
186
186
  "Outputs": {}
187
- }
187
+ }
@@ -11,6 +11,7 @@ test('intrinsic functions', (assert) => {
11
11
  assert.deepEqual(cloudfriend.base64('secret'), { 'Fn::Base64': 'secret' }, 'base64');
12
12
  assert.deepEqual(cloudfriend.cidr('ipBlock', 1, 2), { 'Fn::Cidr': ['ipBlock', 1, 2] }, 'cidr');
13
13
  assert.deepEqual(cloudfriend.findInMap('mapping', 'key', 'value'), { 'Fn::FindInMap': ['mapping', 'key', 'value'] }, 'lookup');
14
+ assert.deepEqual(cloudfriend.findInMap('mapping', 'key', 'value', 'hello-world'), { 'Fn::FindInMap': ['mapping', 'key', 'value', { DefaultValue: 'hello-world' }] }, 'lookup with default value');
14
15
  assert.deepEqual(
15
16
  cloudfriend.forEach('somethings', 'topic', ['abra', 'cadabra'], 'magic', {
16
17
  Type: 'AWS::SNS::Topic',
@@ -190,7 +190,8 @@ test('[shortcuts] lambda', (assert) => {
190
190
  TreatMissingData: 'breaching',
191
191
  EvaluateLowSampleCountPercentile: 'ignore',
192
192
  ExtendedStatistics: 'p100',
193
- OKActions: ['devnull@mapbox.com']
193
+ OKActions: ['devnull@mapbox.com'],
194
+ LogRetentionInDays: 30
194
195
  });
195
196
 
196
197
  template = cf.merge(