rds-database-running-scheduler 0.1.9 → 0.1.10
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.
- package/.jsii +9 -8
- package/API.md +4 -1
- package/README.md +36 -15
- package/assets/funcs/running-schedule.lambda/index.js +14 -1
- package/assets/funcs/running-schedule.lambda/index.js.map +2 -2
- package/lib/constructs/rds-database-running-scheduler.d.ts +3 -0
- package/lib/constructs/rds-database-running-scheduler.js +5 -2
- package/lib/funcs/running-schedule.lambda.d.ts +11 -2
- package/lib/funcs/running-schedule.lambda.js +45 -6
- package/lib/stacks/rds-database-running-schedule-stack.d.ts +2 -1
- package/lib/stacks/rds-database-running-schedule-stack.js +4 -3
- package/package.json +1 -1
package/.jsii
CHANGED
|
@@ -8455,7 +8455,7 @@
|
|
|
8455
8455
|
},
|
|
8456
8456
|
"name": "rds-database-running-scheduler",
|
|
8457
8457
|
"readme": {
|
|
8458
|
-
"markdown": "# RDS Database Running Scheduler (AWS CDK v2)\n\n[](https://github.com/gammarers-aws-cdk-constructs/rds-database-running-scheduler/blob/main/LICENSE)\n[](https://www.npmjs.com/package/rds-database-running-scheduler)\n[](https://github.com/gammarers-aws-cdk-constructs/rds-database-running-scheduler/actions/workflows/release.yml)\n[](https://github.com/gammarers-aws-cdk-constructs/rds-database-running-scheduler/releases)\n\n[](https://constructs.dev/packages/rds-database-running-scheduler)\n\nThis AWS CDK construct controls the start and stop of RDS DB instances and Aurora clusters based on resource tags.
|
|
8458
|
+
"markdown": "# RDS Database Running Scheduler (AWS CDK v2)\n\n[](https://github.com/gammarers-aws-cdk-constructs/rds-database-running-scheduler/blob/main/LICENSE)\n[](https://www.npmjs.com/package/rds-database-running-scheduler)\n[](https://github.com/gammarers-aws-cdk-constructs/rds-database-running-scheduler/actions/workflows/release.yml)\n[](https://github.com/gammarers-aws-cdk-constructs/rds-database-running-scheduler/releases)\n\n[](https://constructs.dev/packages/rds-database-running-scheduler)\n\nThis AWS CDK construct controls the start and stop of RDS DB instances and Aurora clusters based on resource tags. EventBridge Scheduler invokes a durable Lambda function on a cron schedule so databases run only during defined working hours. The Lambda discovers tagged resources account-wide via the Resource Groups Tagging API and controls each resource using the region encoded in its ARN. Default schedule: start 07:50 UTC, stop 19:05 UTC, Monday–Friday.\n\n## Features\n\n- **Tag-based targeting**: Start and stop RDS DB instances and Aurora clusters that match a given tag key and values.\n- **Account-wide discovery**: Finds tagged RDS resources across all regions in the deployment account.\n- **Region-aware RDS control**: Creates per-region RDS clients from each resource ARN so cross-region resources are handled correctly.\n- **EventBridge Scheduler**: Cron-based start and stop schedules with configurable timezone, time, and weekdays.\n- **Lambda with Durable Execution**: A single durable run discovers resources by tag, starts or stops them, and polls until they reach the desired state (with timeout).\n- **Slack notifications**: Posts schedule progress and per-resource results to Slack using a secret stored in AWS Secrets Manager.\n- **Supported resources**: RDS DB instances and RDS Aurora clusters.\n\n## Installation\n\n**npm**\n\n```bash\nnpm install rds-database-running-scheduler\n```\n\n**yarn**\n\n```bash\nyarn add rds-database-running-scheduler\n```\n\n## Usage\n\nUse the **Construct** `RDSDatabaseRunningScheduler` when adding the scheduler into an existing Stack or any CDK scope.\n\n```typescript\nimport { TimeZone } from 'aws-cdk-lib';\nimport { RDSDatabaseRunningScheduler } from 'rds-database-running-scheduler';\n\nnew RDSDatabaseRunningScheduler(scope, 'RDSDatabaseRunningScheduler', {\n targetResource: { tagKey: 'WorkHoursRunning', tagValues: ['YES'] },\n secrets: { slackSecretName: 'example/slack/webhook' },\n enableScheduling: true,\n startSchedule: { timezone: TimeZone.ASIA_TOKYO, minute: '50', hour: '7', week: 'MON-FRI' },\n stopSchedule: { timezone: TimeZone.ASIA_TOKYO, minute: '5', hour: '19', week: 'MON-FRI' },\n});\n```\n\nUse the **Stack** `RDSDatabaseRunningScheduleStack` when you want a dedicated Stack that only contains the scheduler. Both accept the same props.\n\n```typescript\nimport { App, TimeZone } from 'aws-cdk-lib';\nimport { RDSDatabaseRunningScheduleStack } from 'rds-database-running-scheduler';\n\nconst app = new App();\n\nnew RDSDatabaseRunningScheduleStack(app, 'RDSDatabaseRunningScheduleStack', {\n targetResource: { tagKey: 'WorkHoursRunning', tagValues: ['YES'] },\n secrets: { slackSecretName: 'example/slack/webhook' },\n enableScheduling: true,\n startSchedule: { timezone: TimeZone.ASIA_TOKYO, minute: '50', hour: '7', week: 'MON-FRI' },\n stopSchedule: { timezone: TimeZone.ASIA_TOKYO, minute: '5', hour: '19', week: 'MON-FRI' },\n});\n```\n\nTag your RDS instances or Aurora clusters with the same `tagKey` and one of the `tagValues` so they are included in the schedule.\n\nThe Slack secret in AWS Secrets Manager must contain JSON with `token` and `channel` fields:\n\n```json\n{\n \"token\": \"xoxb-...\",\n \"channel\": \"C0123456789\"\n}\n```\n\n## Options\n\n| Option | Type | Required | Description |\n|--------|------|----------|-------------|\n| `targetResource` | `TargetResource` | Yes | Tag key and values used to select RDS resources. |\n| `secrets` | `Secrets` | Yes | Slack configuration. `slackSecretName`: Secrets Manager secret name for Slack (`token` and `channel`). |\n| `enableScheduling` | `boolean` | No | Whether schedules are enabled. Default: `true`. |\n| `startSchedule` | `Schedule` | No | Start schedule. Default: 07:50 UTC, MON–FRI. |\n| `stopSchedule` | `Schedule` | No | Stop schedule. Default: 19:05 UTC, MON–FRI. |\n\n### Schedule\n\n| Field | Type | Description |\n|-------|------|-------------|\n| `timezone` | `TimeZone` | CDK timezone constant (for example `TimeZone.ASIA_TOKYO`, `TimeZone.ETC_UTC`). |\n| `minute` | `string` | Cron minute (for example `'50'`). |\n| `hour` | `string` | Cron hour (for example `'7'`, `'19'`). |\n| `week` | `string` | Cron week day (for example `'MON-FRI'`). |\n\n### TargetResource\n\n| Field | Type | Description |\n|-------|------|-------------|\n| `tagKey` | `string` | Tag key to filter RDS resources. |\n| `tagValues` | `string[]` | Tag values to match (resources with any of these values are targeted). |\n\n### Secrets\n\n| Field | Type | Description |\n|-------|------|-------------|\n| `slackSecretName` | `string` | Secrets Manager secret name containing Slack `token` and `channel`. |\n\n## Requirements\n\n- **Node.js**: >= 20.0.0\n- **AWS CDK**: ^2.232.0\n- **constructs**: ^10.5.1\n- **AWS**: Account and region with permissions to create EventBridge Scheduler, Lambda, IAM, CloudWatch Logs, and Secrets Manager; RDS start/stop permissions for targeted resources; Resource Groups Tagging API access for resource discovery.\n\n## License\n\nThis project is licensed under the Apache-2.0 License.\n"
|
|
8459
8459
|
},
|
|
8460
8460
|
"repository": {
|
|
8461
8461
|
"type": "git",
|
|
@@ -8473,7 +8473,7 @@
|
|
|
8473
8473
|
"base": "aws-cdk-lib.Stack",
|
|
8474
8474
|
"docs": {
|
|
8475
8475
|
"stability": "stable",
|
|
8476
|
-
"summary": "CDK stack that provisions scheduled start/stop control for tagged RDS resources."
|
|
8476
|
+
"summary": "CDK stack that provisions scheduled start/stop control for tagged RDS resources in the deployment account."
|
|
8477
8477
|
},
|
|
8478
8478
|
"fqn": "rds-database-running-scheduler.RDSDatabaseRunningScheduleStack",
|
|
8479
8479
|
"initializer": {
|
|
@@ -8483,7 +8483,7 @@
|
|
|
8483
8483
|
},
|
|
8484
8484
|
"locationInModule": {
|
|
8485
8485
|
"filename": "src/stacks/rds-database-running-schedule-stack.ts",
|
|
8486
|
-
"line":
|
|
8486
|
+
"line": 33
|
|
8487
8487
|
},
|
|
8488
8488
|
"parameters": [
|
|
8489
8489
|
{
|
|
@@ -8518,7 +8518,7 @@
|
|
|
8518
8518
|
"kind": "class",
|
|
8519
8519
|
"locationInModule": {
|
|
8520
8520
|
"filename": "src/stacks/rds-database-running-schedule-stack.ts",
|
|
8521
|
-
"line":
|
|
8521
|
+
"line": 25
|
|
8522
8522
|
},
|
|
8523
8523
|
"name": "RDSDatabaseRunningScheduleStack",
|
|
8524
8524
|
"symbolId": "src/stacks/rds-database-running-schedule-stack:RDSDatabaseRunningScheduleStack"
|
|
@@ -8631,6 +8631,7 @@
|
|
|
8631
8631
|
"assembly": "rds-database-running-scheduler",
|
|
8632
8632
|
"base": "constructs.Construct",
|
|
8633
8633
|
"docs": {
|
|
8634
|
+
"remarks": "The Lambda discovers matching resources account-wide via the Resource Groups\nTagging API and controls each resource using the region encoded in its ARN.",
|
|
8634
8635
|
"stability": "stable",
|
|
8635
8636
|
"summary": "CDK construct that provisions a durable Lambda workflow and EventBridge schedules to start/stop tagged RDS databases and clusters."
|
|
8636
8637
|
},
|
|
@@ -8642,7 +8643,7 @@
|
|
|
8642
8643
|
},
|
|
8643
8644
|
"locationInModule": {
|
|
8644
8645
|
"filename": "src/constructs/rds-database-running-scheduler.ts",
|
|
8645
|
-
"line":
|
|
8646
|
+
"line": 74
|
|
8646
8647
|
},
|
|
8647
8648
|
"parameters": [
|
|
8648
8649
|
{
|
|
@@ -8677,7 +8678,7 @@
|
|
|
8677
8678
|
"kind": "class",
|
|
8678
8679
|
"locationInModule": {
|
|
8679
8680
|
"filename": "src/constructs/rds-database-running-scheduler.ts",
|
|
8680
|
-
"line":
|
|
8681
|
+
"line": 66
|
|
8681
8682
|
},
|
|
8682
8683
|
"name": "RDSDatabaseRunningScheduler",
|
|
8683
8684
|
"symbolId": "src/constructs/rds-database-running-scheduler:RDSDatabaseRunningScheduler"
|
|
@@ -8958,6 +8959,6 @@
|
|
|
8958
8959
|
"symbolId": "src/constructs/rds-database-running-scheduler:TargetResource"
|
|
8959
8960
|
}
|
|
8960
8961
|
},
|
|
8961
|
-
"version": "0.1.
|
|
8962
|
-
"fingerprint": "
|
|
8962
|
+
"version": "0.1.10",
|
|
8963
|
+
"fingerprint": "bFMJ6MG0ILAgYQqUU4vbIbA23FCr7Kddt1h6Mb5Knps="
|
|
8963
8964
|
}
|
package/API.md
CHANGED
|
@@ -6,6 +6,9 @@
|
|
|
6
6
|
|
|
7
7
|
CDK construct that provisions a durable Lambda workflow and EventBridge schedules to start/stop tagged RDS databases and clusters.
|
|
8
8
|
|
|
9
|
+
The Lambda discovers matching resources account-wide via the Resource Groups
|
|
10
|
+
Tagging API and controls each resource using the region encoded in its ARN.
|
|
11
|
+
|
|
9
12
|
#### Initializers <a name="Initializers" id="rds-database-running-scheduler.RDSDatabaseRunningScheduler.Initializer"></a>
|
|
10
13
|
|
|
11
14
|
```typescript
|
|
@@ -147,7 +150,7 @@ The tree node.
|
|
|
147
150
|
|
|
148
151
|
### RDSDatabaseRunningScheduleStack <a name="RDSDatabaseRunningScheduleStack" id="rds-database-running-scheduler.RDSDatabaseRunningScheduleStack"></a>
|
|
149
152
|
|
|
150
|
-
CDK stack that provisions scheduled start/stop control for tagged RDS resources.
|
|
153
|
+
CDK stack that provisions scheduled start/stop control for tagged RDS resources in the deployment account.
|
|
151
154
|
|
|
152
155
|
#### Initializers <a name="Initializers" id="rds-database-running-scheduler.RDSDatabaseRunningScheduleStack.Initializer"></a>
|
|
153
156
|
|
package/README.md
CHANGED
|
@@ -7,14 +7,16 @@
|
|
|
7
7
|
|
|
8
8
|
[](https://constructs.dev/packages/rds-database-running-scheduler)
|
|
9
9
|
|
|
10
|
-
This AWS CDK construct controls the start and stop of RDS DB instances and Aurora clusters based on resource tags.
|
|
10
|
+
This AWS CDK construct controls the start and stop of RDS DB instances and Aurora clusters based on resource tags. EventBridge Scheduler invokes a durable Lambda function on a cron schedule so databases run only during defined working hours. The Lambda discovers tagged resources account-wide via the Resource Groups Tagging API and controls each resource using the region encoded in its ARN. Default schedule: start 07:50 UTC, stop 19:05 UTC, Monday–Friday.
|
|
11
11
|
|
|
12
12
|
## Features
|
|
13
13
|
|
|
14
|
-
- **Tag-based targeting**: Start and stop RDS instances and Aurora clusters that
|
|
14
|
+
- **Tag-based targeting**: Start and stop RDS DB instances and Aurora clusters that match a given tag key and values.
|
|
15
|
+
- **Account-wide discovery**: Finds tagged RDS resources across all regions in the deployment account.
|
|
16
|
+
- **Region-aware RDS control**: Creates per-region RDS clients from each resource ARN so cross-region resources are handled correctly.
|
|
15
17
|
- **EventBridge Scheduler**: Cron-based start and stop schedules with configurable timezone, time, and weekdays.
|
|
16
|
-
- **Lambda with Durable Execution**:
|
|
17
|
-
- **Slack notifications**:
|
|
18
|
+
- **Lambda with Durable Execution**: A single durable run discovers resources by tag, starts or stops them, and polls until they reach the desired state (with timeout).
|
|
19
|
+
- **Slack notifications**: Posts schedule progress and per-resource results to Slack using a secret stored in AWS Secrets Manager.
|
|
18
20
|
- **Supported resources**: RDS DB instances and RDS Aurora clusters.
|
|
19
21
|
|
|
20
22
|
## Installation
|
|
@@ -36,39 +38,52 @@ yarn add rds-database-running-scheduler
|
|
|
36
38
|
Use the **Construct** `RDSDatabaseRunningScheduler` when adding the scheduler into an existing Stack or any CDK scope.
|
|
37
39
|
|
|
38
40
|
```typescript
|
|
41
|
+
import { TimeZone } from 'aws-cdk-lib';
|
|
39
42
|
import { RDSDatabaseRunningScheduler } from 'rds-database-running-scheduler';
|
|
40
43
|
|
|
41
44
|
new RDSDatabaseRunningScheduler(scope, 'RDSDatabaseRunningScheduler', {
|
|
42
45
|
targetResource: { tagKey: 'WorkHoursRunning', tagValues: ['YES'] },
|
|
43
46
|
secrets: { slackSecretName: 'example/slack/webhook' },
|
|
44
47
|
enableScheduling: true,
|
|
45
|
-
startSchedule: { timezone:
|
|
46
|
-
stopSchedule: { timezone:
|
|
48
|
+
startSchedule: { timezone: TimeZone.ASIA_TOKYO, minute: '50', hour: '7', week: 'MON-FRI' },
|
|
49
|
+
stopSchedule: { timezone: TimeZone.ASIA_TOKYO, minute: '5', hour: '19', week: 'MON-FRI' },
|
|
47
50
|
});
|
|
48
51
|
```
|
|
49
52
|
|
|
50
53
|
Use the **Stack** `RDSDatabaseRunningScheduleStack` when you want a dedicated Stack that only contains the scheduler. Both accept the same props.
|
|
51
54
|
|
|
52
55
|
```typescript
|
|
56
|
+
import { App, TimeZone } from 'aws-cdk-lib';
|
|
53
57
|
import { RDSDatabaseRunningScheduleStack } from 'rds-database-running-scheduler';
|
|
54
58
|
|
|
59
|
+
const app = new App();
|
|
60
|
+
|
|
55
61
|
new RDSDatabaseRunningScheduleStack(app, 'RDSDatabaseRunningScheduleStack', {
|
|
56
62
|
targetResource: { tagKey: 'WorkHoursRunning', tagValues: ['YES'] },
|
|
57
63
|
secrets: { slackSecretName: 'example/slack/webhook' },
|
|
58
64
|
enableScheduling: true,
|
|
59
|
-
startSchedule: { timezone:
|
|
60
|
-
stopSchedule: { timezone:
|
|
65
|
+
startSchedule: { timezone: TimeZone.ASIA_TOKYO, minute: '50', hour: '7', week: 'MON-FRI' },
|
|
66
|
+
stopSchedule: { timezone: TimeZone.ASIA_TOKYO, minute: '5', hour: '19', week: 'MON-FRI' },
|
|
61
67
|
});
|
|
62
68
|
```
|
|
63
69
|
|
|
64
70
|
Tag your RDS instances or Aurora clusters with the same `tagKey` and one of the `tagValues` so they are included in the schedule.
|
|
65
71
|
|
|
72
|
+
The Slack secret in AWS Secrets Manager must contain JSON with `token` and `channel` fields:
|
|
73
|
+
|
|
74
|
+
```json
|
|
75
|
+
{
|
|
76
|
+
"token": "xoxb-...",
|
|
77
|
+
"channel": "C0123456789"
|
|
78
|
+
}
|
|
79
|
+
```
|
|
80
|
+
|
|
66
81
|
## Options
|
|
67
82
|
|
|
68
83
|
| Option | Type | Required | Description |
|
|
69
84
|
|--------|------|----------|-------------|
|
|
70
85
|
| `targetResource` | `TargetResource` | Yes | Tag key and values used to select RDS resources. |
|
|
71
|
-
| `secrets` | `Secrets` | Yes | Slack configuration. `slackSecretName`: Secrets Manager secret name for Slack (token and channel). |
|
|
86
|
+
| `secrets` | `Secrets` | Yes | Slack configuration. `slackSecretName`: Secrets Manager secret name for Slack (`token` and `channel`). |
|
|
72
87
|
| `enableScheduling` | `boolean` | No | Whether schedules are enabled. Default: `true`. |
|
|
73
88
|
| `startSchedule` | `Schedule` | No | Start schedule. Default: 07:50 UTC, MON–FRI. |
|
|
74
89
|
| `stopSchedule` | `Schedule` | No | Stop schedule. Default: 19:05 UTC, MON–FRI. |
|
|
@@ -77,10 +92,10 @@ Tag your RDS instances or Aurora clusters with the same `tagKey` and one of the
|
|
|
77
92
|
|
|
78
93
|
| Field | Type | Description |
|
|
79
94
|
|-------|------|-------------|
|
|
80
|
-
| `timezone` | `
|
|
81
|
-
| `minute` | `string` | Cron minute (
|
|
82
|
-
| `hour` | `string` | Cron hour (
|
|
83
|
-
| `week` | `string` | Cron week day (
|
|
95
|
+
| `timezone` | `TimeZone` | CDK timezone constant (for example `TimeZone.ASIA_TOKYO`, `TimeZone.ETC_UTC`). |
|
|
96
|
+
| `minute` | `string` | Cron minute (for example `'50'`). |
|
|
97
|
+
| `hour` | `string` | Cron hour (for example `'7'`, `'19'`). |
|
|
98
|
+
| `week` | `string` | Cron week day (for example `'MON-FRI'`). |
|
|
84
99
|
|
|
85
100
|
### TargetResource
|
|
86
101
|
|
|
@@ -89,12 +104,18 @@ Tag your RDS instances or Aurora clusters with the same `tagKey` and one of the
|
|
|
89
104
|
| `tagKey` | `string` | Tag key to filter RDS resources. |
|
|
90
105
|
| `tagValues` | `string[]` | Tag values to match (resources with any of these values are targeted). |
|
|
91
106
|
|
|
107
|
+
### Secrets
|
|
108
|
+
|
|
109
|
+
| Field | Type | Description |
|
|
110
|
+
|-------|------|-------------|
|
|
111
|
+
| `slackSecretName` | `string` | Secrets Manager secret name containing Slack `token` and `channel`. |
|
|
112
|
+
|
|
92
113
|
## Requirements
|
|
93
114
|
|
|
94
115
|
- **Node.js**: >= 20.0.0
|
|
95
116
|
- **AWS CDK**: ^2.232.0
|
|
96
|
-
- **constructs**: ^10.
|
|
97
|
-
- **AWS**: Account and region with permissions to create EventBridge Scheduler, Lambda, IAM, and RDS
|
|
117
|
+
- **constructs**: ^10.5.1
|
|
118
|
+
- **AWS**: Account and region with permissions to create EventBridge Scheduler, Lambda, IAM, CloudWatch Logs, and Secrets Manager; RDS start/stop permissions for targeted resources; Resource Groups Tagging API access for resource discovery.
|
|
98
119
|
|
|
99
120
|
## License
|
|
100
121
|
|
|
@@ -23601,6 +23601,19 @@ var TRANSITIONING_STATES = [
|
|
|
23601
23601
|
"modifying",
|
|
23602
23602
|
"stopping"
|
|
23603
23603
|
];
|
|
23604
|
+
var rdsClientCache = /* @__PURE__ */ new Map();
|
|
23605
|
+
var getRdsClient = (region) => {
|
|
23606
|
+
if (!region) {
|
|
23607
|
+
throw new Error("Region is required to create RDS client");
|
|
23608
|
+
}
|
|
23609
|
+
const cached = rdsClientCache.get(region);
|
|
23610
|
+
if (cached) {
|
|
23611
|
+
return cached;
|
|
23612
|
+
}
|
|
23613
|
+
const client = new import_client_rds.RDSClient({ region });
|
|
23614
|
+
rdsClientCache.set(region, client);
|
|
23615
|
+
return client;
|
|
23616
|
+
};
|
|
23604
23617
|
var parseArn = (arn) => {
|
|
23605
23618
|
const parts = arn.split(":");
|
|
23606
23619
|
return {
|
|
@@ -23617,7 +23630,7 @@ var getStateDisplay = (current) => {
|
|
|
23617
23630
|
};
|
|
23618
23631
|
var processing = async (context, targetResource, mode) => {
|
|
23619
23632
|
const target = await context.step("get-identifier", async () => parseArn(targetResource));
|
|
23620
|
-
const rds =
|
|
23633
|
+
const rds = getRdsClient(target.region);
|
|
23621
23634
|
let iteration = 0;
|
|
23622
23635
|
for (; ; ) {
|
|
23623
23636
|
const stepName = `describe-${target.type}-${target.identifier}-${iteration}`;
|