@mapbox/cloudfriend 7.3.0-6 → 7.3.0-8

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 (23) hide show
  1. package/.nyc_output/4a01d8fd-0d41-4652-b62f-80a9e0ee2e82.json +1 -0
  2. package/.nyc_output/ffdc1617-095c-45f0-ab0f-449e05e7b3a9.json +1 -0
  3. package/.nyc_output/processinfo/{541ae060-2e88-4f15-a797-36f90bbf7afd.json → 4a01d8fd-0d41-4652-b62f-80a9e0ee2e82.json} +1 -1
  4. package/.nyc_output/processinfo/{8f68394f-90ec-4f8c-8339-6c1c9278c571.json → ffdc1617-095c-45f0-ab0f-449e05e7b3a9.json} +1 -1
  5. package/.nyc_output/processinfo/index.json +1 -1
  6. package/changelog.md +15 -0
  7. package/lib/shortcuts/api.md +36 -5
  8. package/lib/shortcuts/scheduled-lambda.js +40 -4
  9. package/package.json +1 -1
  10. package/test/fixtures/shortcuts/hookshot-github-secret-ref.json +2 -2
  11. package/test/fixtures/shortcuts/hookshot-github-secret-string.json +2 -2
  12. package/test/fixtures/shortcuts/hookshot-github.json +2 -2
  13. package/test/fixtures/shortcuts/hookshot-passthrough-access-log-format.json +2 -2
  14. package/test/fixtures/shortcuts/hookshot-passthrough-alarms.json +2 -2
  15. package/test/fixtures/shortcuts/hookshot-passthrough-enhanced-logging.json +2 -2
  16. package/test/fixtures/shortcuts/hookshot-passthrough-full-blown-logging.json +2 -2
  17. package/test/fixtures/shortcuts/hookshot-passthrough-logging.json +2 -2
  18. package/test/fixtures/shortcuts/hookshot-passthrough.json +2 -2
  19. package/test/fixtures/shortcuts/scheduled-lambda-defaults.json +2 -2
  20. package/test/fixtures/shortcuts/scheduled-lambda-full.json +4 -3
  21. package/test/shortcuts.test.js +1 -0
  22. package/.nyc_output/541ae060-2e88-4f15-a797-36f90bbf7afd.json +0 -1
  23. package/.nyc_output/8f68394f-90ec-4f8c-8339-6c1c9278c571.json +0 -1
@@ -670,11 +670,12 @@ a Lambda permission.
670
670
 
671
671
  ### new ScheduledLambda(options)
672
672
 
673
- | Param | Type | Default | Description |
674
- | --- | --- | --- | --- |
675
- | options | <code>Object</code> | | Extends the options for [`Lambda`](#lambda) with the following additional attributes: |
676
- | options.ScheduleExpression | <code>String</code> | | See [AWS documentation](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-events-rule.html#cfn-events-rule-scheduleexpression). |
677
- | [options.State] | <code>String</code> | <code>&#x27;ENABLED&#x27;</code> | See [AWS documentation](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-events-rule.html#cfn-events-rule-state). |
673
+ | Param | Type | Description |
674
+ | --- | --- | --- |
675
+ | options | <code>Object</code> | Extends the options for [`Lambda`](#lambda) with the following additional attributes: |
676
+ | options.ScheduleExpression | <code>String</code> | See [AWS documentation](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-events-rule.html#cfn-events-rule-scheduleexpression). |
677
+ | [options.ScheduleRoleArn] | <code>String</code> | If specified, the eventbride scheduler will use this role to invoke your lambda . _If this option is specified, do not use the Statement option; add the permissions you need to your Role directly._ See [AWS documentation](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-scheduler-schedule-target.html#cfn-scheduler-schedule-target-rolearn) |
678
+ | [options.ScheduleGroupName] | <code>String</code> | See [AWS documentation](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-scheduler-schedule.html#cfn-scheduler-schedule-groupname). |
678
679
 
679
680
  **Example**
680
681
  ```js
@@ -693,6 +694,36 @@ const lambda = new cf.shortcuts.ScheduledLambda({
693
694
 
694
695
  module.exports = cf.merge(myTemplate, lambda);
695
696
  ```
697
+ **Example**
698
+ ```js
699
+ const cf = require('@mapbox/cloudfriend');
700
+
701
+ const myTemplate = { ... };
702
+
703
+ const role = new cf.shortcuts.ServiceRole({
704
+ LogicalName: 'MyRole',
705
+ Service: 'scheduler.amazonaws.com',
706
+ Statement: [
707
+ {
708
+ Effect: 'Allow',
709
+ Action: 'lambda:InvokeFunction',
710
+ Resource: 'arn:aws:lambda:us-east-1:012345678901:function:my-role-*'
711
+ }
712
+ ]
713
+ });
714
+
715
+ const lambda = new cf.shortcuts.ScheduledLambda({
716
+ LogicalName: 'MyLambda',
717
+ Code: {
718
+ S3Bucket: 'my-code-bucket',
719
+ S3Key: 'path/to/code.zip'
720
+ },
721
+ ScheduleRoleArn: cf.ref('MyRole'),
722
+ ScheduleExpression: 'rate(1 hour)',
723
+ });
724
+
725
+ module.exports = cf.merge(myTemplate, role, lambda);
726
+ ```
696
727
  <a name="ServiceRole"></a>
697
728
 
698
729
  ## ServiceRole
@@ -11,7 +11,9 @@ const ServiceRole = require('./service-role');
11
11
  *
12
12
  * @param {Object} options - Extends the options for [`Lambda`](#lambda) with the following additional attributes:
13
13
  * @param {String} options.ScheduleExpression - See [AWS documentation](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-events-rule.html#cfn-events-rule-scheduleexpression).
14
- * @param {String} [options.State='ENABLED'] - See [AWS documentation](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-events-rule.html#cfn-events-rule-state).
14
+ * @param {String} [options.ScheduleRoleArn=undefined] If specified, the eventbride scheduler will use this role to invoke your lambda . _If this option is specified, do not use the Statement option; add the permissions you need to your Role directly._
15
+ * See [AWS documentation](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-scheduler-schedule-target.html#cfn-scheduler-schedule-target-rolearn)
16
+ * @param {String} [options.ScheduleGroupName=undefined] - See [AWS documentation](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-scheduler-schedule.html#cfn-scheduler-schedule-groupname).
15
17
  *
16
18
  * @example
17
19
  * const cf = require('@mapbox/cloudfriend');
@@ -28,6 +30,35 @@ const ServiceRole = require('./service-role');
28
30
  * });
29
31
  *
30
32
  * module.exports = cf.merge(myTemplate, lambda);
33
+ *
34
+ * @example
35
+ * const cf = require('@mapbox/cloudfriend');
36
+ *
37
+ * const myTemplate = { ... };
38
+ *
39
+ * const role = new cf.shortcuts.ServiceRole({
40
+ * LogicalName: 'MyRole',
41
+ * Service: 'scheduler.amazonaws.com',
42
+ * Statement: [
43
+ * {
44
+ * Effect: 'Allow',
45
+ * Action: 'lambda:InvokeFunction',
46
+ * Resource: 'arn:aws:lambda:us-east-1:012345678901:function:my-role-*'
47
+ * }
48
+ * ]
49
+ * });
50
+ *
51
+ * const lambda = new cf.shortcuts.ScheduledLambda({
52
+ * LogicalName: 'MyLambda',
53
+ * Code: {
54
+ * S3Bucket: 'my-code-bucket',
55
+ * S3Key: 'path/to/code.zip'
56
+ * },
57
+ * ScheduleRoleArn: cf.ref('MyRole'),
58
+ * ScheduleExpression: 'rate(1 hour)',
59
+ * });
60
+ *
61
+ * module.exports = cf.merge(myTemplate, role, lambda);
31
62
  */
32
63
  class ScheduledLambda extends Lambda {
33
64
  constructor(options) {
@@ -35,8 +66,9 @@ class ScheduledLambda extends Lambda {
35
66
  super(options);
36
67
 
37
68
  const {
38
- ScheduleRoleArn,
39
69
  ScheduleExpression,
70
+ ScheduleRoleArn,
71
+ ScheduleGroupName,
40
72
  State = 'ENABLED'
41
73
  } = options;
42
74
 
@@ -68,6 +100,10 @@ class ScheduledLambda extends Lambda {
68
100
  }
69
101
  };
70
102
 
103
+ if (ScheduleGroupName) {
104
+ this.Resources[`${this.LogicalName}EventBridgeSchedule`].Properties.GroupName = ScheduleGroupName;
105
+ }
106
+
71
107
  if (ScheduleRoleArn) {
72
108
  this.Resources[`${this.LogicalName}EventBridgeSchedule`].Properties.Target.RoleArn = ScheduleRoleArn;
73
109
  } else {
@@ -78,9 +114,9 @@ class ScheduledLambda extends Lambda {
78
114
  Statement: [
79
115
  {
80
116
  Effect: 'Allow',
81
- Action: 'lambda:InvokeLambda',
117
+ Action: 'lambda:InvokeFunction',
82
118
  Resource: {
83
- 'Fn::GetAtt': [`${this.LogicalName}Logs`, 'Arn']
119
+ 'Fn::GetAtt': [this.LogicalName, 'Arn']
84
120
  }
85
121
  }
86
122
  ]
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mapbox/cloudfriend",
3
- "version": "7.3.0-6",
3
+ "version": "7.3.0-8",
4
4
  "description": "Helper functions for assembling CloudFormation templates in JavaScript",
5
5
  "main": "index.js",
6
6
  "engines": {
@@ -28,7 +28,7 @@
28
28
  "Type": "AWS::ApiGateway::Stage",
29
29
  "Properties": {
30
30
  "DeploymentId": {
31
- "Ref": "PassDeployment474705f9"
31
+ "Ref": "PassDeploymentd18750cb"
32
32
  },
33
33
  "StageName": "hookshot",
34
34
  "RestApiId": {
@@ -47,7 +47,7 @@
47
47
  ]
48
48
  }
49
49
  },
50
- "PassDeployment474705f9": {
50
+ "PassDeploymentd18750cb": {
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": "PassDeployment474705f9"
27
+ "Ref": "PassDeploymentd18750cb"
28
28
  },
29
29
  "StageName": "hookshot",
30
30
  "RestApiId": {
@@ -43,7 +43,7 @@
43
43
  ]
44
44
  }
45
45
  },
46
- "PassDeployment474705f9": {
46
+ "PassDeploymentd18750cb": {
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": "PassDeployment474705f9"
27
+ "Ref": "PassDeploymentd18750cb"
28
28
  },
29
29
  "StageName": "hookshot",
30
30
  "RestApiId": {
@@ -43,7 +43,7 @@
43
43
  ]
44
44
  }
45
45
  },
46
- "PassDeployment474705f9": {
46
+ "PassDeploymentd18750cb": {
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": "PassDeployment474705f9"
27
+ "Ref": "PassDeploymentd18750cb"
28
28
  },
29
29
  "StageName": "hookshot",
30
30
  "RestApiId": {
@@ -52,7 +52,7 @@
52
52
  }
53
53
  }
54
54
  },
55
- "PassDeployment474705f9": {
55
+ "PassDeploymentd18750cb": {
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": "PassDeployment474705f9"
27
+ "Ref": "PassDeploymentd18750cb"
28
28
  },
29
29
  "StageName": "hookshot",
30
30
  "RestApiId": {
@@ -43,7 +43,7 @@
43
43
  ]
44
44
  }
45
45
  },
46
- "PassDeployment474705f9": {
46
+ "PassDeploymentd18750cb": {
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": "PassDeployment474705f9"
27
+ "Ref": "PassDeploymentd18750cb"
28
28
  },
29
29
  "StageName": "hookshot",
30
30
  "RestApiId": {
@@ -43,7 +43,7 @@
43
43
  ]
44
44
  }
45
45
  },
46
- "PassDeployment474705f9": {
46
+ "PassDeploymentd18750cb": {
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": "PassDeployment474705f9"
27
+ "Ref": "PassDeploymentd18750cb"
28
28
  },
29
29
  "StageName": "hookshot",
30
30
  "RestApiId": {
@@ -43,7 +43,7 @@
43
43
  ]
44
44
  }
45
45
  },
46
- "PassDeployment474705f9": {
46
+ "PassDeploymentd18750cb": {
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": "PassDeployment474705f9"
27
+ "Ref": "PassDeploymentd18750cb"
28
28
  },
29
29
  "StageName": "hookshot",
30
30
  "RestApiId": {
@@ -43,7 +43,7 @@
43
43
  ]
44
44
  }
45
45
  },
46
- "PassDeployment474705f9": {
46
+ "PassDeploymentd18750cb": {
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": "PassDeployment474705f9"
27
+ "Ref": "PassDeploymentd18750cb"
28
28
  },
29
29
  "StageName": "hookshot",
30
30
  "RestApiId": {
@@ -43,7 +43,7 @@
43
43
  ]
44
44
  }
45
45
  },
46
- "PassDeployment474705f9": {
46
+ "PassDeploymentd18750cb": {
47
47
  "Type": "AWS::ApiGateway::Deployment",
48
48
  "DependsOn": "PassMethod",
49
49
  "Properties": {
@@ -189,10 +189,10 @@
189
189
  "Statement": [
190
190
  {
191
191
  "Effect": "Allow",
192
- "Action": "lambda:InvokeLambda",
192
+ "Action": "lambda:InvokeFunction",
193
193
  "Resource": {
194
194
  "Fn::GetAtt": [
195
- "MyLambdaLogs",
195
+ "MyLambda",
196
196
  "Arn"
197
197
  ]
198
198
  }
@@ -162,7 +162,8 @@
162
162
  "Arn"
163
163
  ]
164
164
  }
165
- }
165
+ },
166
+ "GroupName": "my-cool-stack"
166
167
  }
167
168
  },
168
169
  "MyLambdaEventBridgeScheduleRole": {
@@ -189,10 +190,10 @@
189
190
  "Statement": [
190
191
  {
191
192
  "Effect": "Allow",
192
- "Action": "lambda:InvokeLambda",
193
+ "Action": "lambda:InvokeFunction",
193
194
  "Resource": {
194
195
  "Fn::GetAtt": [
195
- "MyLambdaLogs",
196
+ "MyLambda",
196
197
  "Arn"
197
198
  ]
198
199
  }
@@ -335,6 +335,7 @@ test('[shortcuts] scheduled-lambda', (assert) => {
335
335
  S3Key: 'path/to/code.zip'
336
336
  },
337
337
  ScheduledRoleArn: 'arn:aws:iam::012345678901:role/MyCoolRole',
338
+ ScheduleGroupName: 'my-cool-stack',
338
339
  ScheduleExpression: 'rate(1 hour)',
339
340
  State: 'DISABLED'
340
341
  });