rds-database-running-scheduler 0.6.3 → 0.7.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 +38 -38
- package/API.md +24 -11
- package/README.md +12 -6
- package/assets/funcs/running-schedule.lambda/index.js +2085 -598
- package/assets/funcs/running-schedule.lambda/index.js.map +4 -4
- package/lib/funcs/core/running-schedule-errors.d.ts +6 -1
- package/lib/funcs/core/running-schedule-errors.js +7 -2
- package/lib/funcs/core/running-schedule-map.d.ts +108 -0
- package/lib/funcs/core/running-schedule-map.js +137 -0
- package/lib/funcs/core/running-schedule-stop-skip.d.ts +39 -0
- package/lib/funcs/core/running-schedule-stop-skip.js +74 -0
- package/lib/funcs/core/running-schedule-wait.d.ts +45 -5
- package/lib/funcs/core/running-schedule-wait.js +57 -8
- package/lib/funcs/running-schedule.lambda.js +232 -80
- package/lib/rds-database-running-schedule-stack.js +1 -1
- package/lib/rds-database-running-scheduler.d.ts +20 -11
- package/lib/rds-database-running-scheduler.js +54 -79
- package/package.json +18 -10
package/.jsii
CHANGED
|
@@ -8448,7 +8448,7 @@
|
|
|
8448
8448
|
"stability": "stable"
|
|
8449
8449
|
},
|
|
8450
8450
|
"homepage": "https://github.com/gammarers-aws-cdk-constructs/rds-database-running-scheduler.git",
|
|
8451
|
-
"jsiiVersion": "6.0.
|
|
8451
|
+
"jsiiVersion": "6.0.25 (build a771806)",
|
|
8452
8452
|
"keywords": [
|
|
8453
8453
|
"aurora",
|
|
8454
8454
|
"aws",
|
|
@@ -8471,7 +8471,7 @@
|
|
|
8471
8471
|
},
|
|
8472
8472
|
"name": "rds-database-running-scheduler",
|
|
8473
8473
|
"readme": {
|
|
8474
|
-
"markdown": "# RDS Database Running Scheduler (CDK v2)\n\n[](https://www.npmjs.com/package/rds-database-running-scheduler)\n[](https://www.npmjs.com/package/rds-database-running-scheduler)\n[](https://www.npmjs.com/package/rds-database-running-scheduler)\n[](https://github.com/gammarers-aws-cdk-constructs/rds-database-running-scheduler/actions/workflows/build.yml)\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.\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- **Multi-region discovery**: Searches every region enabled for the account, one region at a time, for tagged RDS resources. Set `targetRegions` to search only the regions you list.\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- **Cross-region control**: Each resource is started and stopped in the region it lives in, even when that is not the stack's region.\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 waits until they reach the desired state or the per-resource wait limit.\n- **Configurable wait**: Set `resourceWait.intervalSeconds` and `resourceWait.maxSeconds` to control how often each resource is checked and how long the function waits before timing out. Defaults are 60 seconds and 1800 seconds.\n- **Optional Slack notifications**: Set `notification.slack.enable` to `SlackNotificationEnable.ENABLED` and provide `secretName` to post schedule progress and per-resource results to Slack via Secrets Manager. Leave `enable` unset (default `SlackNotificationEnable.DISABLED`), set it to `DISABLED`, or omit `notification.slack` to skip secret lookup, Slack API calls, and related IAM grants. When Slack is enabled, a timeout posts a message unless `notification.slack.notifyOnWaitTimeout` is `WaitTimeoutNotification.DISABLED`.\n- **Opt-in failure detection**: Set `failureDetection.enabled` to `true` to create CloudWatch alarms for the Lambda `Errors` and `Throttles` metrics and for the handler's failure logs (wait timeout, unexpected status, failed execution). Pass an existing SNS topic as `failureDetection.alarmTopic` to be notified. Nothing is created by default, and the construct never creates an SNS topic.\n- **Supported resources**: RDS DB instances and RDS Aurora clusters.\n\n## How it works\n\nEventBridge Scheduler runs a start cron and a stop cron. Each one invokes a durable Lambda function. A failed invocation is retried at most twice, and only while the original event is less than 2 hours old. That window matches the durable execution timeout and is not configurable via props today. On the default schedule it ends before the opposite cron, so a failed stop is not run again after the next start.\n\nThe function lists the regions enabled for the account and searches each one with the Resource Groups Tagging API for RDS DB instances and Aurora clusters that match `targetResource`. The Tagging API returns only the resources of the region it is called in, so each region is searched separately. When `targetRegions` is set, only those regions are searched. When both a cluster and its member instances match, only the cluster is controlled. Each remaining resource is started or stopped in the region taken from its ARN.\n\nThe function then checks that resource every `resourceWait.intervalSeconds` until it is available or stopped, or until `resourceWait.maxSeconds` elapses. A stop also waits through `storage-optimization`. A start that sees `storage-optimization` waits until the status is `stopped`, then starts the database. `configuring-iam-database-auth` and `configuring-log-exports` are waited on the same way. When Slack is enabled, it posts progress and, by default, a message when the wait limit is exceeded.\n\nSome cases change nothing. When no resource matches, the run ends without posting to Slack. A resource that is already in the target state (available for a start, stopped for a stop) gets no start or stop call, but Slack still receives its result message. A cluster that no longer exists is skipped without a failure and without a result message. Both schedules can also be created in the disabled state with `enableScheduling`.\n\nA resource that does not reach its target state within the wait limit, or reports a status that cannot be handled (for example `incompatible-restore`), fails the run. The other resources are still processed first, then the whole execution is marked as failed. The failure is also written to the log, which is what the opt-in failure detection alarms watch.\n\nThe Lambda log group keeps logs for three months. It is deleted only when its creation fails, and it is retained when the stack is deleted or the resource is replaced, so failures stay investigable.\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### pnpm\n\n```bash\npnpm add rds-database-running-scheduler\n```\n\n## Usage\n\n### Minimal deployable app\n\nUse the **Stack** `RDSDatabaseRunningScheduleStack` when you want a dedicated stack you can deploy as-is. Put this in your CDK app entry (for example `bin/app.ts`).\n\n```typescript\nimport { App } from 'aws-cdk-lib';\nimport { RDSDatabaseRunningScheduleStack } from 'rds-database-running-scheduler';\n\nconst app = new App();\n\nnew RDSDatabaseRunningScheduleStack(app, 'RDSDatabaseRunningScheduleStack', {\n env: {\n account: process.env.CDK_DEFAULT_ACCOUNT,\n region: process.env.CDK_DEFAULT_REGION,\n },\n targetResource: { tagKey: 'WorkHoursRunning', tagValues: ['YES'] },\n});\n\napp.synth();\n```\n\nThis uses the default schedules: start at 07:50 UTC and stop at 19:05 UTC, Monday–Friday. Slack notifications and failure detection are off. Every region enabled for the account is searched.\n\nDeploy checklist:\n\n1. Install this package and its peers (`aws-cdk-lib`, `constructs`, `lambda-failure-detector`) in your CDK app.\n2. Tag the RDS DB instances or Aurora clusters you want to control with the same `tagKey` and one of the `tagValues`.\n3. Only when you enable Slack, create the Secrets Manager secret first (see [Slack secret](#slack-secret)).\n4. From the CDK app: `npx cdk deploy RDSDatabaseRunningScheduleStack`\n\n### Construct\n\nUse the **Construct** `RDSDatabaseRunningScheduler` when adding the scheduler into an existing Stack or any CDK scope. It accepts the same scheduler props as the Stack.\n\n```typescript\nimport { RDSDatabaseRunningScheduler } from 'rds-database-running-scheduler';\n\nnew RDSDatabaseRunningScheduler(scope, 'RDSDatabaseRunningScheduler', {\n targetResource: { tagKey: 'WorkHoursRunning', tagValues: ['YES'] },\n});\n```\n\nTo search only some regions, list them in `targetRegions`:\n\n```typescript\nnew RDSDatabaseRunningScheduler(scope, 'RDSDatabaseRunningScheduler', {\n targetResource: { tagKey: 'WorkHoursRunning', tagValues: ['YES'] },\n targetRegions: ['ap-northeast-1', 'us-east-1'],\n});\n```\n\nTo be alerted when a run fails, enable failure detection and pass an SNS topic you already own:\n\n```typescript\nimport { Topic } from 'aws-cdk-lib/aws-sns';\n\nnew RDSDatabaseRunningScheduler(scope, 'RDSDatabaseRunningScheduler', {\n targetResource: { tagKey: 'WorkHoursRunning', tagValues: ['YES'] },\n failureDetection: {\n enabled: true,\n alarmTopic: Topic.fromTopicArn(scope, 'AlarmTopic', 'arn:aws:sns:ap-northeast-1:123456789012:alarm-topic'),\n },\n});\n```\n\nWith Slack notifications and a custom schedule:\n\n```typescript\nimport { TimeZone } from 'aws-cdk-lib';\nimport { RDSDatabaseRunningScheduler, SchedulingEnable, SlackNotificationEnable } from 'rds-database-running-scheduler';\n\nnew RDSDatabaseRunningScheduler(scope, 'RDSDatabaseRunningScheduler', {\n targetResource: { tagKey: 'WorkHoursRunning', tagValues: ['YES'] },\n notification: { slack: { enable: SlackNotificationEnable.ENABLED, secretName: 'example/slack/webhook' } },\n enableScheduling: SchedulingEnable.ENABLED,\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\nThe Stack takes the same props, so the same options work with `RDSDatabaseRunningScheduleStack`.\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\n### Slack secret\n\nSlack is optional. Only when `notification.slack.enable` is `SlackNotificationEnable.ENABLED` do you need to create the secret in AWS Secrets Manager **before deploying**. Without it, no secret is read and no secret-related IAM is granted. When enabled, the construct grants the Lambda read access to that secret and attaches the AWS Parameters and Secrets Lambda Extension layer, so you do not add either yourself. The secret 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| `targetRegions` | `string[]` | No | Regions to search for tagged RDS resources. Each must be a region enabled for the account. Must not be empty, blank, or contain duplicates. Default: every region enabled for the account. |\n| `notification` | `Notification` | No | Notification channels. Set `notification.slack.enable` to `SlackNotificationEnable.ENABLED` to send Slack messages. |\n| `resourceWait` | `ResourceWait` | No | Per-resource status-check interval and maximum wait. Default: 60-second interval, 1800-second maximum. |\n| `enableScheduling` | `SchedulingEnable` | No | Whether start and stop schedules are enabled. `ENABLED` or `DISABLED`. Default: `ENABLED`. |\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| `failureDetection` | `LambdaFailureDetection` | No | Opt-in CloudWatch failure detection from [lambda-failure-detector](https://www.npmjs.com/package/lambda-failure-detector). Alarms are created only when `enabled` is `true`. `alarmTopic` is an optional existing SNS topic for every alarm. Default: no failure detection resources. |\n\n### Schedule\n\n| Field | Type | Required | Description |\n|-------|------|----------|-------------|\n| `timezone` | `TimeZone` | Yes | CDK timezone constant (for example `TimeZone.ASIA_TOKYO`, `TimeZone.ETC_UTC`). |\n| `minute` | `string` | No | Cron minute (for example `'50'`). |\n| `hour` | `string` | No | Cron hour (for example `'7'`, `'19'`). |\n| `week` | `string` | No | Cron week day (for example `'MON-FRI'`). |\n\n### TargetResource\n\n| Field | Type | Required | Description |\n|-------|------|----------|-------------|\n| `tagKey` | `string` | Yes | Tag key to filter RDS resources. |\n| `tagValues` | `string[]` | Yes | Tag values to match (resources with any of these values are targeted). |\n\n### Notification\n\n| Field | Type | Required | Description |\n|-------|------|----------|-------------|\n| `slack` | `SlackNotification` | No | Slack settings. Omit, or set `enable` to `SlackNotificationEnable.DISABLED`, to disable Slack. |\n\n### SlackNotification\n\n| Field | Type | Required | Description |\n|-------|------|----------|-------------|\n| `enable` | `SlackNotificationEnable` | No | Enable Slack notifications. `ENABLED` or `DISABLED`. Default: `DISABLED`. When `DISABLED`, secret lookup, Slack API calls, and IAM grants are skipped. |\n| `secretName` | `string` | No | Secrets Manager secret name containing Slack `token` and `channel`. Required when `enable` is `ENABLED`. |\n| `notifyOnWaitTimeout` | `WaitTimeoutNotification` | No | Post a Slack message when a resource exceeds `resourceWait.maxSeconds`. `ENABLED` or `DISABLED`. Applies only when `enable` is `ENABLED`. Default: `ENABLED`. |\n\n### ResourceWait\n\n| Field | Type | Required | Description |\n|-------|------|----------|-------------|\n| `intervalSeconds` | `number` | No | Seconds between status checks. Positive integer. Default: `60`. |\n| `maxSeconds` | `number` | No | Maximum accumulated wait seconds for one resource. Positive integer, greater than or equal to `intervalSeconds`, and at most `6900`. Default: `1800`. |\n\n## API\n\nSee [API.md](./API.md).\n\n## Requirements\n\n- **Node.js**: >= 20.0.0\n- **AWS CDK**: ^2.232.0\n- **constructs**: ^10.5.1\n- **lambda-failure-detector**: ^0.2.1 (peer dependency, used only when `failureDetection.enabled` is `true`)\n- **AWS**: Account and region with permissions to create EventBridge Scheduler, Lambda, IAM, and CloudWatch Logs; RDS describe/start/stop permissions for targeted resources. Start/stop IAM is scoped to DB instance and cluster ARNs in the account and to `aws:ResourceTag` matching `targetResource`. Resource Groups Tagging API access (`tag:GetResources`) and `ec2:DescribeRegions` are required for resource discovery. Secrets Manager access is required only when Slack notifications are enabled.\n\n## Notes\n\n- **Least privilege**: Discovery and status checks (`tag:GetResources`, `ec2:DescribeRegions`, `rds:DescribeDBInstances`, `rds:DescribeDBClusters`) do not support resource-level permissions, so they use `*`. Start and stop are limited to DB instance and cluster ARNs in your account and to resources whose `aws:ResourceTag/<tagKey>` matches `targetResource`. The region part of those ARNs is `*` because tagged resources may live outside the stack region.\n- **Safe to run again**: A start on an available resource and a stop on a stopped resource make no RDS call, so a retried or repeated run does not repeat a finished operation.\n- **Retries**: Failed invocations are retried at most twice within 2 hours, which is not configurable via props today. A run that fails because a resource timed out or reported an unexpected status is a failed invocation too.\n\n## Troubleshooting\n\nStart with the Lambda log group (`/aws/lambda/<function name>`). It keeps logs for three months and is retained when the stack is deleted.\n\nWhen nothing seems to happen, check these in order:\n\n1. The schedules were not created with `enableScheduling: SchedulingEnable.DISABLED`.\n2. The resources carry the exact `tagKey` and one of the `tagValues`.\n3. The resources are in a searched region: every enabled region by default, or only `targetRegions` when it is set.\n4. The resource is not a cluster that no longer exists, which is skipped silently.\n\nWhen Slack messages are missing, confirm the secret exists, contains `token` and `channel`, and that `notification.slack.enable` is `ENABLED`. A secret that cannot be read fails the run.\n\nWhen `failureDetection.enabled` is `true`, these alarms are created. Each one counts ERROR logs that start with the marker of the same name, in the `RDSDatabaseRunningScheduler` metric namespace:\n\n| Alarm / marker | Meaning |\n|----------------|---------|\n| `ResourceWaitTimedOut` | A resource did not reach its target state within `resourceWait.maxSeconds`. |\n| `ResourceStatusUnexpected` | A resource reported a status that cannot be handled, for example `incompatible-restore`. |\n| `ScheduleExecutionFailed` | The whole execution failed for any reason, including the two above. It also fires for failures before any resource is processed, such as an invalid `targetRegions`. |\n\nThe Lambda `Errors` and `Throttles` alarms cover failures of the invocation itself. A durable execution that fails inside the handler does not always raise `Errors`, so rely on `ScheduleExecutionFailed` for those.\n\n## License\n\nThis project is licensed under the (Apache-2.0) License.\n"
|
|
8474
|
+
"markdown": "# RDS Database Running Scheduler (CDK v2)\n\n[](https://www.npmjs.com/package/rds-database-running-scheduler)\n[](https://www.npmjs.com/package/rds-database-running-scheduler)\n[](https://www.npmjs.com/package/rds-database-running-scheduler)\n[](https://github.com/gammarers-aws-cdk-constructs/rds-database-running-scheduler/actions/workflows/build.yml)\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.\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- **Multi-region discovery**: Searches every region enabled for the account, one region at a time, for tagged RDS resources. Set `targetRegions` to search only the regions you list.\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- **Cross-region control**: Each resource is started and stopped in the region it lives in, even when that is not the stack's region.\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 waits until they reach the desired state or the per-resource wait limit.\n- **Configurable wait**: Set `resourceWait.intervalSeconds` and `resourceWait.maxSeconds` to control how often each resource is checked and how long the function waits before timing out. Defaults are 60 seconds and 1800 seconds.\n- **Optional Slack notifications**: Set `notification.slack.enable` to `SlackNotificationEnable.ENABLED` and provide `secretName` to post schedule progress and per-resource results to Slack via Secrets Manager. Leave `enable` unset (default `SlackNotificationEnable.DISABLED`), set it to `DISABLED`, or omit `notification.slack` to skip secret lookup, Slack API calls, and related IAM grants. When Slack is enabled, a timeout posts a message unless `notification.slack.notifyOnWaitTimeout` is `WaitTimeoutNotification.DISABLED`.\n- **Opt-in failure detection**: Set `failureDetection.enabled` to `true` to create CloudWatch alarms for the Lambda `Errors` and `Throttles` metrics and for the handler's failure logs (wait timeout, unexpected status, failed execution). Pass an existing SNS topic as `failureDetection.alarmTopic` to be notified. Nothing is created by default, and the construct never creates an SNS topic.\n- **Stop skips unsupported configurations**: A stop leaves RDS Custom, Aurora Serverless v1, and Aurora global database clusters that are not the only cluster in that global database running. The execution result and Slack include the reason. A start still runs them.\n- **Backup defers a stop**: A stop that finds `backing-up` before calling stop waits for the next stop schedule instead of timing out. The result and Slack include the reason. A start still waits through `backing-up`.\n- **Supported resources**: RDS DB instances and RDS Aurora clusters.\n\n## How it works\n\nEventBridge Scheduler runs a start cron and a stop cron. Each one invokes a durable Lambda function. A failed invocation is retried at most twice, and only while the original event is less than 2 hours old. That window matches the durable execution timeout. One invocation times out after 15 minutes, and the execution history is kept for 1 day. The invocation timeout, the execution timeout, and the history retention are not configurable via props today. On the default schedule the retry window ends before the opposite cron, so a failed stop is not run again after the next start.\n\nThe function lists the regions enabled for the account and searches each one with the Resource Groups Tagging API for RDS DB instances and Aurora clusters that match `targetResource`. The Tagging API returns only the resources of the region it is called in, so each region is searched separately. Each `GetResources` call returns at most 100 matches, and the function follows `PaginationToken` until the last page before it deduplicates. When `targetRegions` is set, only those regions are searched. When both a cluster and its member instances match, only the cluster is controlled. Each remaining resource is started or stopped in the region taken from its ARN.\n\nThe function then checks that resource every `resourceWait.intervalSeconds` until it is available or stopped, or until `resourceWait.maxSeconds` elapses. A stop also waits through `storage-optimization`. A start that sees `storage-optimization` waits until the status is `stopped`, then starts the database. `configuring-iam-database-auth` and `configuring-log-exports` are waited on the same way. A stop that sees `backing-up` before it calls stop does not wait and does not fail. The result status is `deferred`, and the reason says the next stop schedule will try again. When Slack is enabled, that reason is posted in the thread. A start still waits through `backing-up`. After stop has been called, a later `backing-up` status is waited on like any other transition. When Slack is enabled, it posts progress and, by default, a message when the wait limit is exceeded.\n\nSome cases change nothing. When no resource matches, the run ends without posting to Slack. A resource that is already in the target state (available for a start, stopped for a stop) gets no start or stop call, but Slack still receives its result message. A cluster that no longer exists is skipped without a failure and without a result message. Both schedules can also be created in the disabled state with `enableScheduling`.\n\nA stop skips a configuration the stop API rejects, and the run does not fail because of that skip. An RDS Custom instance has an engine name that starts with `custom-`. An Aurora Serverless v1 cluster has `EngineMode` `serverless`. An Aurora global database cluster is skipped when `EngineMode` is `global`, or when `GlobalClusterIdentifier` is set and the cluster has read replicas or no writer. The only cluster in a global database, and Aurora Serverless v2 (`EngineMode` `provisioned`), are still stopped. The result status is `skipped` and includes the reason. When Slack is enabled, that reason is posted in the thread. A start still runs these resources.\n\nA resource that does not reach its target state within the wait limit, reports a status that cannot be handled (for example `incompatible-restore`), or is a DB instance that no longer exists, is a failed resource. The run still starts or stops every other resource and posts that resource's Slack message before the execution is marked as failed. The execution error names up to 10 failed resources. The log lists every failed resource and its error, separate from the failure-detection markers.\n\nThe Lambda log group keeps logs for three months. It is deleted only when its creation fails, and it is retained when the stack is deleted or the resource is replaced, so failures stay investigable.\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### pnpm\n\n```bash\npnpm add rds-database-running-scheduler\n```\n\n## Usage\n\n### Minimal deployable app\n\nUse the **Stack** `RDSDatabaseRunningScheduleStack` when you want a dedicated stack you can deploy as-is. Put this in your CDK app entry (for example `bin/app.ts`).\n\n```typescript\nimport { App } from 'aws-cdk-lib';\nimport { RDSDatabaseRunningScheduleStack } from 'rds-database-running-scheduler';\n\nconst app = new App();\n\nnew RDSDatabaseRunningScheduleStack(app, 'RDSDatabaseRunningScheduleStack', {\n env: {\n account: process.env.CDK_DEFAULT_ACCOUNT,\n region: process.env.CDK_DEFAULT_REGION,\n },\n targetResource: { tagKey: 'WorkHoursRunning', tagValues: ['YES'] },\n});\n\napp.synth();\n```\n\nThis uses the default schedules: start at 07:50 UTC and stop at 19:05 UTC, Monday–Friday. Slack notifications and failure detection are off. Every region enabled for the account is searched.\n\nDeploy checklist:\n\n1. Install this package and its peers (`aws-cdk-lib`, `constructs`, `lambda-failure-detector`) in your CDK app.\n2. Tag the RDS DB instances or Aurora clusters you want to control with the same `tagKey` and one of the `tagValues`.\n3. Only when you enable Slack, create the Secrets Manager secret first (see [Slack secret](#slack-secret)).\n4. From the CDK app: `npx cdk deploy RDSDatabaseRunningScheduleStack`\n\n### Construct\n\nUse the **Construct** `RDSDatabaseRunningScheduler` when adding the scheduler into an existing Stack or any CDK scope. It accepts the same scheduler props as the Stack.\n\n```typescript\nimport { RDSDatabaseRunningScheduler } from 'rds-database-running-scheduler';\n\nnew RDSDatabaseRunningScheduler(scope, 'RDSDatabaseRunningScheduler', {\n targetResource: { tagKey: 'WorkHoursRunning', tagValues: ['YES'] },\n});\n```\n\nTo search only some regions, list them in `targetRegions`:\n\n```typescript\nnew RDSDatabaseRunningScheduler(scope, 'RDSDatabaseRunningScheduler', {\n targetResource: { tagKey: 'WorkHoursRunning', tagValues: ['YES'] },\n targetRegions: ['ap-northeast-1', 'us-east-1'],\n});\n```\n\nTo be alerted when a run fails, enable failure detection and pass an SNS topic you already own:\n\n```typescript\nimport { Topic } from 'aws-cdk-lib/aws-sns';\n\nnew RDSDatabaseRunningScheduler(scope, 'RDSDatabaseRunningScheduler', {\n targetResource: { tagKey: 'WorkHoursRunning', tagValues: ['YES'] },\n failureDetection: {\n enabled: true,\n alarmTopic: Topic.fromTopicArn(scope, 'AlarmTopic', 'arn:aws:sns:ap-northeast-1:123456789012:alarm-topic'),\n },\n});\n```\n\nWith Slack notifications and a custom schedule:\n\n```typescript\nimport { TimeZone } from 'aws-cdk-lib';\nimport { RDSDatabaseRunningScheduler, SchedulingEnable, SlackNotificationEnable } from 'rds-database-running-scheduler';\n\nnew RDSDatabaseRunningScheduler(scope, 'RDSDatabaseRunningScheduler', {\n targetResource: { tagKey: 'WorkHoursRunning', tagValues: ['YES'] },\n notification: { slack: { enable: SlackNotificationEnable.ENABLED, secretName: 'example/slack/webhook' } },\n enableScheduling: SchedulingEnable.ENABLED,\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\nThe Stack takes the same props, so the same options work with `RDSDatabaseRunningScheduleStack`.\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\n### Slack secret\n\nSlack is optional. Only when `notification.slack.enable` is `SlackNotificationEnable.ENABLED` do you need to create the secret in AWS Secrets Manager **before deploying**. Without it, no secret is read and no secret-related IAM is granted. When enabled, the construct grants the Lambda read access to that secret and attaches the AWS Parameters and Secrets Lambda Extension layer, so you do not add either yourself. The secret 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| `targetRegions` | `string[]` | No | Regions to search for tagged RDS resources. Each must be a region enabled for the account. Must not be empty, blank, or contain duplicates. Default: every region enabled for the account. |\n| `notification` | `Notification` | No | Notification channels. Set `notification.slack.enable` to `SlackNotificationEnable.ENABLED` to send Slack messages. |\n| `resourceWait` | `ResourceWait` | No | Per-resource status-check interval and maximum wait. Default: 60-second interval, 1800-second maximum. |\n| `enableScheduling` | `SchedulingEnable` | No | Whether start and stop schedules are enabled. `ENABLED` or `DISABLED`. Default: `ENABLED`. |\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| `failureDetection` | `LambdaFailureDetection` | No | Opt-in CloudWatch failure detection from [lambda-failure-detector](https://www.npmjs.com/package/lambda-failure-detector). Alarms are created only when `enabled` is `true`. `alarmTopic` is an optional existing SNS topic for every alarm. Default: no failure detection resources. |\n\n### Schedule\n\n| Field | Type | Required | Description |\n|-------|------|----------|-------------|\n| `timezone` | `TimeZone` | Yes | CDK timezone constant (for example `TimeZone.ASIA_TOKYO`, `TimeZone.ETC_UTC`). |\n| `minute` | `string` | No | Cron minute (for example `'50'`). |\n| `hour` | `string` | No | Cron hour (for example `'7'`, `'19'`). |\n| `week` | `string` | No | Cron week day (for example `'MON-FRI'`). |\n\n### TargetResource\n\n| Field | Type | Required | Description |\n|-------|------|----------|-------------|\n| `tagKey` | `string` | Yes | Tag key to filter RDS resources. |\n| `tagValues` | `string[]` | Yes | Tag values to match (resources with any of these values are targeted). |\n\n### Notification\n\n| Field | Type | Required | Description |\n|-------|------|----------|-------------|\n| `slack` | `SlackNotification` | No | Slack settings. Omit, or set `enable` to `SlackNotificationEnable.DISABLED`, to disable Slack. |\n\n### SlackNotification\n\n| Field | Type | Required | Description |\n|-------|------|----------|-------------|\n| `enable` | `SlackNotificationEnable` | No | Enable Slack notifications. `ENABLED` or `DISABLED`. Default: `DISABLED`. When `DISABLED`, secret lookup, Slack API calls, and IAM grants are skipped. |\n| `secretName` | `string` | No | Secrets Manager secret name containing Slack `token` and `channel`. Required when `enable` is `ENABLED`. |\n| `notifyOnWaitTimeout` | `WaitTimeoutNotification` | No | Post a Slack message when a resource exceeds `resourceWait.maxSeconds`. `ENABLED` or `DISABLED`. Applies only when `enable` is `ENABLED`. Default: `ENABLED`. |\n\n### ResourceWait\n\n| Field | Type | Required | Description |\n|-------|------|----------|-------------|\n| `intervalSeconds` | `number` | No | Seconds between status checks. Positive integer. Default: `60`. |\n| `maxSeconds` | `number` | No | Maximum accumulated wait seconds for one resource. Positive integer, greater than or equal to `intervalSeconds`, and at most `6900`. A stop that sees `backing-up` before calling stop does not use this budget. Default: `1800`. |\n\n## API\n\nSee [API.md](./API.md).\n\n## Requirements\n\n- **Node.js**: >= 20.0.0\n- **AWS CDK**: ^2.232.0\n- **constructs**: ^10.5.1\n- **lambda-failure-detector**: ^0.2.1 (peer dependency, used only when `failureDetection.enabled` is `true`)\n- **AWS**: Account and region with permissions to create EventBridge Scheduler, Lambda, IAM, and CloudWatch Logs; RDS describe/start/stop permissions for targeted resources. Start/stop IAM is scoped to DB instance and cluster ARNs in the account and to `aws:ResourceTag` matching `targetResource`. Resource Groups Tagging API access (`tag:GetResources`) and `ec2:DescribeRegions` are required for resource discovery. Secrets Manager access is required only when Slack notifications are enabled.\n\n## Notes\n\n- **Least privilege**: Discovery and status checks (`tag:GetResources`, `ec2:DescribeRegions`, `rds:DescribeDBInstances`, `rds:DescribeDBClusters`) do not support resource-level permissions, so they use `*`. Start and stop are limited to DB instance and cluster ARNs in your account and to resources whose `aws:ResourceTag/<tagKey>` matches `targetResource`. The region part of those ARNs is `*` because tagged resources may live outside the stack region.\n- **Safe to run again**: A start on an available resource and a stop on a stopped resource make no RDS call, so a retried or repeated run does not repeat a finished operation.\n- **Retries**: Failed invocations are retried at most twice within 2 hours, which is not configurable via props today. A run that fails because a resource timed out or reported an unexpected status is a failed invocation too.\n\n## Troubleshooting\n\nStart with the Lambda log group (`/aws/lambda/<function name>`). It keeps logs for three months and is retained when the stack is deleted.\n\nWhen nothing seems to happen, check these in order:\n\n1. The schedules were not created with `enableScheduling: SchedulingEnable.DISABLED`.\n2. The resources carry the exact `tagKey` and one of the `tagValues`.\n3. The resources are in a searched region: every enabled region by default, or only `targetRegions` when it is set.\n4. The resource is not a cluster that no longer exists, which is skipped silently. A DB instance that no longer exists fails that resource instead.\n5. A stop of RDS Custom, Aurora Serverless v1, or a global database cluster that cannot be stopped is skipped with a reason in the execution result and, when Slack is enabled, in the thread. That skip does not fail the run.\n6. A database still running after the stop schedule may have been deferred because an automatic backup was in progress. The execution result and, when Slack is enabled, the thread say the next stop schedule will try again. That deferral does not fail the run.\n\nWhen Slack messages are missing, confirm the secret exists, contains `token` and `channel`, and that `notification.slack.enable` is `ENABLED`. A secret that cannot be read fails the run.\n\nWhen `failureDetection.enabled` is `true`, these alarms are created. Each one counts ERROR logs that start with the marker of the same name, in the `RDSDatabaseRunningScheduler` metric namespace:\n\n| Alarm / marker | Meaning |\n|----------------|---------|\n| `ResourceWaitTimedOut` | A resource did not reach its target state within `resourceWait.maxSeconds`. |\n| `ResourceStatusUnexpected` | A resource reported a status that cannot be handled, for example `incompatible-restore`. |\n| `ScheduleExecutionFailed` | The whole execution failed for any reason, including the two above. It also fires for failures before any resource is processed, such as an invalid `targetRegions`. |\n\nThe Lambda `Errors` and `Throttles` alarms cover failures of the invocation itself. A durable execution that fails inside the handler does not always raise `Errors`, so rely on `ScheduleExecutionFailed` for those.\n\n## License\n\nThis project is licensed under the (Apache-2.0) License.\n"
|
|
8475
8475
|
},
|
|
8476
8476
|
"repository": {
|
|
8477
8477
|
"type": "git",
|
|
@@ -8496,7 +8496,7 @@
|
|
|
8496
8496
|
"kind": "interface",
|
|
8497
8497
|
"locationInModule": {
|
|
8498
8498
|
"filename": "src/rds-database-running-scheduler.ts",
|
|
8499
|
-
"line":
|
|
8499
|
+
"line": 119
|
|
8500
8500
|
},
|
|
8501
8501
|
"name": "Notification",
|
|
8502
8502
|
"properties": [
|
|
@@ -8510,7 +8510,7 @@
|
|
|
8510
8510
|
"immutable": true,
|
|
8511
8511
|
"locationInModule": {
|
|
8512
8512
|
"filename": "src/rds-database-running-scheduler.ts",
|
|
8513
|
-
"line":
|
|
8513
|
+
"line": 124
|
|
8514
8514
|
},
|
|
8515
8515
|
"name": "slack",
|
|
8516
8516
|
"optional": true,
|
|
@@ -8602,7 +8602,7 @@
|
|
|
8602
8602
|
"assembly": "rds-database-running-scheduler",
|
|
8603
8603
|
"base": "constructs.Construct",
|
|
8604
8604
|
"docs": {
|
|
8605
|
-
"remarks": "The Lambda lists the regions enabled for the account
|
|
8605
|
+
"remarks": "The Lambda lists the regions enabled for the account and searches each one\nwith the Resource Groups Tagging API, following each page until the last.\n`targetRegions` limits that search. Aurora cluster member instances are\ndeduplicated when the parent cluster is also tagged, and each remaining\nresource is controlled in the region encoded in its ARN.\n\nA resource is checked until it reaches a stable state or its wait limit.\nA stop that finds `backing-up` before calling stop is deferred to the next\nstop schedule. A stop the API would reject (RDS Custom, Aurora Serverless v1,\nor an Aurora global database cluster that is not the only cluster) is skipped.\nBoth outcomes record a reason and do not fail the run. When one resource\nfails, the others are still processed, then the execution fails. A failed\nschedule invocation is retried at most twice, and only while the original\nevent is less than 2 hours old, so a stop failure is not replayed after the\nnext start.\n\nWhen Slack is enabled, the Lambda posts progress, results, skip and defer\nreasons, and, by default, a timeout message. Otherwise Secrets Manager\nlookup, Slack API calls, and related IAM grants are skipped. When\n`failureDetection.enabled` is `true`, CloudWatch alarms watch the Lambda\nand the handler's failure logs.",
|
|
8606
8606
|
"stability": "stable",
|
|
8607
8607
|
"summary": "CDK construct that provisions a durable Lambda workflow and EventBridge schedules to start/stop tagged RDS databases and clusters."
|
|
8608
8608
|
},
|
|
@@ -8614,7 +8614,7 @@
|
|
|
8614
8614
|
},
|
|
8615
8615
|
"locationInModule": {
|
|
8616
8616
|
"filename": "src/rds-database-running-scheduler.ts",
|
|
8617
|
-
"line":
|
|
8617
|
+
"line": 419
|
|
8618
8618
|
},
|
|
8619
8619
|
"parameters": [
|
|
8620
8620
|
{
|
|
@@ -8649,7 +8649,7 @@
|
|
|
8649
8649
|
"kind": "class",
|
|
8650
8650
|
"locationInModule": {
|
|
8651
8651
|
"filename": "src/rds-database-running-scheduler.ts",
|
|
8652
|
-
"line":
|
|
8652
|
+
"line": 405
|
|
8653
8653
|
},
|
|
8654
8654
|
"name": "RDSDatabaseRunningScheduler",
|
|
8655
8655
|
"properties": [
|
|
@@ -8662,7 +8662,7 @@
|
|
|
8662
8662
|
"immutable": true,
|
|
8663
8663
|
"locationInModule": {
|
|
8664
8664
|
"filename": "src/rds-database-running-scheduler.ts",
|
|
8665
|
-
"line":
|
|
8665
|
+
"line": 410
|
|
8666
8666
|
},
|
|
8667
8667
|
"name": "failureDetector",
|
|
8668
8668
|
"optional": true,
|
|
@@ -8684,7 +8684,7 @@
|
|
|
8684
8684
|
"kind": "interface",
|
|
8685
8685
|
"locationInModule": {
|
|
8686
8686
|
"filename": "src/rds-database-running-scheduler.ts",
|
|
8687
|
-
"line":
|
|
8687
|
+
"line": 150
|
|
8688
8688
|
},
|
|
8689
8689
|
"name": "RDSDatabaseRunningSchedulerProps",
|
|
8690
8690
|
"properties": [
|
|
@@ -8697,7 +8697,7 @@
|
|
|
8697
8697
|
"immutable": true,
|
|
8698
8698
|
"locationInModule": {
|
|
8699
8699
|
"filename": "src/rds-database-running-scheduler.ts",
|
|
8700
|
-
"line":
|
|
8700
|
+
"line": 152
|
|
8701
8701
|
},
|
|
8702
8702
|
"name": "targetResource",
|
|
8703
8703
|
"type": {
|
|
@@ -8714,7 +8714,7 @@
|
|
|
8714
8714
|
"immutable": true,
|
|
8715
8715
|
"locationInModule": {
|
|
8716
8716
|
"filename": "src/rds-database-running-scheduler.ts",
|
|
8717
|
-
"line":
|
|
8717
|
+
"line": 164
|
|
8718
8718
|
},
|
|
8719
8719
|
"name": "enableScheduling",
|
|
8720
8720
|
"optional": true,
|
|
@@ -8733,7 +8733,7 @@
|
|
|
8733
8733
|
"immutable": true,
|
|
8734
8734
|
"locationInModule": {
|
|
8735
8735
|
"filename": "src/rds-database-running-scheduler.ts",
|
|
8736
|
-
"line":
|
|
8736
|
+
"line": 192
|
|
8737
8737
|
},
|
|
8738
8738
|
"name": "failureDetection",
|
|
8739
8739
|
"optional": true,
|
|
@@ -8751,7 +8751,7 @@
|
|
|
8751
8751
|
"immutable": true,
|
|
8752
8752
|
"locationInModule": {
|
|
8753
8753
|
"filename": "src/rds-database-running-scheduler.ts",
|
|
8754
|
-
"line":
|
|
8754
|
+
"line": 170
|
|
8755
8755
|
},
|
|
8756
8756
|
"name": "notification",
|
|
8757
8757
|
"optional": true,
|
|
@@ -8769,7 +8769,7 @@
|
|
|
8769
8769
|
"immutable": true,
|
|
8770
8770
|
"locationInModule": {
|
|
8771
8771
|
"filename": "src/rds-database-running-scheduler.ts",
|
|
8772
|
-
"line":
|
|
8772
|
+
"line": 175
|
|
8773
8773
|
},
|
|
8774
8774
|
"name": "resourceWait",
|
|
8775
8775
|
"optional": true,
|
|
@@ -8786,7 +8786,7 @@
|
|
|
8786
8786
|
"immutable": true,
|
|
8787
8787
|
"locationInModule": {
|
|
8788
8788
|
"filename": "src/rds-database-running-scheduler.ts",
|
|
8789
|
-
"line":
|
|
8789
|
+
"line": 179
|
|
8790
8790
|
},
|
|
8791
8791
|
"name": "startSchedule",
|
|
8792
8792
|
"optional": true,
|
|
@@ -8803,7 +8803,7 @@
|
|
|
8803
8803
|
"immutable": true,
|
|
8804
8804
|
"locationInModule": {
|
|
8805
8805
|
"filename": "src/rds-database-running-scheduler.ts",
|
|
8806
|
-
"line":
|
|
8806
|
+
"line": 177
|
|
8807
8807
|
},
|
|
8808
8808
|
"name": "stopSchedule",
|
|
8809
8809
|
"optional": true,
|
|
@@ -8822,7 +8822,7 @@
|
|
|
8822
8822
|
"immutable": true,
|
|
8823
8823
|
"locationInModule": {
|
|
8824
8824
|
"filename": "src/rds-database-running-scheduler.ts",
|
|
8825
|
-
"line":
|
|
8825
|
+
"line": 159
|
|
8826
8826
|
},
|
|
8827
8827
|
"name": "targetRegions",
|
|
8828
8828
|
"optional": true,
|
|
@@ -8849,7 +8849,7 @@
|
|
|
8849
8849
|
"kind": "interface",
|
|
8850
8850
|
"locationInModule": {
|
|
8851
8851
|
"filename": "src/rds-database-running-scheduler.ts",
|
|
8852
|
-
"line":
|
|
8852
|
+
"line": 130
|
|
8853
8853
|
},
|
|
8854
8854
|
"name": "ResourceWait",
|
|
8855
8855
|
"properties": [
|
|
@@ -8864,7 +8864,7 @@
|
|
|
8864
8864
|
"immutable": true,
|
|
8865
8865
|
"locationInModule": {
|
|
8866
8866
|
"filename": "src/rds-database-running-scheduler.ts",
|
|
8867
|
-
"line":
|
|
8867
|
+
"line": 136
|
|
8868
8868
|
},
|
|
8869
8869
|
"name": "intervalSeconds",
|
|
8870
8870
|
"optional": true,
|
|
@@ -8876,14 +8876,14 @@
|
|
|
8876
8876
|
"abstract": true,
|
|
8877
8877
|
"docs": {
|
|
8878
8878
|
"default": "1800",
|
|
8879
|
-
"remarks": "
|
|
8879
|
+
"remarks": "A stop that sees `backing-up` before stop is called does not use this budget.\nMust be a positive integer, greater than or equal to `intervalSeconds`, and at most 6900\nso the limit fires before the 2-hour durable execution timeout.",
|
|
8880
8880
|
"stability": "stable",
|
|
8881
8881
|
"summary": "Maximum accumulated wait seconds for one resource to reach a stable state."
|
|
8882
8882
|
},
|
|
8883
8883
|
"immutable": true,
|
|
8884
8884
|
"locationInModule": {
|
|
8885
8885
|
"filename": "src/rds-database-running-scheduler.ts",
|
|
8886
|
-
"line":
|
|
8886
|
+
"line": 144
|
|
8887
8887
|
},
|
|
8888
8888
|
"name": "maxSeconds",
|
|
8889
8889
|
"optional": true,
|
|
@@ -8905,7 +8905,7 @@
|
|
|
8905
8905
|
"kind": "interface",
|
|
8906
8906
|
"locationInModule": {
|
|
8907
8907
|
"filename": "src/rds-database-running-scheduler.ts",
|
|
8908
|
-
"line":
|
|
8908
|
+
"line": 68
|
|
8909
8909
|
},
|
|
8910
8910
|
"name": "Schedule",
|
|
8911
8911
|
"properties": [
|
|
@@ -8918,7 +8918,7 @@
|
|
|
8918
8918
|
"immutable": true,
|
|
8919
8919
|
"locationInModule": {
|
|
8920
8920
|
"filename": "src/rds-database-running-scheduler.ts",
|
|
8921
|
-
"line":
|
|
8921
|
+
"line": 70
|
|
8922
8922
|
},
|
|
8923
8923
|
"name": "timezone",
|
|
8924
8924
|
"type": {
|
|
@@ -8934,7 +8934,7 @@
|
|
|
8934
8934
|
"immutable": true,
|
|
8935
8935
|
"locationInModule": {
|
|
8936
8936
|
"filename": "src/rds-database-running-scheduler.ts",
|
|
8937
|
-
"line":
|
|
8937
|
+
"line": 74
|
|
8938
8938
|
},
|
|
8939
8939
|
"name": "hour",
|
|
8940
8940
|
"optional": true,
|
|
@@ -8951,7 +8951,7 @@
|
|
|
8951
8951
|
"immutable": true,
|
|
8952
8952
|
"locationInModule": {
|
|
8953
8953
|
"filename": "src/rds-database-running-scheduler.ts",
|
|
8954
|
-
"line":
|
|
8954
|
+
"line": 72
|
|
8955
8955
|
},
|
|
8956
8956
|
"name": "minute",
|
|
8957
8957
|
"optional": true,
|
|
@@ -8968,7 +8968,7 @@
|
|
|
8968
8968
|
"immutable": true,
|
|
8969
8969
|
"locationInModule": {
|
|
8970
8970
|
"filename": "src/rds-database-running-scheduler.ts",
|
|
8971
|
-
"line":
|
|
8971
|
+
"line": 76
|
|
8972
8972
|
},
|
|
8973
8973
|
"name": "week",
|
|
8974
8974
|
"optional": true,
|
|
@@ -8989,7 +8989,7 @@
|
|
|
8989
8989
|
"kind": "enum",
|
|
8990
8990
|
"locationInModule": {
|
|
8991
8991
|
"filename": "src/rds-database-running-scheduler.ts",
|
|
8992
|
-
"line":
|
|
8992
|
+
"line": 48
|
|
8993
8993
|
},
|
|
8994
8994
|
"members": [
|
|
8995
8995
|
{
|
|
@@ -9022,7 +9022,7 @@
|
|
|
9022
9022
|
"kind": "interface",
|
|
9023
9023
|
"locationInModule": {
|
|
9024
9024
|
"filename": "src/rds-database-running-scheduler.ts",
|
|
9025
|
-
"line":
|
|
9025
|
+
"line": 93
|
|
9026
9026
|
},
|
|
9027
9027
|
"name": "SlackNotification",
|
|
9028
9028
|
"properties": [
|
|
@@ -9037,7 +9037,7 @@
|
|
|
9037
9037
|
"immutable": true,
|
|
9038
9038
|
"locationInModule": {
|
|
9039
9039
|
"filename": "src/rds-database-running-scheduler.ts",
|
|
9040
|
-
"line":
|
|
9040
|
+
"line": 100
|
|
9041
9041
|
},
|
|
9042
9042
|
"name": "enable",
|
|
9043
9043
|
"optional": true,
|
|
@@ -9055,7 +9055,7 @@
|
|
|
9055
9055
|
"immutable": true,
|
|
9056
9056
|
"locationInModule": {
|
|
9057
9057
|
"filename": "src/rds-database-running-scheduler.ts",
|
|
9058
|
-
"line":
|
|
9058
|
+
"line": 111
|
|
9059
9059
|
},
|
|
9060
9060
|
"name": "notifyOnWaitTimeout",
|
|
9061
9061
|
"optional": true,
|
|
@@ -9073,7 +9073,7 @@
|
|
|
9073
9073
|
"immutable": true,
|
|
9074
9074
|
"locationInModule": {
|
|
9075
9075
|
"filename": "src/rds-database-running-scheduler.ts",
|
|
9076
|
-
"line":
|
|
9076
|
+
"line": 105
|
|
9077
9077
|
},
|
|
9078
9078
|
"name": "secretName",
|
|
9079
9079
|
"optional": true,
|
|
@@ -9094,7 +9094,7 @@
|
|
|
9094
9094
|
"kind": "enum",
|
|
9095
9095
|
"locationInModule": {
|
|
9096
9096
|
"filename": "src/rds-database-running-scheduler.ts",
|
|
9097
|
-
"line":
|
|
9097
|
+
"line": 38
|
|
9098
9098
|
},
|
|
9099
9099
|
"members": [
|
|
9100
9100
|
{
|
|
@@ -9126,7 +9126,7 @@
|
|
|
9126
9126
|
"kind": "interface",
|
|
9127
9127
|
"locationInModule": {
|
|
9128
9128
|
"filename": "src/rds-database-running-scheduler.ts",
|
|
9129
|
-
"line":
|
|
9129
|
+
"line": 82
|
|
9130
9130
|
},
|
|
9131
9131
|
"name": "TargetResource",
|
|
9132
9132
|
"properties": [
|
|
@@ -9139,7 +9139,7 @@
|
|
|
9139
9139
|
"immutable": true,
|
|
9140
9140
|
"locationInModule": {
|
|
9141
9141
|
"filename": "src/rds-database-running-scheduler.ts",
|
|
9142
|
-
"line":
|
|
9142
|
+
"line": 84
|
|
9143
9143
|
},
|
|
9144
9144
|
"name": "tagKey",
|
|
9145
9145
|
"type": {
|
|
@@ -9155,7 +9155,7 @@
|
|
|
9155
9155
|
"immutable": true,
|
|
9156
9156
|
"locationInModule": {
|
|
9157
9157
|
"filename": "src/rds-database-running-scheduler.ts",
|
|
9158
|
-
"line":
|
|
9158
|
+
"line": 86
|
|
9159
9159
|
},
|
|
9160
9160
|
"name": "tagValues",
|
|
9161
9161
|
"type": {
|
|
@@ -9180,7 +9180,7 @@
|
|
|
9180
9180
|
"kind": "enum",
|
|
9181
9181
|
"locationInModule": {
|
|
9182
9182
|
"filename": "src/rds-database-running-scheduler.ts",
|
|
9183
|
-
"line":
|
|
9183
|
+
"line": 58
|
|
9184
9184
|
},
|
|
9185
9185
|
"members": [
|
|
9186
9186
|
{
|
|
@@ -9202,6 +9202,6 @@
|
|
|
9202
9202
|
"symbolId": "src/rds-database-running-scheduler:WaitTimeoutNotification"
|
|
9203
9203
|
}
|
|
9204
9204
|
},
|
|
9205
|
-
"version": "0.
|
|
9206
|
-
"fingerprint": "
|
|
9205
|
+
"version": "0.7.1",
|
|
9206
|
+
"fingerprint": "PLNB9iTyXC2FgaziBSrTSzSOxQHUtdLDQ8H4yIykEWo="
|
|
9207
9207
|
}
|
package/API.md
CHANGED
|
@@ -4,21 +4,31 @@
|
|
|
4
4
|
|
|
5
5
|
### RDSDatabaseRunningScheduler <a name="RDSDatabaseRunningScheduler" id="rds-database-running-scheduler.RDSDatabaseRunningScheduler"></a>
|
|
6
6
|
|
|
7
|
+
- *Implements:* constructs.IConstruct, constructs.IDependable
|
|
8
|
+
|
|
7
9
|
CDK construct that provisions a durable Lambda workflow and EventBridge schedules to start/stop tagged RDS databases and clusters.
|
|
8
10
|
|
|
9
|
-
The Lambda lists the regions enabled for the account
|
|
10
|
-
the Resource Groups Tagging API
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
11
|
+
The Lambda lists the regions enabled for the account and searches each one
|
|
12
|
+
with the Resource Groups Tagging API, following each page until the last.
|
|
13
|
+
`targetRegions` limits that search. Aurora cluster member instances are
|
|
14
|
+
deduplicated when the parent cluster is also tagged, and each remaining
|
|
15
|
+
resource is controlled in the region encoded in its ARN.
|
|
16
|
+
|
|
17
|
+
A resource is checked until it reaches a stable state or its wait limit.
|
|
18
|
+
A stop that finds `backing-up` before calling stop is deferred to the next
|
|
19
|
+
stop schedule. A stop the API would reject (RDS Custom, Aurora Serverless v1,
|
|
20
|
+
or an Aurora global database cluster that is not the only cluster) is skipped.
|
|
21
|
+
Both outcomes record a reason and do not fail the run. When one resource
|
|
22
|
+
fails, the others are still processed, then the execution fails. A failed
|
|
15
23
|
schedule invocation is retried at most twice, and only while the original
|
|
16
24
|
event is less than 2 hours old, so a stop failure is not replayed after the
|
|
17
|
-
next start.
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
25
|
+
next start.
|
|
26
|
+
|
|
27
|
+
When Slack is enabled, the Lambda posts progress, results, skip and defer
|
|
28
|
+
reasons, and, by default, a timeout message. Otherwise Secrets Manager
|
|
29
|
+
lookup, Slack API calls, and related IAM grants are skipped. When
|
|
30
|
+
`failureDetection.enabled` is `true`, CloudWatch alarms watch the Lambda
|
|
31
|
+
and the handler's failure logs.
|
|
22
32
|
|
|
23
33
|
#### Initializers <a name="Initializers" id="rds-database-running-scheduler.RDSDatabaseRunningScheduler.Initializer"></a>
|
|
24
34
|
|
|
@@ -176,6 +186,8 @@ Undefined unless `failureDetection.enabled` is `true`.
|
|
|
176
186
|
|
|
177
187
|
### RDSDatabaseRunningScheduleStack <a name="RDSDatabaseRunningScheduleStack" id="rds-database-running-scheduler.RDSDatabaseRunningScheduleStack"></a>
|
|
178
188
|
|
|
189
|
+
- *Implements:* constructs.IConstruct, constructs.IDependable, aws-cdk-lib.ITaggable
|
|
190
|
+
|
|
179
191
|
CDK stack that provisions scheduled start/stop control for tagged RDS resources in the enabled regions of the deployment account, or only in `targetRegions`.
|
|
180
192
|
|
|
181
193
|
Delegates resource discovery, cluster-priority deduplication, start/stop
|
|
@@ -1764,6 +1776,7 @@ public readonly maxSeconds: number;
|
|
|
1764
1776
|
|
|
1765
1777
|
Maximum accumulated wait seconds for one resource to reach a stable state.
|
|
1766
1778
|
|
|
1779
|
+
A stop that sees `backing-up` before stop is called does not use this budget.
|
|
1767
1780
|
Must be a positive integer, greater than or equal to `intervalSeconds`, and at most 6900
|
|
1768
1781
|
so the limit fires before the 2-hour durable execution timeout.
|
|
1769
1782
|
|
package/README.md
CHANGED
|
@@ -20,19 +20,23 @@ This AWS CDK construct controls the start and stop of RDS DB instances and Auror
|
|
|
20
20
|
- **Configurable wait**: Set `resourceWait.intervalSeconds` and `resourceWait.maxSeconds` to control how often each resource is checked and how long the function waits before timing out. Defaults are 60 seconds and 1800 seconds.
|
|
21
21
|
- **Optional Slack notifications**: Set `notification.slack.enable` to `SlackNotificationEnable.ENABLED` and provide `secretName` to post schedule progress and per-resource results to Slack via Secrets Manager. Leave `enable` unset (default `SlackNotificationEnable.DISABLED`), set it to `DISABLED`, or omit `notification.slack` to skip secret lookup, Slack API calls, and related IAM grants. When Slack is enabled, a timeout posts a message unless `notification.slack.notifyOnWaitTimeout` is `WaitTimeoutNotification.DISABLED`.
|
|
22
22
|
- **Opt-in failure detection**: Set `failureDetection.enabled` to `true` to create CloudWatch alarms for the Lambda `Errors` and `Throttles` metrics and for the handler's failure logs (wait timeout, unexpected status, failed execution). Pass an existing SNS topic as `failureDetection.alarmTopic` to be notified. Nothing is created by default, and the construct never creates an SNS topic.
|
|
23
|
+
- **Stop skips unsupported configurations**: A stop leaves RDS Custom, Aurora Serverless v1, and Aurora global database clusters that are not the only cluster in that global database running. The execution result and Slack include the reason. A start still runs them.
|
|
24
|
+
- **Backup defers a stop**: A stop that finds `backing-up` before calling stop waits for the next stop schedule instead of timing out. The result and Slack include the reason. A start still waits through `backing-up`.
|
|
23
25
|
- **Supported resources**: RDS DB instances and RDS Aurora clusters.
|
|
24
26
|
|
|
25
27
|
## How it works
|
|
26
28
|
|
|
27
|
-
EventBridge Scheduler runs a start cron and a stop cron. Each one invokes a durable Lambda function. A failed invocation is retried at most twice, and only while the original event is less than 2 hours old. That window matches the durable execution timeout and is not configurable via props today. On the default schedule
|
|
29
|
+
EventBridge Scheduler runs a start cron and a stop cron. Each one invokes a durable Lambda function. A failed invocation is retried at most twice, and only while the original event is less than 2 hours old. That window matches the durable execution timeout. One invocation times out after 15 minutes, and the execution history is kept for 1 day. The invocation timeout, the execution timeout, and the history retention are not configurable via props today. On the default schedule the retry window ends before the opposite cron, so a failed stop is not run again after the next start.
|
|
28
30
|
|
|
29
|
-
The function lists the regions enabled for the account and searches each one with the Resource Groups Tagging API for RDS DB instances and Aurora clusters that match `targetResource`. The Tagging API returns only the resources of the region it is called in, so each region is searched separately. When `targetRegions` is set, only those regions are searched. When both a cluster and its member instances match, only the cluster is controlled. Each remaining resource is started or stopped in the region taken from its ARN.
|
|
31
|
+
The function lists the regions enabled for the account and searches each one with the Resource Groups Tagging API for RDS DB instances and Aurora clusters that match `targetResource`. The Tagging API returns only the resources of the region it is called in, so each region is searched separately. Each `GetResources` call returns at most 100 matches, and the function follows `PaginationToken` until the last page before it deduplicates. When `targetRegions` is set, only those regions are searched. When both a cluster and its member instances match, only the cluster is controlled. Each remaining resource is started or stopped in the region taken from its ARN.
|
|
30
32
|
|
|
31
|
-
The function then checks that resource every `resourceWait.intervalSeconds` until it is available or stopped, or until `resourceWait.maxSeconds` elapses. A stop also waits through `storage-optimization`. A start that sees `storage-optimization` waits until the status is `stopped`, then starts the database. `configuring-iam-database-auth` and `configuring-log-exports` are waited on the same way. When Slack is enabled, it posts progress and, by default, a message when the wait limit is exceeded.
|
|
33
|
+
The function then checks that resource every `resourceWait.intervalSeconds` until it is available or stopped, or until `resourceWait.maxSeconds` elapses. A stop also waits through `storage-optimization`. A start that sees `storage-optimization` waits until the status is `stopped`, then starts the database. `configuring-iam-database-auth` and `configuring-log-exports` are waited on the same way. A stop that sees `backing-up` before it calls stop does not wait and does not fail. The result status is `deferred`, and the reason says the next stop schedule will try again. When Slack is enabled, that reason is posted in the thread. A start still waits through `backing-up`. After stop has been called, a later `backing-up` status is waited on like any other transition. When Slack is enabled, it posts progress and, by default, a message when the wait limit is exceeded.
|
|
32
34
|
|
|
33
35
|
Some cases change nothing. When no resource matches, the run ends without posting to Slack. A resource that is already in the target state (available for a start, stopped for a stop) gets no start or stop call, but Slack still receives its result message. A cluster that no longer exists is skipped without a failure and without a result message. Both schedules can also be created in the disabled state with `enableScheduling`.
|
|
34
36
|
|
|
35
|
-
A
|
|
37
|
+
A stop skips a configuration the stop API rejects, and the run does not fail because of that skip. An RDS Custom instance has an engine name that starts with `custom-`. An Aurora Serverless v1 cluster has `EngineMode` `serverless`. An Aurora global database cluster is skipped when `EngineMode` is `global`, or when `GlobalClusterIdentifier` is set and the cluster has read replicas or no writer. The only cluster in a global database, and Aurora Serverless v2 (`EngineMode` `provisioned`), are still stopped. The result status is `skipped` and includes the reason. When Slack is enabled, that reason is posted in the thread. A start still runs these resources.
|
|
38
|
+
|
|
39
|
+
A resource that does not reach its target state within the wait limit, reports a status that cannot be handled (for example `incompatible-restore`), or is a DB instance that no longer exists, is a failed resource. The run still starts or stops every other resource and posts that resource's Slack message before the execution is marked as failed. The execution error names up to 10 failed resources. The log lists every failed resource and its error, separate from the failure-detection markers.
|
|
36
40
|
|
|
37
41
|
The Lambda log group keeps logs for three months. It is deleted only when its creation fails, and it is retained when the stack is deleted or the resource is replaced, so failures stay investigable.
|
|
38
42
|
|
|
@@ -201,7 +205,7 @@ Slack is optional. Only when `notification.slack.enable` is `SlackNotificationEn
|
|
|
201
205
|
| Field | Type | Required | Description |
|
|
202
206
|
|-------|------|----------|-------------|
|
|
203
207
|
| `intervalSeconds` | `number` | No | Seconds between status checks. Positive integer. Default: `60`. |
|
|
204
|
-
| `maxSeconds` | `number` | No | Maximum accumulated wait seconds for one resource. Positive integer, greater than or equal to `intervalSeconds`, and at most `6900`. Default: `1800`. |
|
|
208
|
+
| `maxSeconds` | `number` | No | Maximum accumulated wait seconds for one resource. Positive integer, greater than or equal to `intervalSeconds`, and at most `6900`. A stop that sees `backing-up` before calling stop does not use this budget. Default: `1800`. |
|
|
205
209
|
|
|
206
210
|
## API
|
|
207
211
|
|
|
@@ -230,7 +234,9 @@ When nothing seems to happen, check these in order:
|
|
|
230
234
|
1. The schedules were not created with `enableScheduling: SchedulingEnable.DISABLED`.
|
|
231
235
|
2. The resources carry the exact `tagKey` and one of the `tagValues`.
|
|
232
236
|
3. The resources are in a searched region: every enabled region by default, or only `targetRegions` when it is set.
|
|
233
|
-
4. The resource is not a cluster that no longer exists, which is skipped silently.
|
|
237
|
+
4. The resource is not a cluster that no longer exists, which is skipped silently. A DB instance that no longer exists fails that resource instead.
|
|
238
|
+
5. A stop of RDS Custom, Aurora Serverless v1, or a global database cluster that cannot be stopped is skipped with a reason in the execution result and, when Slack is enabled, in the thread. That skip does not fail the run.
|
|
239
|
+
6. A database still running after the stop schedule may have been deferred because an automatic backup was in progress. The execution result and, when Slack is enabled, the thread say the next stop schedule will try again. That deferral does not fail the run.
|
|
234
240
|
|
|
235
241
|
When Slack messages are missing, confirm the secret exists, contains `token` and `channel`, and that `notification.slack.enable` is `ENABLED`. A secret that cannot be read fails the run.
|
|
236
242
|
|