rds-database-running-scheduler 0.1.11 → 0.2.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.
- package/.jsii +18 -10
- package/API.md +6 -1
- package/README.md +5 -2
- package/assets/funcs/running-schedule.lambda/index.js +64 -11
- package/assets/funcs/running-schedule.lambda/index.js.map +3 -3
- package/lib/constructs/rds-database-running-scheduler.d.ts +3 -1
- package/lib/constructs/rds-database-running-scheduler.js +5 -3
- package/lib/funcs/running-schedule-targets.d.ts +66 -0
- package/lib/funcs/running-schedule-targets.js +92 -0
- package/lib/funcs/running-schedule.lambda.d.ts +5 -3
- package/lib/funcs/running-schedule.lambda.js +41 -23
- package/lib/index.d.ts +3 -0
- package/lib/index.js +4 -1
- package/lib/stacks/rds-database-running-schedule-stack.d.ts +3 -0
- package/lib/stacks/rds-database-running-schedule-stack.js +5 -2
- package/package.json +10 -2
package/.jsii
CHANGED
|
@@ -8435,14 +8435,21 @@
|
|
|
8435
8435
|
}
|
|
8436
8436
|
}
|
|
8437
8437
|
},
|
|
8438
|
-
"description": "
|
|
8438
|
+
"description": "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, deduplicates Aurora cluster member instances when the parent cluster is also tagged, and controls each remaining resource using the region encoded in its ARN. Default schedule: start 07:50 UTC, stop 19:05 UTC, Monday–Friday.",
|
|
8439
8439
|
"docs": {
|
|
8440
8440
|
"stability": "stable"
|
|
8441
8441
|
},
|
|
8442
8442
|
"homepage": "https://github.com/gammarers-aws-cdk-constructs/rds-database-running-scheduler.git",
|
|
8443
8443
|
"jsiiVersion": "5.9.44 (build 150b837)",
|
|
8444
8444
|
"keywords": [
|
|
8445
|
-
"
|
|
8445
|
+
"aurora",
|
|
8446
|
+
"aws",
|
|
8447
|
+
"cdk",
|
|
8448
|
+
"cluster",
|
|
8449
|
+
"database",
|
|
8450
|
+
"instance",
|
|
8451
|
+
"rds",
|
|
8452
|
+
"schedule"
|
|
8446
8453
|
],
|
|
8447
8454
|
"license": "Apache-2.0",
|
|
8448
8455
|
"metadata": {
|
|
@@ -8455,7 +8462,7 @@
|
|
|
8455
8462
|
},
|
|
8456
8463
|
"name": "rds-database-running-scheduler",
|
|
8457
8464
|
"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. 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"
|
|
8465
|
+
"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, deduplicates Aurora cluster member instances when the parent cluster is also tagged, and controls each remaining 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- **Cluster-priority deduplication**: When tag discovery returns both an Aurora cluster and its member DB instances, only the cluster is processed to avoid conflicting start/stop operations.\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\nFor Aurora, tagging the cluster is sufficient. If member DB instances inherit the same tag, the Lambda automatically excludes them when the parent cluster is also targeted, so cluster-level start/stop is applied once without conflicting instance-level operations.\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 describe/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
8466
|
},
|
|
8460
8467
|
"repository": {
|
|
8461
8468
|
"type": "git",
|
|
@@ -8472,6 +8479,7 @@
|
|
|
8472
8479
|
"assembly": "rds-database-running-scheduler",
|
|
8473
8480
|
"base": "aws-cdk-lib.Stack",
|
|
8474
8481
|
"docs": {
|
|
8482
|
+
"remarks": "Delegates resource discovery, cluster-priority deduplication, and start/stop\nexecution to {@link RDSDatabaseRunningScheduler}.",
|
|
8475
8483
|
"stability": "stable",
|
|
8476
8484
|
"summary": "CDK stack that provisions scheduled start/stop control for tagged RDS resources in the deployment account."
|
|
8477
8485
|
},
|
|
@@ -8483,7 +8491,7 @@
|
|
|
8483
8491
|
},
|
|
8484
8492
|
"locationInModule": {
|
|
8485
8493
|
"filename": "src/stacks/rds-database-running-schedule-stack.ts",
|
|
8486
|
-
"line":
|
|
8494
|
+
"line": 36
|
|
8487
8495
|
},
|
|
8488
8496
|
"parameters": [
|
|
8489
8497
|
{
|
|
@@ -8518,7 +8526,7 @@
|
|
|
8518
8526
|
"kind": "class",
|
|
8519
8527
|
"locationInModule": {
|
|
8520
8528
|
"filename": "src/stacks/rds-database-running-schedule-stack.ts",
|
|
8521
|
-
"line":
|
|
8529
|
+
"line": 28
|
|
8522
8530
|
},
|
|
8523
8531
|
"name": "RDSDatabaseRunningScheduleStack",
|
|
8524
8532
|
"symbolId": "src/stacks/rds-database-running-schedule-stack:RDSDatabaseRunningScheduleStack"
|
|
@@ -8631,7 +8639,7 @@
|
|
|
8631
8639
|
"assembly": "rds-database-running-scheduler",
|
|
8632
8640
|
"base": "constructs.Construct",
|
|
8633
8641
|
"docs": {
|
|
8634
|
-
"remarks": "The Lambda discovers matching resources account-wide via the Resource Groups\nTagging API and controls each resource using the
|
|
8642
|
+
"remarks": "The Lambda discovers matching resources account-wide via the Resource Groups\nTagging API, deduplicates Aurora cluster member instances when the parent\ncluster is also tagged, and controls each remaining resource using the\nregion encoded in its ARN.",
|
|
8635
8643
|
"stability": "stable",
|
|
8636
8644
|
"summary": "CDK construct that provisions a durable Lambda workflow and EventBridge schedules to start/stop tagged RDS databases and clusters."
|
|
8637
8645
|
},
|
|
@@ -8643,7 +8651,7 @@
|
|
|
8643
8651
|
},
|
|
8644
8652
|
"locationInModule": {
|
|
8645
8653
|
"filename": "src/constructs/rds-database-running-scheduler.ts",
|
|
8646
|
-
"line":
|
|
8654
|
+
"line": 76
|
|
8647
8655
|
},
|
|
8648
8656
|
"parameters": [
|
|
8649
8657
|
{
|
|
@@ -8678,7 +8686,7 @@
|
|
|
8678
8686
|
"kind": "class",
|
|
8679
8687
|
"locationInModule": {
|
|
8680
8688
|
"filename": "src/constructs/rds-database-running-scheduler.ts",
|
|
8681
|
-
"line":
|
|
8689
|
+
"line": 68
|
|
8682
8690
|
},
|
|
8683
8691
|
"name": "RDSDatabaseRunningScheduler",
|
|
8684
8692
|
"symbolId": "src/constructs/rds-database-running-scheduler:RDSDatabaseRunningScheduler"
|
|
@@ -8959,6 +8967,6 @@
|
|
|
8959
8967
|
"symbolId": "src/constructs/rds-database-running-scheduler:TargetResource"
|
|
8960
8968
|
}
|
|
8961
8969
|
},
|
|
8962
|
-
"version": "0.1
|
|
8963
|
-
"fingerprint": "
|
|
8970
|
+
"version": "0.2.1",
|
|
8971
|
+
"fingerprint": "fvXf5yl/VmCKW+3rkp/NnLRnSYiKEzOkfzrna+YjyIQ="
|
|
8964
8972
|
}
|
package/API.md
CHANGED
|
@@ -7,7 +7,9 @@
|
|
|
7
7
|
CDK construct that provisions a durable Lambda workflow and EventBridge schedules to start/stop tagged RDS databases and clusters.
|
|
8
8
|
|
|
9
9
|
The Lambda discovers matching resources account-wide via the Resource Groups
|
|
10
|
-
Tagging API
|
|
10
|
+
Tagging API, deduplicates Aurora cluster member instances when the parent
|
|
11
|
+
cluster is also tagged, and controls each remaining resource using the
|
|
12
|
+
region encoded in its ARN.
|
|
11
13
|
|
|
12
14
|
#### Initializers <a name="Initializers" id="rds-database-running-scheduler.RDSDatabaseRunningScheduler.Initializer"></a>
|
|
13
15
|
|
|
@@ -152,6 +154,9 @@ The tree node.
|
|
|
152
154
|
|
|
153
155
|
CDK stack that provisions scheduled start/stop control for tagged RDS resources in the deployment account.
|
|
154
156
|
|
|
157
|
+
Delegates resource discovery, cluster-priority deduplication, and start/stop
|
|
158
|
+
execution to {@link RDSDatabaseRunningScheduler}.
|
|
159
|
+
|
|
155
160
|
#### Initializers <a name="Initializers" id="rds-database-running-scheduler.RDSDatabaseRunningScheduleStack.Initializer"></a>
|
|
156
161
|
|
|
157
162
|
```typescript
|
package/README.md
CHANGED
|
@@ -7,12 +7,13 @@
|
|
|
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. 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.
|
|
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, deduplicates Aurora cluster member instances when the parent cluster is also tagged, and controls each remaining 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
14
|
- **Tag-based targeting**: Start and stop RDS DB instances and Aurora clusters that match a given tag key and values.
|
|
15
15
|
- **Account-wide discovery**: Finds tagged RDS resources across all regions in the deployment account.
|
|
16
|
+
- **Cluster-priority deduplication**: When tag discovery returns both an Aurora cluster and its member DB instances, only the cluster is processed to avoid conflicting start/stop operations.
|
|
16
17
|
- **Region-aware RDS control**: Creates per-region RDS clients from each resource ARN so cross-region resources are handled correctly.
|
|
17
18
|
- **EventBridge Scheduler**: Cron-based start and stop schedules with configurable timezone, time, and weekdays.
|
|
18
19
|
- **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).
|
|
@@ -69,6 +70,8 @@ new RDSDatabaseRunningScheduleStack(app, 'RDSDatabaseRunningScheduleStack', {
|
|
|
69
70
|
|
|
70
71
|
Tag your RDS instances or Aurora clusters with the same `tagKey` and one of the `tagValues` so they are included in the schedule.
|
|
71
72
|
|
|
73
|
+
For Aurora, tagging the cluster is sufficient. If member DB instances inherit the same tag, the Lambda automatically excludes them when the parent cluster is also targeted, so cluster-level start/stop is applied once without conflicting instance-level operations.
|
|
74
|
+
|
|
72
75
|
The Slack secret in AWS Secrets Manager must contain JSON with `token` and `channel` fields:
|
|
73
76
|
|
|
74
77
|
```json
|
|
@@ -115,7 +118,7 @@ The Slack secret in AWS Secrets Manager must contain JSON with `token` and `chan
|
|
|
115
118
|
- **Node.js**: >= 20.0.0
|
|
116
119
|
- **AWS CDK**: ^2.232.0
|
|
117
120
|
- **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.
|
|
121
|
+
- **AWS**: Account and region with permissions to create EventBridge Scheduler, Lambda, IAM, CloudWatch Logs, and Secrets Manager; RDS describe/start/stop permissions for targeted resources; Resource Groups Tagging API access for resource discovery.
|
|
119
122
|
|
|
120
123
|
## License
|
|
121
124
|
|
|
@@ -23705,6 +23705,47 @@ var import_client_resource_groups_tagging_api = require("@aws-sdk/client-resourc
|
|
|
23705
23705
|
var import_web_api = __toESM(require_dist5());
|
|
23706
23706
|
var import_aws_lambda_secret_fetcher = __toESM(require_lib2());
|
|
23707
23707
|
var import_safe_env_getter = __toESM(require_lib3());
|
|
23708
|
+
|
|
23709
|
+
// src/funcs/running-schedule-targets.ts
|
|
23710
|
+
var parseRdsArn = (arn) => {
|
|
23711
|
+
const parts = arn.split(":");
|
|
23712
|
+
return {
|
|
23713
|
+
targetResource: arn,
|
|
23714
|
+
identifier: parts[6] ?? "",
|
|
23715
|
+
type: parts[5] === "cluster" ? "cluster" : "db",
|
|
23716
|
+
account: parts[4] ?? "",
|
|
23717
|
+
region: parts[3] ?? ""
|
|
23718
|
+
};
|
|
23719
|
+
};
|
|
23720
|
+
var buildClusterKey = (region, clusterIdentifier) => `${region}:${clusterIdentifier}`;
|
|
23721
|
+
var collectClusterKeysFromArns = (arns) => {
|
|
23722
|
+
const keys = /* @__PURE__ */ new Set();
|
|
23723
|
+
for (const arn of arns) {
|
|
23724
|
+
const info = parseRdsArn(arn);
|
|
23725
|
+
if (info.type === "cluster") {
|
|
23726
|
+
keys.add(buildClusterKey(info.region, info.identifier));
|
|
23727
|
+
}
|
|
23728
|
+
}
|
|
23729
|
+
return keys;
|
|
23730
|
+
};
|
|
23731
|
+
var shouldExcludeClusterMemberDb = (region, dbClusterIdentifier, clusterKeys) => {
|
|
23732
|
+
if (clusterKeys.size === 0 || dbClusterIdentifier == null || dbClusterIdentifier === "") {
|
|
23733
|
+
return false;
|
|
23734
|
+
}
|
|
23735
|
+
return clusterKeys.has(buildClusterKey(region, dbClusterIdentifier));
|
|
23736
|
+
};
|
|
23737
|
+
var filterClusterMemberDbs = (arns, dbClusterIdentifiers, clusterKeys) => {
|
|
23738
|
+
return arns.filter((arn) => {
|
|
23739
|
+
const info = parseRdsArn(arn);
|
|
23740
|
+
if (info.type === "cluster") {
|
|
23741
|
+
return true;
|
|
23742
|
+
}
|
|
23743
|
+
const dbClusterIdentifier = dbClusterIdentifiers.get(arn);
|
|
23744
|
+
return !shouldExcludeClusterMemberDb(info.region, dbClusterIdentifier, clusterKeys);
|
|
23745
|
+
});
|
|
23746
|
+
};
|
|
23747
|
+
|
|
23748
|
+
// src/funcs/running-schedule.lambda.ts
|
|
23708
23749
|
var STATE_LIST = [
|
|
23709
23750
|
{ name: "AVAILABLE", emoji: "\u{1F929}", state: "available" },
|
|
23710
23751
|
{ name: "STOPPED", emoji: "\u{1F634}", state: "stopped" }
|
|
@@ -23729,22 +23770,31 @@ var getRdsClient = (region) => {
|
|
|
23729
23770
|
rdsClientCache.set(region, client);
|
|
23730
23771
|
return client;
|
|
23731
23772
|
};
|
|
23732
|
-
var
|
|
23733
|
-
const
|
|
23734
|
-
|
|
23735
|
-
|
|
23736
|
-
|
|
23737
|
-
|
|
23738
|
-
|
|
23739
|
-
|
|
23740
|
-
|
|
23773
|
+
var deduplicateTargetResources = async (arns) => {
|
|
23774
|
+
const clusterKeys = collectClusterKeysFromArns(arns);
|
|
23775
|
+
if (clusterKeys.size === 0) {
|
|
23776
|
+
return arns;
|
|
23777
|
+
}
|
|
23778
|
+
const dbClusterIdentifiers = /* @__PURE__ */ new Map();
|
|
23779
|
+
for (const arn of arns) {
|
|
23780
|
+
const info = parseRdsArn(arn);
|
|
23781
|
+
if (info.type !== "db") {
|
|
23782
|
+
continue;
|
|
23783
|
+
}
|
|
23784
|
+
const rds = getRdsClient(info.region);
|
|
23785
|
+
const response = await rds.send(
|
|
23786
|
+
new import_client_rds.DescribeDBInstancesCommand({ DBInstanceIdentifier: info.identifier })
|
|
23787
|
+
);
|
|
23788
|
+
dbClusterIdentifiers.set(arn, response.DBInstances?.[0]?.DBClusterIdentifier);
|
|
23789
|
+
}
|
|
23790
|
+
return filterClusterMemberDbs(arns, dbClusterIdentifiers, clusterKeys);
|
|
23741
23791
|
};
|
|
23742
23792
|
var getStateDisplay = (current) => {
|
|
23743
23793
|
const found = STATE_LIST.find((s) => s.state === current);
|
|
23744
23794
|
return found ? { emoji: found.emoji, name: found.name } : void 0;
|
|
23745
23795
|
};
|
|
23746
23796
|
var processing = async (context, targetResource, mode) => {
|
|
23747
|
-
const target = await context.step("get-identifier", async () =>
|
|
23797
|
+
const target = await context.step("get-identifier", async () => parseRdsArn(targetResource));
|
|
23748
23798
|
const rds = getRdsClient(target.region);
|
|
23749
23799
|
let iteration = 0;
|
|
23750
23800
|
for (; ; ) {
|
|
@@ -23839,7 +23889,7 @@ var handler = withDurableExecution(
|
|
|
23839
23889
|
const slackSecretValue = await context.step("fetch-slack-secret", async () => {
|
|
23840
23890
|
return import_aws_lambda_secret_fetcher.secretFetcher.getSecretValue(slackSecretName);
|
|
23841
23891
|
});
|
|
23842
|
-
const
|
|
23892
|
+
const discoveredResources = await context.step("get-resources", async () => {
|
|
23843
23893
|
const client2 = new import_client_resource_groups_tagging_api.ResourceGroupsTaggingAPIClient({});
|
|
23844
23894
|
const response = await client2.send(
|
|
23845
23895
|
new import_client_resource_groups_tagging_api.GetResourcesCommand({
|
|
@@ -23849,6 +23899,9 @@ var handler = withDurableExecution(
|
|
|
23849
23899
|
);
|
|
23850
23900
|
return (response.ResourceTagMappingList ?? []).map((m) => m.ResourceARN ?? "").filter(Boolean);
|
|
23851
23901
|
});
|
|
23902
|
+
const targetResources = await context.step("deduplicate-target-resources", async () => {
|
|
23903
|
+
return deduplicateTargetResources(discoveredResources);
|
|
23904
|
+
});
|
|
23852
23905
|
if (targetResources.length === 0) {
|
|
23853
23906
|
return { processed: 0, results: [] };
|
|
23854
23907
|
}
|