rds-database-auto-start-preventer 0.5.2 → 0.6.0
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 +65 -19
- package/API.md +84 -2
- package/README.md +40 -2
- package/assets/funcs/auto-start-prevent.lambda/index.js +3540 -939
- package/assets/funcs/auto-start-prevent.lambda/index.js.map +4 -4
- package/lib/funcs/auto-start-prevent-function.js +2 -2
- package/lib/funcs/auto-start-prevent.lambda.d.ts +1 -0
- package/lib/funcs/auto-start-prevent.lambda.js +132 -94
- package/lib/funcs/core/auto-start-prevent.predicates.d.ts +28 -9
- package/lib/funcs/core/auto-start-prevent.predicates.js +44 -17
- package/lib/rds-database-auto-start-prevent-stack.d.ts +1 -1
- package/lib/rds-database-auto-start-prevent-stack.js +4 -3
- package/lib/rds-database-auto-start-preventer.d.ts +19 -1
- package/lib/rds-database-auto-start-preventer.js +71 -80
- package/lib/settings/consts.d.ts +19 -0
- package/lib/settings/consts.js +23 -0
- package/package.json +9 -6
package/.jsii
CHANGED
|
@@ -8,7 +8,8 @@
|
|
|
8
8
|
},
|
|
9
9
|
"dependencies": {
|
|
10
10
|
"aws-cdk-lib": "^2.232.0",
|
|
11
|
-
"constructs": "^10.5.1"
|
|
11
|
+
"constructs": "^10.5.1",
|
|
12
|
+
"lambda-failure-detector": "^0.2.3"
|
|
12
13
|
},
|
|
13
14
|
"dependencyClosure": {
|
|
14
15
|
"@aws-cdk/asset-awscli-v1": {
|
|
@@ -8433,6 +8434,13 @@
|
|
|
8433
8434
|
"module": "constructs"
|
|
8434
8435
|
}
|
|
8435
8436
|
}
|
|
8437
|
+
},
|
|
8438
|
+
"lambda-failure-detector": {
|
|
8439
|
+
"targets": {
|
|
8440
|
+
"js": {
|
|
8441
|
+
"npm": "lambda-failure-detector"
|
|
8442
|
+
}
|
|
8443
|
+
}
|
|
8436
8444
|
}
|
|
8437
8445
|
},
|
|
8438
8446
|
"description": "CDK construct library that stops RDS DB instances and clusters after they are auto-started by AWS (RDS-EVENT-0154 / RDS-EVENT-0153), using EventBridge and a Durable Lambda to filter by tags in the handler, stop matching available resources, and post to Slack only after a successful stop when a Slack secret name is set.",
|
|
@@ -8440,7 +8448,7 @@
|
|
|
8440
8448
|
"stability": "stable"
|
|
8441
8449
|
},
|
|
8442
8450
|
"homepage": "https://github.com/gammarers-aws-cdk-constructs/rds-database-auto-start-preventer.git",
|
|
8443
|
-
"jsiiVersion": "6.0.
|
|
8451
|
+
"jsiiVersion": "6.0.21 (build c0277eb)",
|
|
8444
8452
|
"keywords": [
|
|
8445
8453
|
"aws",
|
|
8446
8454
|
"aws-cdk",
|
|
@@ -8459,7 +8467,7 @@
|
|
|
8459
8467
|
},
|
|
8460
8468
|
"name": "rds-database-auto-start-preventer",
|
|
8461
8469
|
"readme": {
|
|
8462
|
-
"markdown": "# RDS Database Auto Start Preventer (CDK v2)\n\n[](https://www.npmjs.com/package/rds-database-auto-start-preventer)\n[](https://www.npmjs.com/package/rds-database-auto-start-preventer)\n[](https://www.npmjs.com/package/rds-database-auto-start-preventer)\n[](https://github.com/gammarers-aws-cdk-constructs/rds-database-auto-start-preventer/actions/workflows/build.yml)\n\n[](https://constructs.dev/packages/rds-database-auto-start-preventer)\n\nCDK construct library that stops RDS DB instances and clusters after they are auto-started by AWS (RDS-EVENT-0154 / RDS-EVENT-0153). It uses EventBridge rules and a Durable Lambda to detect auto-start events, filter resources by tags in the handler, stop matching resources when they are `available`, and post a Slack notification only when this Lambda invoked the stop API successfully and a Slack secret name is set.\n\n## Features\n\n- **EventBridge integration** – Listens for RDS DB Instance (RDS-EVENT-0154) and DB Cluster (RDS-EVENT-0153) auto-start events\n- **Handler-side tag filtering** – EventBridge rules match all auto-start events; the Lambda evaluates `TagList` from `rds:DescribeDBInstances` / `rds:DescribeDBClusters`. Tag mismatch is a no-op (no StopDB*, no Slack)\n- **Durable Lambda** – Uses AWS Lambda Durable Execution for a long-running workflow (initial wait, status wait, stop, and post-stop wait) with a 2-hour execution timeout\n- **Least-privilege IAM** – Describe is scoped to account/region `db` / `cluster` ARNs; Stop is further limited by `aws:ResourceTag` matching `tagKey` / `tagValues` (no Resource Groups Tagging API)\n- **Slack notifications** – When `slackSecretName` is set, sends a message when this invocation called `StopDBInstance` / `StopDBCluster` and the resource reached `stopped` (no notification when the secret name is omitted, the resource was already stopped, or tags did not match)\n- **Optional rule toggle** – EventBridge rules can be enabled or disabled via `enableRule`\n\n## How it works\n\n1. EventBridge invokes the Durable Lambda with the RDS auto-start event and tag filter parameters (`tagKey`, `tagValues`).\n2. The handler waits **1 minute**, then calls DescribeDB* until the resource leaves transitional statuses. While the status stays transitional (or stopping after StopDB*), it waits up to **5 minutes** between describes.\n3. If the resource tag does not match, the handler exits as a **no-op** (no StopDB*, no Slack).\n4. If the resource is `available` and tags match, the handler calls StopDB* and waits until `stopped` (again using up to 5-minute intervals while transitional).\n5. If the resource is already `stopped` (for example, stopped by another process), the handler exits without calling StopDB* and without posting to Slack.\n6. When `slackSecretName` is set, Slack is notified only when StopDB* was invoked by this invocation and the resource reached `stopped`. When it is omitted, the handler does not post to Slack.\n\nTiming defaults (not configurable via props today):\n\n| Setting | Value |\n|---------|-------|\n| Initial wait before the first describe | 1 minute |\n| Wait between describes while status is transitional / stopping | up to 5 minutes |\n| Lambda invocation `timeout` | 15 minutes |\n| Durable `executionTimeout` | 2 hours |\n| Durable history `retentionPeriod` | 1 day |\n\nTag the RDS instances or clusters you want to protect (for example, `AutoStartPrevent=YES`). Resources without a matching tag are left running (no-op).\n\n## Installation\n\n### npm\n\n```bash\nnpm install rds-database-auto-start-preventer\n```\n\n### yarn\n\n```bash\nyarn add rds-database-auto-start-preventer\n```\n\n### pnpm\n\n```bash\npnpm add rds-database-auto-start-preventer\n```\n\n## Usage\n\n### Minimal deployable app\n\nUse `RDSDatabaseAutoStartPreventStack` when you want a dedicated stack you can deploy as-is. Put this in your CDK app entry (for example `bin/app.ts`), then deploy.\n\n```typescript\nimport { App } from 'aws-cdk-lib';\nimport { RDSDatabaseAutoStartPreventStack } from 'rds-database-auto-start-preventer';\n\nconst app = new App();\n\nnew RDSDatabaseAutoStartPreventStack(app, 'RDSDatabaseAutoStartPreventStack', {\n env: {\n account: process.env.CDK_DEFAULT_ACCOUNT,\n region: process.env.CDK_DEFAULT_REGION,\n },\n stackName: 'rds-database-auto-start-prevent',\n targetResource: {\n tagKey: 'AutoStartPrevent',\n tagValues: ['YES'],\n },\n // Omit slackSecretName to skip Slack; set it when stop should notify Slack.\n secrets: {\n slackSecretName: 'my-app/slack',\n },\n});\n\napp.synth();\n```\n\nDeploy checklist:\n\n1. Install this package and peers (`aws-cdk-lib`, `constructs`) in your CDK app.\n2. Tag the RDS instances or clusters to protect (for example `AutoStartPrevent=YES`).\n3. Optional: create the Secrets Manager secret described in [Slack secret](#slack-secret-aws-secrets-manager). Omit `slackSecretName` if you do not need Slack.\n4. From the CDK app: `npx cdk deploy RDSDatabaseAutoStartPreventStack`\n\n### Construct in an existing stack\n\nUse `RDSDatabaseAutoStartPreventer` when you want to add auto-start prevention to an existing stack or compose it with other constructs. Omit `slackSecretName` to stop matching resources without Slack.\n\n```typescript\nimport { App, Stack } from 'aws-cdk-lib';\nimport { RDSDatabaseAutoStartPreventer } from 'rds-database-auto-start-preventer';\n\nconst app = new App();\nconst stack = new Stack(app, 'MyStack');\n\nnew RDSDatabaseAutoStartPreventer(stack, 'RDSDatabaseAutoStartPreventer', {\n targetResource: {\n tagKey: 'AutoStartPrevent',\n tagValues: ['YES'],\n },\n secrets: {},\n});\n```\n\nPass `slackSecretName` when a successful stop should post to Slack. `enableRule` defaults to `true`.\n\n```typescript\nnew RDSDatabaseAutoStartPreventer(stack, 'RDSDatabaseAutoStartPreventer', {\n targetResource: {\n tagKey: 'AutoStartPrevent',\n tagValues: ['YES'],\n },\n enableRule: true,\n secrets: {\n slackSecretName: 'my-app/slack',\n },\n});\n```\n\n### Slack secret (AWS Secrets Manager)\n\nCreate the secret **before** deploy when you want Slack notifications. Omit `slackSecretName` to skip Slack entirely (no secret and no Secrets Manager IAM are required in that case).\n\nStore a JSON object in AWS Secrets Manager with the Slack Bot Token and channel ID:\n\n| Key | Value |\n|-----|-------|\n| `token` | Slack Bot Token (e.g. `xoxb-...`) |\n| `channel` | Slack channel ID (e.g. `C01234ABCD`) |\n\nExample secret value:\n\n```json\n{\n \"token\": \"xoxb-...\",\n \"channel\": \"C01234ABCD\"\n}\n```\n\nWhen `slackSecretName` is set, the construct grants the Lambda role read access to that secret and attaches the AWS Parameters and Secrets Extension. You do not need to add a separate Secrets Manager policy yourself for this secret.\n\n## Options\n\n| Option | Type | Required | Description |\n|--------|------|----------|-------------|\n| `targetResource` | `TargetResource` | Yes | Tag-based criteria evaluated in the Lambda handler. |\n| `targetResource.tagKey` | `string` | Yes | Tag key to match (e.g. `AutoStartPrevent`, `Environment`). |\n| `targetResource.tagValues` | `string[]` | Yes | Tag values that indicate the resource should be stopped (e.g. `['YES']`, `['production']`). |\n| `enableRule` | `boolean` | No | Whether the EventBridge rules are enabled. Defaults to `true` if omitted. |\n| `secrets` | `Secrets` | Yes | External secrets for notifications. |\n| `secrets.slackSecretName` | `string` | No | Name of the Secrets Manager secret containing Slack `token` and `channel`. Omit it to skip Slack notifications. |\n\nEmpty `tagKey`, an empty `tagValues` array (or blank entries), and a blank `slackSecretName` fail at synthesis. Omitting `slackSecretName` is allowed. Unresolved CDK tokens are not checked.\n\n## API\n\nSee [API.md](./API.md).\n\n## Requirements\n\n- **Node.js** >= 20.0.0 (for your CDK app)\n- **AWS CDK** ^2.232.0\n- **constructs** ^10.5.1\n- **AWS Lambda** runtime Node.js 24.x with Durable Execution (deployed by the construct)\n\n## Notes\n\n- **Aurora / dual events:** An Aurora auto-start can emit both a DB cluster event (`RDS-EVENT-0153`) and DB instance event(s) (`RDS-EVENT-0154`). This package listens for both and may run separate Durable executions. Tag mismatch remains a no-op; if the resource is already `stopped`, the handler does not call StopDB* and does not post to Slack.\n- **IAM:** RDS Describe is limited to account/region `db` / `cluster` ARNs. Stop requires a matching `aws:ResourceTag` for your `tagKey` / `tagValues`. Slack secret read is granted only when `slackSecretName` is set.\n\n## Troubleshooting\n\n- **CloudWatch Logs:** The construct creates a dedicated Log Group for the Durable Lambda (JSON logs, 3-month retention). After a successful create, the log group uses `RetainExceptOnCreate` so it remains available for incident review after stack delete or replace.\n- **Nothing stopped / no Slack:** Confirm the resource tag matches `tagKey` / `tagValues`. Mismatch is intentional no-op with no Slack message.\n- **Stop attempted but Slack missing:** Slack runs only when this invocation called StopDB* and the resource reached `stopped`, and only when `slackSecretName` is set. Already-stopped resources skip Slack.\n- **Secret errors:** Ensure the secret exists before deploy, JSON has non-empty `token` and `channel`, and the name passed as `slackSecretName` matches Secrets Manager.\n\n## License\n\nThis project is licensed under the Apache-2.0 License.\n"
|
|
8470
|
+
"markdown": "# RDS Database Auto Start Preventer (CDK v2)\n\n[](https://www.npmjs.com/package/rds-database-auto-start-preventer)\n[](https://www.npmjs.com/package/rds-database-auto-start-preventer)\n[](https://www.npmjs.com/package/rds-database-auto-start-preventer)\n[](https://github.com/gammarers-aws-cdk-constructs/rds-database-auto-start-preventer/actions/workflows/build.yml)\n\n[](https://constructs.dev/packages/rds-database-auto-start-preventer)\n\nCDK construct library that stops RDS DB instances and clusters after they are auto-started by AWS (RDS-EVENT-0154 / RDS-EVENT-0153). It uses EventBridge rules and a Durable Lambda to detect auto-start events, filter resources by tags in the handler, stop matching resources when they are `available`, and post a Slack notification only when this Lambda invoked the stop API successfully and a Slack secret name is set.\n\n## Features\n\n- **EventBridge integration** – Listens for RDS DB Instance (RDS-EVENT-0154) and DB Cluster (RDS-EVENT-0153) auto-start events\n- **Handler-side tag filtering** – EventBridge rules match all auto-start events; the Lambda evaluates `TagList` from `rds:DescribeDBInstances` / `rds:DescribeDBClusters`. Tag mismatch is a no-op (no StopDB*, no Slack)\n- **Durable Lambda** – Uses AWS Lambda Durable Execution for a long-running workflow (initial wait, status wait, stop, and post-stop wait) with a 2-hour execution timeout\n- **Least-privilege IAM** – Describe is scoped to account/region `db` / `cluster` ARNs; Stop is further limited by `aws:ResourceTag` matching `tagKey` / `tagValues` (no Resource Groups Tagging API)\n- **Slack notifications** – When `slackSecretName` is set, sends a message when this invocation called `StopDBInstance` / `StopDBCluster` and the resource reached `stopped` (no notification when the secret name is omitted, the resource was already stopped, or tags did not match)\n- **Optional rule toggle** – EventBridge rules can be enabled or disabled via `enableRule`\n- **Optional failure detection** – With `failureDetection.enabled`, creates CloudWatch alarms for Lambda errors, throttles, and failed executions, notifying an existing SNS topic when one is passed\n\n## How it works\n\n1. EventBridge invokes the Durable Lambda with the RDS auto-start event and tag filter parameters (`tagKey`, `tagValues`).\n2. The handler waits **1 minute**, then calls DescribeDB* until the resource leaves transitional statuses. While the status stays transitional (or stopping after StopDB*), it waits up to **5 minutes** between describes.\n3. If the resource tag does not match, the handler exits as a **no-op** (no StopDB*, no Slack).\n4. If the resource is `available` and tags match, the handler calls StopDB* and waits until `stopped` (again using up to 5-minute intervals while transitional).\n5. If the resource is already `stopped` (for example, stopped by another process), the handler exits without calling StopDB* and without posting to Slack.\n6. When `slackSecretName` is set, Slack is notified only when StopDB* was invoked by this invocation and the resource reached `stopped`. When it is omitted, the handler does not post to Slack.\n7. If the execution fails (invalid input or Slack secret, unexpected RDS status, stop not reaching `stopped`, or Slack post failure), the handler logs `AutoStartPreventFailed` with the DB identifier and error message, and the durable execution ends as failed. With `failureDetection.enabled`, this log raises a CloudWatch alarm.\n\nTiming defaults (not configurable via props today):\n\n| Setting | Value |\n|---------|-------|\n| Initial wait before the first describe | 1 minute |\n| Wait between describes while status is transitional / stopping | up to 5 minutes |\n| Lambda invocation `timeout` | 3 minutes |\n| Durable `executionTimeout` | 2 hours |\n| Durable history `retentionPeriod` | 1 day |\n\nTag the RDS instances or clusters you want to protect (for example, `AutoStartPrevent=YES`). Resources without a matching tag are left running (no-op).\n\n## Installation\n\n### npm\n\n```bash\nnpm install rds-database-auto-start-preventer\n```\n\n### yarn\n\n```bash\nyarn add rds-database-auto-start-preventer\n```\n\n### pnpm\n\n```bash\npnpm add rds-database-auto-start-preventer\n```\n\n## Usage\n\n### Minimal deployable app\n\nUse `RDSDatabaseAutoStartPreventStack` when you want a dedicated stack you can deploy as-is. Put this in your CDK app entry (for example `bin/app.ts`), then deploy.\n\n```typescript\nimport { App } from 'aws-cdk-lib';\nimport { RDSDatabaseAutoStartPreventStack } from 'rds-database-auto-start-preventer';\n\nconst app = new App();\n\nnew RDSDatabaseAutoStartPreventStack(app, 'RDSDatabaseAutoStartPreventStack', {\n env: {\n account: process.env.CDK_DEFAULT_ACCOUNT,\n region: process.env.CDK_DEFAULT_REGION,\n },\n stackName: 'rds-database-auto-start-prevent',\n targetResource: {\n tagKey: 'AutoStartPrevent',\n tagValues: ['YES'],\n },\n // Omit slackSecretName to skip Slack; set it when stop should notify Slack.\n secrets: {\n slackSecretName: 'my-app/slack',\n },\n});\n\napp.synth();\n```\n\nDeploy checklist:\n\n1. Install this package and peers (`aws-cdk-lib`, `constructs`, `lambda-failure-detector`) in your CDK app.\n2. Tag the RDS instances or clusters to protect (for example `AutoStartPrevent=YES`).\n3. Optional: create the Secrets Manager secret described in [Slack secret](#slack-secret-aws-secrets-manager). Omit `slackSecretName` if you do not need Slack.\n4. From the CDK app: `npx cdk deploy RDSDatabaseAutoStartPreventStack`\n\n### Construct in an existing stack\n\nUse `RDSDatabaseAutoStartPreventer` when you want to add auto-start prevention to an existing stack or compose it with other constructs. Omit `slackSecretName` to stop matching resources without Slack.\n\n```typescript\nimport { App, Stack } from 'aws-cdk-lib';\nimport { RDSDatabaseAutoStartPreventer } from 'rds-database-auto-start-preventer';\n\nconst app = new App();\nconst stack = new Stack(app, 'MyStack');\n\nnew RDSDatabaseAutoStartPreventer(stack, 'RDSDatabaseAutoStartPreventer', {\n targetResource: {\n tagKey: 'AutoStartPrevent',\n tagValues: ['YES'],\n },\n secrets: {},\n});\n```\n\nPass `slackSecretName` when a successful stop should post to Slack. `enableRule` defaults to `true`.\n\n```typescript\nnew RDSDatabaseAutoStartPreventer(stack, 'RDSDatabaseAutoStartPreventer', {\n targetResource: {\n tagKey: 'AutoStartPrevent',\n tagValues: ['YES'],\n },\n enableRule: true,\n secrets: {\n slackSecretName: 'my-app/slack',\n },\n});\n```\n\n### Failure detection (CloudWatch alarms)\n\nFailure detection is off by default. Set `failureDetection.enabled` to `true` to create the alarms. The construct does not create an SNS topic: pass an existing topic as `alarmTopic` to receive notifications, or omit it to create alarms without actions.\n\n```typescript\nimport { Topic } from 'aws-cdk-lib/aws-sns';\n\nconst alarmTopic = new Topic(stack, 'AlarmTopic');\n\nnew RDSDatabaseAutoStartPreventer(stack, 'RDSDatabaseAutoStartPreventer', {\n targetResource: {\n tagKey: 'AutoStartPrevent',\n tagValues: ['YES'],\n },\n secrets: {},\n failureDetection: {\n enabled: true,\n alarmTopic,\n },\n});\n```\n\nAlarms created when enabled (threshold 1 in a 5-minute period):\n\n| Alarm | Metric | Fires when |\n|-------|--------|------------|\n| Lambda errors | `AWS/Lambda` `Errors` | An invocation fails at the platform level (for example a crash or invocation timeout). |\n| Lambda throttles | `AWS/Lambda` `Throttles` | An invocation is throttled. |\n| Failed execution | `RDSDatabaseAutoStartPreventer` `AutoStartPreventFailed` | The handler logs `AutoStartPreventFailed` because the durable execution failed (invalid input or Slack secret, unexpected RDS status, stop not reaching `stopped`, or Slack post failure after retries). |\n\n### Slack secret (AWS Secrets Manager)\n\nCreate the secret **before** deploy when you want Slack notifications. Omit `slackSecretName` to skip Slack entirely (no secret and no Secrets Manager IAM are required in that case).\n\nStore a JSON object in AWS Secrets Manager with the Slack Bot Token and channel ID:\n\n| Key | Value |\n|-----|-------|\n| `token` | Slack Bot Token (e.g. `xoxb-...`) |\n| `channel` | Slack channel ID (e.g. `C01234ABCD`) |\n\nExample secret value:\n\n```json\n{\n \"token\": \"xoxb-...\",\n \"channel\": \"C01234ABCD\"\n}\n```\n\nWhen `slackSecretName` is set, the construct grants the Lambda role read access to that secret and attaches the AWS Parameters and Secrets Extension. You do not need to add a separate Secrets Manager policy yourself for this secret.\n\n## Options\n\n| Option | Type | Required | Description |\n|--------|------|----------|-------------|\n| `targetResource` | `TargetResource` | Yes | Tag-based criteria evaluated in the Lambda handler. |\n| `targetResource.tagKey` | `string` | Yes | Tag key to match (e.g. `AutoStartPrevent`, `Environment`). |\n| `targetResource.tagValues` | `string[]` | Yes | Tag values that indicate the resource should be stopped (e.g. `['YES']`, `['production']`). |\n| `enableRule` | `boolean` | No | Whether the EventBridge rules are enabled. Defaults to `true` if omitted. |\n| `secrets` | `Secrets` | Yes | External secrets for notifications. |\n| `secrets.slackSecretName` | `string` | No | Name of the Secrets Manager secret containing Slack `token` and `channel`. Omit it to skip Slack notifications. |\n| `failureDetection` | `AutoStartPreventFailureDetectionProps` | No | CloudWatch failure detection for the Lambda. No alarms when omitted. |\n| `failureDetection.enabled` | `boolean` | No | Creates the failure alarms only when `true`. |\n| `failureDetection.alarmTopic` | `ITopic` | No | Existing SNS topic notified by every alarm. Alarms have no actions when omitted. |\n\nEmpty `tagKey`, an empty `tagValues` array (or blank entries), and a blank `slackSecretName` fail at synthesis. Omitting `slackSecretName` is allowed. Unresolved CDK tokens are not checked.\n\n## API\n\nSee [API.md](./API.md).\n\n## Requirements\n\n- **Node.js** >= 20.0.0 (for your CDK app)\n- **AWS CDK** ^2.232.0\n- **constructs** ^10.5.1\n- **lambda-failure-detector** ^0.2.3 (peer dependency, used for `failureDetection`)\n- **AWS Lambda** runtime Node.js 24.x with Durable Execution (deployed by the construct)\n\n## Notes\n\n- **Aurora / dual events:** An Aurora auto-start can emit both a DB cluster event (`RDS-EVENT-0153`) and DB instance event(s) (`RDS-EVENT-0154`). This package listens for both and may run separate Durable executions. Tag mismatch remains a no-op; if the resource is already `stopped`, the handler does not call StopDB* and does not post to Slack.\n- **IAM:** RDS Describe is limited to account/region `db` / `cluster` ARNs. Stop requires a matching `aws:ResourceTag` for your `tagKey` / `tagValues`. Slack secret read is granted only when `slackSecretName` is set.\n- **Failure alarms:** A failed durable execution ends the invocation normally, so it does not raise the Lambda `Errors` metric. The `AutoStartPreventFailed` log alarm covers those failures. The log line contains the DB identifier and error message, never the Slack token or channel.\n\n## Troubleshooting\n\n- **CloudWatch Logs:** The construct creates a dedicated Log Group for the Durable Lambda (JSON logs, 3-month retention). After a successful create, the log group uses `RetainExceptOnCreate` so it remains available for incident review after stack delete or replace.\n- **Nothing stopped / no Slack:** Confirm the resource tag matches `tagKey` / `tagValues`. Mismatch is intentional no-op with no Slack message.\n- **Stop attempted but Slack missing:** Slack runs only when this invocation called StopDB* and the resource reached `stopped`, and only when `slackSecretName` is set. Already-stopped resources skip Slack.\n- **`AutoStartPreventFailed` alarm:** Search the Lambda log group for `AutoStartPreventFailed` to find the DB identifier and error message of the failed execution.\n- **Secret errors:** Ensure the secret exists before deploy, JSON has non-empty `token` and `channel`, and the name passed as `slackSecretName` matches Secrets Manager.\n\n## License\n\nThis project is licensed under the Apache-2.0 License.\n"
|
|
8463
8471
|
},
|
|
8464
8472
|
"repository": {
|
|
8465
8473
|
"type": "git",
|
|
@@ -8472,6 +8480,26 @@
|
|
|
8472
8480
|
}
|
|
8473
8481
|
},
|
|
8474
8482
|
"types": {
|
|
8483
|
+
"rds-database-auto-start-preventer.AutoStartPreventFailureDetectionProps": {
|
|
8484
|
+
"assembly": "rds-database-auto-start-preventer",
|
|
8485
|
+
"datatype": true,
|
|
8486
|
+
"docs": {
|
|
8487
|
+
"remarks": "When `enabled` is true, creates alarms on the Lambda `Errors` and `Throttles` metrics and on\nfailed executions logged by the handler (custom metric `RDSDatabaseAutoStartPreventer` / `AutoStartPreventFailed`).\nNo SNS topic is created; alarms notify `alarmTopic` only when it is set.",
|
|
8488
|
+
"stability": "stable",
|
|
8489
|
+
"summary": "Opt-in CloudWatch failure detection for the auto-start prevent Lambda."
|
|
8490
|
+
},
|
|
8491
|
+
"fqn": "rds-database-auto-start-preventer.AutoStartPreventFailureDetectionProps",
|
|
8492
|
+
"interfaces": [
|
|
8493
|
+
"lambda-failure-detector.LambdaFailureDetection"
|
|
8494
|
+
],
|
|
8495
|
+
"kind": "interface",
|
|
8496
|
+
"locationInModule": {
|
|
8497
|
+
"filename": "src/rds-database-auto-start-preventer.ts",
|
|
8498
|
+
"line": 70
|
|
8499
|
+
},
|
|
8500
|
+
"name": "AutoStartPreventFailureDetectionProps",
|
|
8501
|
+
"symbolId": "src/rds-database-auto-start-preventer:AutoStartPreventFailureDetectionProps"
|
|
8502
|
+
},
|
|
8475
8503
|
"rds-database-auto-start-preventer.RDSDatabaseAutoStartPreventStack": {
|
|
8476
8504
|
"assembly": "rds-database-auto-start-preventer",
|
|
8477
8505
|
"base": "aws-cdk-lib.Stack",
|
|
@@ -8510,7 +8538,7 @@
|
|
|
8510
8538
|
},
|
|
8511
8539
|
{
|
|
8512
8540
|
"docs": {
|
|
8513
|
-
"summary": "- Stack props (target resource, enable rule, secrets)."
|
|
8541
|
+
"summary": "- Stack props (target resource, enable rule, secrets, failure detection)."
|
|
8514
8542
|
},
|
|
8515
8543
|
"name": "props",
|
|
8516
8544
|
"type": {
|
|
@@ -8551,7 +8579,7 @@
|
|
|
8551
8579
|
"assembly": "rds-database-auto-start-preventer",
|
|
8552
8580
|
"base": "constructs.Construct",
|
|
8553
8581
|
"docs": {
|
|
8554
|
-
"remarks": "EventBridge rules match all auto-start events; tag filtering runs in the handler\nusing `TagList` from `rds:DescribeDBInstances` / `rds:DescribeDBClusters`.\nIAM grants account/region-scoped describe on `db` / `cluster` ARNs, and stop only\nwhen `aws:ResourceTag` matches {@link TargetResource} (no Resource Groups Tagging API).",
|
|
8582
|
+
"remarks": "EventBridge rules match all auto-start events; tag filtering runs in the handler\nusing `TagList` from `rds:DescribeDBInstances` / `rds:DescribeDBClusters`.\nIAM grants account/region-scoped describe on `db` / `cluster` ARNs, and stop only\nwhen `aws:ResourceTag` matches {@link TargetResource} (no Resource Groups Tagging API).\nCloudWatch failure alarms are created only when\n{@link RDSDatabaseAutoStartPreventerProps.failureDetection} is enabled.",
|
|
8555
8583
|
"stability": "stable",
|
|
8556
8584
|
"summary": "Deploys EventBridge rules and a Durable Lambda to stop matching RDS resources after auto-start events (RDS-EVENT-0154 / RDS-EVENT-0153)."
|
|
8557
8585
|
},
|
|
@@ -8563,11 +8591,11 @@
|
|
|
8563
8591
|
},
|
|
8564
8592
|
"remarks": "The Lambda receives `{ event, params }` where `params` carries `tagKey` and `tagValues`\nfrom {@link RDSDatabaseAutoStartPreventerProps.targetResource}. Tag filters are passed\nonly via that payload (not via `TAG_KEY` / `TAG_VALUES` environment variables).",
|
|
8565
8593
|
"stability": "stable",
|
|
8566
|
-
"summary": "Creates the Durable Lambda, EventBridge rules, and
|
|
8594
|
+
"summary": "Creates the Durable Lambda, EventBridge rules, IAM policies, and optional failure alarms."
|
|
8567
8595
|
},
|
|
8568
8596
|
"locationInModule": {
|
|
8569
8597
|
"filename": "src/rds-database-auto-start-preventer.ts",
|
|
8570
|
-
"line":
|
|
8598
|
+
"line": 149
|
|
8571
8599
|
},
|
|
8572
8600
|
"parameters": [
|
|
8573
8601
|
{
|
|
@@ -8602,7 +8630,7 @@
|
|
|
8602
8630
|
"kind": "class",
|
|
8603
8631
|
"locationInModule": {
|
|
8604
8632
|
"filename": "src/rds-database-auto-start-preventer.ts",
|
|
8605
|
-
"line":
|
|
8633
|
+
"line": 135
|
|
8606
8634
|
},
|
|
8607
8635
|
"name": "RDSDatabaseAutoStartPreventer",
|
|
8608
8636
|
"symbolId": "src/rds-database-auto-start-preventer:RDSDatabaseAutoStartPreventer"
|
|
@@ -8618,7 +8646,7 @@
|
|
|
8618
8646
|
"kind": "interface",
|
|
8619
8647
|
"locationInModule": {
|
|
8620
8648
|
"filename": "src/rds-database-auto-start-preventer.ts",
|
|
8621
|
-
"line":
|
|
8649
|
+
"line": 75
|
|
8622
8650
|
},
|
|
8623
8651
|
"name": "RDSDatabaseAutoStartPreventerProps",
|
|
8624
8652
|
"properties": [
|
|
@@ -8631,7 +8659,7 @@
|
|
|
8631
8659
|
"immutable": true,
|
|
8632
8660
|
"locationInModule": {
|
|
8633
8661
|
"filename": "src/rds-database-auto-start-preventer.ts",
|
|
8634
|
-
"line":
|
|
8662
|
+
"line": 81
|
|
8635
8663
|
},
|
|
8636
8664
|
"name": "secrets",
|
|
8637
8665
|
"type": {
|
|
@@ -8647,7 +8675,7 @@
|
|
|
8647
8675
|
"immutable": true,
|
|
8648
8676
|
"locationInModule": {
|
|
8649
8677
|
"filename": "src/rds-database-auto-start-preventer.ts",
|
|
8650
|
-
"line":
|
|
8678
|
+
"line": 77
|
|
8651
8679
|
},
|
|
8652
8680
|
"name": "targetResource",
|
|
8653
8681
|
"type": {
|
|
@@ -8664,13 +8692,31 @@
|
|
|
8664
8692
|
"immutable": true,
|
|
8665
8693
|
"locationInModule": {
|
|
8666
8694
|
"filename": "src/rds-database-auto-start-preventer.ts",
|
|
8667
|
-
"line":
|
|
8695
|
+
"line": 79
|
|
8668
8696
|
},
|
|
8669
8697
|
"name": "enableRule",
|
|
8670
8698
|
"optional": true,
|
|
8671
8699
|
"type": {
|
|
8672
8700
|
"primitive": "boolean"
|
|
8673
8701
|
}
|
|
8702
|
+
},
|
|
8703
|
+
{
|
|
8704
|
+
"abstract": true,
|
|
8705
|
+
"docs": {
|
|
8706
|
+
"default": "no alarms",
|
|
8707
|
+
"stability": "stable",
|
|
8708
|
+
"summary": "CloudWatch failure detection for the Lambda."
|
|
8709
|
+
},
|
|
8710
|
+
"immutable": true,
|
|
8711
|
+
"locationInModule": {
|
|
8712
|
+
"filename": "src/rds-database-auto-start-preventer.ts",
|
|
8713
|
+
"line": 87
|
|
8714
|
+
},
|
|
8715
|
+
"name": "failureDetection",
|
|
8716
|
+
"optional": true,
|
|
8717
|
+
"type": {
|
|
8718
|
+
"fqn": "rds-database-auto-start-preventer.AutoStartPreventFailureDetectionProps"
|
|
8719
|
+
}
|
|
8674
8720
|
}
|
|
8675
8721
|
],
|
|
8676
8722
|
"symbolId": "src/rds-database-auto-start-preventer:RDSDatabaseAutoStartPreventerProps"
|
|
@@ -8686,7 +8732,7 @@
|
|
|
8686
8732
|
"kind": "interface",
|
|
8687
8733
|
"locationInModule": {
|
|
8688
8734
|
"filename": "src/rds-database-auto-start-preventer.ts",
|
|
8689
|
-
"line":
|
|
8735
|
+
"line": 55
|
|
8690
8736
|
},
|
|
8691
8737
|
"name": "Secrets",
|
|
8692
8738
|
"properties": [
|
|
@@ -8700,7 +8746,7 @@
|
|
|
8700
8746
|
"immutable": true,
|
|
8701
8747
|
"locationInModule": {
|
|
8702
8748
|
"filename": "src/rds-database-auto-start-preventer.ts",
|
|
8703
|
-
"line":
|
|
8749
|
+
"line": 60
|
|
8704
8750
|
},
|
|
8705
8751
|
"name": "slackSecretName",
|
|
8706
8752
|
"optional": true,
|
|
@@ -8723,7 +8769,7 @@
|
|
|
8723
8769
|
"kind": "interface",
|
|
8724
8770
|
"locationInModule": {
|
|
8725
8771
|
"filename": "src/rds-database-auto-start-preventer.ts",
|
|
8726
|
-
"line":
|
|
8772
|
+
"line": 44
|
|
8727
8773
|
},
|
|
8728
8774
|
"name": "TargetResource",
|
|
8729
8775
|
"properties": [
|
|
@@ -8736,7 +8782,7 @@
|
|
|
8736
8782
|
"immutable": true,
|
|
8737
8783
|
"locationInModule": {
|
|
8738
8784
|
"filename": "src/rds-database-auto-start-preventer.ts",
|
|
8739
|
-
"line":
|
|
8785
|
+
"line": 46
|
|
8740
8786
|
},
|
|
8741
8787
|
"name": "tagKey",
|
|
8742
8788
|
"type": {
|
|
@@ -8752,7 +8798,7 @@
|
|
|
8752
8798
|
"immutable": true,
|
|
8753
8799
|
"locationInModule": {
|
|
8754
8800
|
"filename": "src/rds-database-auto-start-preventer.ts",
|
|
8755
|
-
"line":
|
|
8801
|
+
"line": 48
|
|
8756
8802
|
},
|
|
8757
8803
|
"name": "tagValues",
|
|
8758
8804
|
"type": {
|
|
@@ -8768,6 +8814,6 @@
|
|
|
8768
8814
|
"symbolId": "src/rds-database-auto-start-preventer:TargetResource"
|
|
8769
8815
|
}
|
|
8770
8816
|
},
|
|
8771
|
-
"version": "0.
|
|
8772
|
-
"fingerprint": "
|
|
8817
|
+
"version": "0.6.0",
|
|
8818
|
+
"fingerprint": "tCB64hT1n6oAbF9gHEPApTXJCuBCu/bOu/Q4ScG9SGc="
|
|
8773
8819
|
}
|
package/API.md
CHANGED
|
@@ -10,6 +10,8 @@ EventBridge rules match all auto-start events; tag filtering runs in the handler
|
|
|
10
10
|
using `TagList` from `rds:DescribeDBInstances` / `rds:DescribeDBClusters`.
|
|
11
11
|
IAM grants account/region-scoped describe on `db` / `cluster` ARNs, and stop only
|
|
12
12
|
when `aws:ResourceTag` matches {@link TargetResource} (no Resource Groups Tagging API).
|
|
13
|
+
CloudWatch failure alarms are created only when
|
|
14
|
+
{@link RDSDatabaseAutoStartPreventerProps.failureDetection} is enabled.
|
|
13
15
|
|
|
14
16
|
#### Initializers <a name="Initializers" id="rds-database-auto-start-preventer.RDSDatabaseAutoStartPreventer.Initializer"></a>
|
|
15
17
|
|
|
@@ -166,7 +168,7 @@ new RDSDatabaseAutoStartPreventStack(scope: Construct, id: string, props: RDSDat
|
|
|
166
168
|
| --- | --- | --- |
|
|
167
169
|
| <code><a href="#rds-database-auto-start-preventer.RDSDatabaseAutoStartPreventStack.Initializer.parameter.scope">scope</a></code> | <code>constructs.Construct</code> | - Parent construct. |
|
|
168
170
|
| <code><a href="#rds-database-auto-start-preventer.RDSDatabaseAutoStartPreventStack.Initializer.parameter.id">id</a></code> | <code>string</code> | - Stack id. |
|
|
169
|
-
| <code><a href="#rds-database-auto-start-preventer.RDSDatabaseAutoStartPreventStack.Initializer.parameter.props">props</a></code> | <code><a href="#rds-database-auto-start-preventer.RDSDatabaseAutoStartPreventStackProps">RDSDatabaseAutoStartPreventStackProps</a></code> | - Stack props (target resource, enable rule, secrets). |
|
|
171
|
+
| <code><a href="#rds-database-auto-start-preventer.RDSDatabaseAutoStartPreventStack.Initializer.parameter.props">props</a></code> | <code><a href="#rds-database-auto-start-preventer.RDSDatabaseAutoStartPreventStackProps">RDSDatabaseAutoStartPreventStackProps</a></code> | - Stack props (target resource, enable rule, secrets, failure detection). |
|
|
170
172
|
|
|
171
173
|
---
|
|
172
174
|
|
|
@@ -190,7 +192,7 @@ Stack id.
|
|
|
190
192
|
|
|
191
193
|
- *Type:* <a href="#rds-database-auto-start-preventer.RDSDatabaseAutoStartPreventStackProps">RDSDatabaseAutoStartPreventStackProps</a>
|
|
192
194
|
|
|
193
|
-
Stack props (target resource, enable rule, secrets).
|
|
195
|
+
Stack props (target resource, enable rule, secrets, failure detection).
|
|
194
196
|
|
|
195
197
|
---
|
|
196
198
|
|
|
@@ -1109,6 +1111,58 @@ Whether termination protection is enabled for this stack.
|
|
|
1109
1111
|
|
|
1110
1112
|
## Structs <a name="Structs" id="Structs"></a>
|
|
1111
1113
|
|
|
1114
|
+
### AutoStartPreventFailureDetectionProps <a name="AutoStartPreventFailureDetectionProps" id="rds-database-auto-start-preventer.AutoStartPreventFailureDetectionProps"></a>
|
|
1115
|
+
|
|
1116
|
+
Opt-in CloudWatch failure detection for the auto-start prevent Lambda.
|
|
1117
|
+
|
|
1118
|
+
When `enabled` is true, creates alarms on the Lambda `Errors` and `Throttles` metrics and on
|
|
1119
|
+
failed executions logged by the handler (custom metric `RDSDatabaseAutoStartPreventer` / `AutoStartPreventFailed`).
|
|
1120
|
+
No SNS topic is created; alarms notify `alarmTopic` only when it is set.
|
|
1121
|
+
|
|
1122
|
+
#### Initializer <a name="Initializer" id="rds-database-auto-start-preventer.AutoStartPreventFailureDetectionProps.Initializer"></a>
|
|
1123
|
+
|
|
1124
|
+
```typescript
|
|
1125
|
+
import { AutoStartPreventFailureDetectionProps } from 'rds-database-auto-start-preventer'
|
|
1126
|
+
|
|
1127
|
+
const autoStartPreventFailureDetectionProps: AutoStartPreventFailureDetectionProps = { ... }
|
|
1128
|
+
```
|
|
1129
|
+
|
|
1130
|
+
#### Properties <a name="Properties" id="Properties"></a>
|
|
1131
|
+
|
|
1132
|
+
| **Name** | **Type** | **Description** |
|
|
1133
|
+
| --- | --- | --- |
|
|
1134
|
+
| <code><a href="#rds-database-auto-start-preventer.AutoStartPreventFailureDetectionProps.property.alarmTopic">alarmTopic</a></code> | <code>aws-cdk-lib.aws_sns.ITopic</code> | SNS topic for alarm notifications. |
|
|
1135
|
+
| <code><a href="#rds-database-auto-start-preventer.AutoStartPreventFailureDetectionProps.property.enabled">enabled</a></code> | <code>boolean</code> | When true, creates failure detection alarms and log-based metrics. |
|
|
1136
|
+
|
|
1137
|
+
---
|
|
1138
|
+
|
|
1139
|
+
##### `alarmTopic`<sup>Optional</sup> <a name="alarmTopic" id="rds-database-auto-start-preventer.AutoStartPreventFailureDetectionProps.property.alarmTopic"></a>
|
|
1140
|
+
|
|
1141
|
+
```typescript
|
|
1142
|
+
public readonly alarmTopic: ITopic;
|
|
1143
|
+
```
|
|
1144
|
+
|
|
1145
|
+
- *Type:* aws-cdk-lib.aws_sns.ITopic
|
|
1146
|
+
|
|
1147
|
+
SNS topic for alarm notifications.
|
|
1148
|
+
|
|
1149
|
+
When omitted, alarms are created without SNS actions.
|
|
1150
|
+
|
|
1151
|
+
---
|
|
1152
|
+
|
|
1153
|
+
##### `enabled`<sup>Optional</sup> <a name="enabled" id="rds-database-auto-start-preventer.AutoStartPreventFailureDetectionProps.property.enabled"></a>
|
|
1154
|
+
|
|
1155
|
+
```typescript
|
|
1156
|
+
public readonly enabled: boolean;
|
|
1157
|
+
```
|
|
1158
|
+
|
|
1159
|
+
- *Type:* boolean
|
|
1160
|
+
- *Default:* false when omitted
|
|
1161
|
+
|
|
1162
|
+
When true, creates failure detection alarms and log-based metrics.
|
|
1163
|
+
|
|
1164
|
+
---
|
|
1165
|
+
|
|
1112
1166
|
### RDSDatabaseAutoStartPreventerProps <a name="RDSDatabaseAutoStartPreventerProps" id="rds-database-auto-start-preventer.RDSDatabaseAutoStartPreventerProps"></a>
|
|
1113
1167
|
|
|
1114
1168
|
Props for the RDS database auto-start preventer construct.
|
|
@@ -1128,6 +1182,7 @@ const rDSDatabaseAutoStartPreventerProps: RDSDatabaseAutoStartPreventerProps = {
|
|
|
1128
1182
|
| <code><a href="#rds-database-auto-start-preventer.RDSDatabaseAutoStartPreventerProps.property.secrets">secrets</a></code> | <code><a href="#rds-database-auto-start-preventer.Secrets">Secrets</a></code> | Secrets used for notifications (e.g. Slack). |
|
|
1129
1183
|
| <code><a href="#rds-database-auto-start-preventer.RDSDatabaseAutoStartPreventerProps.property.targetResource">targetResource</a></code> | <code><a href="#rds-database-auto-start-preventer.TargetResource">TargetResource</a></code> | Tag-based target resource criteria for RDS instances/clusters to protect. |
|
|
1130
1184
|
| <code><a href="#rds-database-auto-start-preventer.RDSDatabaseAutoStartPreventerProps.property.enableRule">enableRule</a></code> | <code>boolean</code> | Whether the EventBridge rules are enabled. |
|
|
1185
|
+
| <code><a href="#rds-database-auto-start-preventer.RDSDatabaseAutoStartPreventerProps.property.failureDetection">failureDetection</a></code> | <code><a href="#rds-database-auto-start-preventer.AutoStartPreventFailureDetectionProps">AutoStartPreventFailureDetectionProps</a></code> | CloudWatch failure detection for the Lambda. |
|
|
1131
1186
|
|
|
1132
1187
|
---
|
|
1133
1188
|
|
|
@@ -1169,6 +1224,19 @@ Defaults to true if omitted.
|
|
|
1169
1224
|
|
|
1170
1225
|
---
|
|
1171
1226
|
|
|
1227
|
+
##### `failureDetection`<sup>Optional</sup> <a name="failureDetection" id="rds-database-auto-start-preventer.RDSDatabaseAutoStartPreventerProps.property.failureDetection"></a>
|
|
1228
|
+
|
|
1229
|
+
```typescript
|
|
1230
|
+
public readonly failureDetection: AutoStartPreventFailureDetectionProps;
|
|
1231
|
+
```
|
|
1232
|
+
|
|
1233
|
+
- *Type:* <a href="#rds-database-auto-start-preventer.AutoStartPreventFailureDetectionProps">AutoStartPreventFailureDetectionProps</a>
|
|
1234
|
+
- *Default:* no alarms
|
|
1235
|
+
|
|
1236
|
+
CloudWatch failure detection for the Lambda.
|
|
1237
|
+
|
|
1238
|
+
---
|
|
1239
|
+
|
|
1172
1240
|
### RDSDatabaseAutoStartPreventStackProps <a name="RDSDatabaseAutoStartPreventStackProps" id="rds-database-auto-start-preventer.RDSDatabaseAutoStartPreventStackProps"></a>
|
|
1173
1241
|
|
|
1174
1242
|
Props for the RDS database auto start prevent CDK stack.
|
|
@@ -1188,6 +1256,7 @@ const rDSDatabaseAutoStartPreventStackProps: RDSDatabaseAutoStartPreventStackPro
|
|
|
1188
1256
|
| <code><a href="#rds-database-auto-start-preventer.RDSDatabaseAutoStartPreventStackProps.property.secrets">secrets</a></code> | <code><a href="#rds-database-auto-start-preventer.Secrets">Secrets</a></code> | Secrets used for notifications (e.g. Slack). |
|
|
1189
1257
|
| <code><a href="#rds-database-auto-start-preventer.RDSDatabaseAutoStartPreventStackProps.property.targetResource">targetResource</a></code> | <code><a href="#rds-database-auto-start-preventer.TargetResource">TargetResource</a></code> | Tag-based target resource criteria for RDS instances/clusters to protect. |
|
|
1190
1258
|
| <code><a href="#rds-database-auto-start-preventer.RDSDatabaseAutoStartPreventStackProps.property.enableRule">enableRule</a></code> | <code>boolean</code> | Whether the EventBridge rules are enabled. |
|
|
1259
|
+
| <code><a href="#rds-database-auto-start-preventer.RDSDatabaseAutoStartPreventStackProps.property.failureDetection">failureDetection</a></code> | <code><a href="#rds-database-auto-start-preventer.AutoStartPreventFailureDetectionProps">AutoStartPreventFailureDetectionProps</a></code> | CloudWatch failure detection for the Lambda. |
|
|
1191
1260
|
| <code><a href="#rds-database-auto-start-preventer.RDSDatabaseAutoStartPreventStackProps.property.analyticsReporting">analyticsReporting</a></code> | <code>boolean</code> | Include runtime versioning information in this Stack. |
|
|
1192
1261
|
| <code><a href="#rds-database-auto-start-preventer.RDSDatabaseAutoStartPreventStackProps.property.crossRegionReferences">crossRegionReferences</a></code> | <code>boolean</code> | Enable this flag to allow native cross region stack references. |
|
|
1193
1262
|
| <code><a href="#rds-database-auto-start-preventer.RDSDatabaseAutoStartPreventStackProps.property.description">description</a></code> | <code>string</code> | A description of the stack. |
|
|
@@ -1241,6 +1310,19 @@ Defaults to true if omitted.
|
|
|
1241
1310
|
|
|
1242
1311
|
---
|
|
1243
1312
|
|
|
1313
|
+
##### `failureDetection`<sup>Optional</sup> <a name="failureDetection" id="rds-database-auto-start-preventer.RDSDatabaseAutoStartPreventStackProps.property.failureDetection"></a>
|
|
1314
|
+
|
|
1315
|
+
```typescript
|
|
1316
|
+
public readonly failureDetection: AutoStartPreventFailureDetectionProps;
|
|
1317
|
+
```
|
|
1318
|
+
|
|
1319
|
+
- *Type:* <a href="#rds-database-auto-start-preventer.AutoStartPreventFailureDetectionProps">AutoStartPreventFailureDetectionProps</a>
|
|
1320
|
+
- *Default:* no alarms
|
|
1321
|
+
|
|
1322
|
+
CloudWatch failure detection for the Lambda.
|
|
1323
|
+
|
|
1324
|
+
---
|
|
1325
|
+
|
|
1244
1326
|
##### `analyticsReporting`<sup>Optional</sup> <a name="analyticsReporting" id="rds-database-auto-start-preventer.RDSDatabaseAutoStartPreventStackProps.property.analyticsReporting"></a>
|
|
1245
1327
|
|
|
1246
1328
|
```typescript
|
package/README.md
CHANGED
|
@@ -17,6 +17,7 @@ CDK construct library that stops RDS DB instances and clusters after they are au
|
|
|
17
17
|
- **Least-privilege IAM** – Describe is scoped to account/region `db` / `cluster` ARNs; Stop is further limited by `aws:ResourceTag` matching `tagKey` / `tagValues` (no Resource Groups Tagging API)
|
|
18
18
|
- **Slack notifications** – When `slackSecretName` is set, sends a message when this invocation called `StopDBInstance` / `StopDBCluster` and the resource reached `stopped` (no notification when the secret name is omitted, the resource was already stopped, or tags did not match)
|
|
19
19
|
- **Optional rule toggle** – EventBridge rules can be enabled or disabled via `enableRule`
|
|
20
|
+
- **Optional failure detection** – With `failureDetection.enabled`, creates CloudWatch alarms for Lambda errors, throttles, and failed executions, notifying an existing SNS topic when one is passed
|
|
20
21
|
|
|
21
22
|
## How it works
|
|
22
23
|
|
|
@@ -26,6 +27,7 @@ CDK construct library that stops RDS DB instances and clusters after they are au
|
|
|
26
27
|
4. If the resource is `available` and tags match, the handler calls StopDB* and waits until `stopped` (again using up to 5-minute intervals while transitional).
|
|
27
28
|
5. If the resource is already `stopped` (for example, stopped by another process), the handler exits without calling StopDB* and without posting to Slack.
|
|
28
29
|
6. When `slackSecretName` is set, Slack is notified only when StopDB* was invoked by this invocation and the resource reached `stopped`. When it is omitted, the handler does not post to Slack.
|
|
30
|
+
7. If the execution fails (invalid input or Slack secret, unexpected RDS status, stop not reaching `stopped`, or Slack post failure), the handler logs `AutoStartPreventFailed` with the DB identifier and error message, and the durable execution ends as failed. With `failureDetection.enabled`, this log raises a CloudWatch alarm.
|
|
29
31
|
|
|
30
32
|
Timing defaults (not configurable via props today):
|
|
31
33
|
|
|
@@ -33,7 +35,7 @@ Timing defaults (not configurable via props today):
|
|
|
33
35
|
|---------|-------|
|
|
34
36
|
| Initial wait before the first describe | 1 minute |
|
|
35
37
|
| Wait between describes while status is transitional / stopping | up to 5 minutes |
|
|
36
|
-
| Lambda invocation `timeout` |
|
|
38
|
+
| Lambda invocation `timeout` | 3 minutes |
|
|
37
39
|
| Durable `executionTimeout` | 2 hours |
|
|
38
40
|
| Durable history `retentionPeriod` | 1 day |
|
|
39
41
|
|
|
@@ -92,7 +94,7 @@ app.synth();
|
|
|
92
94
|
|
|
93
95
|
Deploy checklist:
|
|
94
96
|
|
|
95
|
-
1. Install this package and peers (`aws-cdk-lib`, `constructs`) in your CDK app.
|
|
97
|
+
1. Install this package and peers (`aws-cdk-lib`, `constructs`, `lambda-failure-detector`) in your CDK app.
|
|
96
98
|
2. Tag the RDS instances or clusters to protect (for example `AutoStartPrevent=YES`).
|
|
97
99
|
3. Optional: create the Secrets Manager secret described in [Slack secret](#slack-secret-aws-secrets-manager). Omit `slackSecretName` if you do not need Slack.
|
|
98
100
|
4. From the CDK app: `npx cdk deploy RDSDatabaseAutoStartPreventStack`
|
|
@@ -132,6 +134,36 @@ new RDSDatabaseAutoStartPreventer(stack, 'RDSDatabaseAutoStartPreventer', {
|
|
|
132
134
|
});
|
|
133
135
|
```
|
|
134
136
|
|
|
137
|
+
### Failure detection (CloudWatch alarms)
|
|
138
|
+
|
|
139
|
+
Failure detection is off by default. Set `failureDetection.enabled` to `true` to create the alarms. The construct does not create an SNS topic: pass an existing topic as `alarmTopic` to receive notifications, or omit it to create alarms without actions.
|
|
140
|
+
|
|
141
|
+
```typescript
|
|
142
|
+
import { Topic } from 'aws-cdk-lib/aws-sns';
|
|
143
|
+
|
|
144
|
+
const alarmTopic = new Topic(stack, 'AlarmTopic');
|
|
145
|
+
|
|
146
|
+
new RDSDatabaseAutoStartPreventer(stack, 'RDSDatabaseAutoStartPreventer', {
|
|
147
|
+
targetResource: {
|
|
148
|
+
tagKey: 'AutoStartPrevent',
|
|
149
|
+
tagValues: ['YES'],
|
|
150
|
+
},
|
|
151
|
+
secrets: {},
|
|
152
|
+
failureDetection: {
|
|
153
|
+
enabled: true,
|
|
154
|
+
alarmTopic,
|
|
155
|
+
},
|
|
156
|
+
});
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
Alarms created when enabled (threshold 1 in a 5-minute period):
|
|
160
|
+
|
|
161
|
+
| Alarm | Metric | Fires when |
|
|
162
|
+
|-------|--------|------------|
|
|
163
|
+
| Lambda errors | `AWS/Lambda` `Errors` | An invocation fails at the platform level (for example a crash or invocation timeout). |
|
|
164
|
+
| Lambda throttles | `AWS/Lambda` `Throttles` | An invocation is throttled. |
|
|
165
|
+
| Failed execution | `RDSDatabaseAutoStartPreventer` `AutoStartPreventFailed` | The handler logs `AutoStartPreventFailed` because the durable execution failed (invalid input or Slack secret, unexpected RDS status, stop not reaching `stopped`, or Slack post failure after retries). |
|
|
166
|
+
|
|
135
167
|
### Slack secret (AWS Secrets Manager)
|
|
136
168
|
|
|
137
169
|
Create the secret **before** deploy when you want Slack notifications. Omit `slackSecretName` to skip Slack entirely (no secret and no Secrets Manager IAM are required in that case).
|
|
@@ -164,6 +196,9 @@ When `slackSecretName` is set, the construct grants the Lambda role read access
|
|
|
164
196
|
| `enableRule` | `boolean` | No | Whether the EventBridge rules are enabled. Defaults to `true` if omitted. |
|
|
165
197
|
| `secrets` | `Secrets` | Yes | External secrets for notifications. |
|
|
166
198
|
| `secrets.slackSecretName` | `string` | No | Name of the Secrets Manager secret containing Slack `token` and `channel`. Omit it to skip Slack notifications. |
|
|
199
|
+
| `failureDetection` | `AutoStartPreventFailureDetectionProps` | No | CloudWatch failure detection for the Lambda. No alarms when omitted. |
|
|
200
|
+
| `failureDetection.enabled` | `boolean` | No | Creates the failure alarms only when `true`. |
|
|
201
|
+
| `failureDetection.alarmTopic` | `ITopic` | No | Existing SNS topic notified by every alarm. Alarms have no actions when omitted. |
|
|
167
202
|
|
|
168
203
|
Empty `tagKey`, an empty `tagValues` array (or blank entries), and a blank `slackSecretName` fail at synthesis. Omitting `slackSecretName` is allowed. Unresolved CDK tokens are not checked.
|
|
169
204
|
|
|
@@ -176,18 +211,21 @@ See [API.md](./API.md).
|
|
|
176
211
|
- **Node.js** >= 20.0.0 (for your CDK app)
|
|
177
212
|
- **AWS CDK** ^2.232.0
|
|
178
213
|
- **constructs** ^10.5.1
|
|
214
|
+
- **lambda-failure-detector** ^0.2.3 (peer dependency, used for `failureDetection`)
|
|
179
215
|
- **AWS Lambda** runtime Node.js 24.x with Durable Execution (deployed by the construct)
|
|
180
216
|
|
|
181
217
|
## Notes
|
|
182
218
|
|
|
183
219
|
- **Aurora / dual events:** An Aurora auto-start can emit both a DB cluster event (`RDS-EVENT-0153`) and DB instance event(s) (`RDS-EVENT-0154`). This package listens for both and may run separate Durable executions. Tag mismatch remains a no-op; if the resource is already `stopped`, the handler does not call StopDB* and does not post to Slack.
|
|
184
220
|
- **IAM:** RDS Describe is limited to account/region `db` / `cluster` ARNs. Stop requires a matching `aws:ResourceTag` for your `tagKey` / `tagValues`. Slack secret read is granted only when `slackSecretName` is set.
|
|
221
|
+
- **Failure alarms:** A failed durable execution ends the invocation normally, so it does not raise the Lambda `Errors` metric. The `AutoStartPreventFailed` log alarm covers those failures. The log line contains the DB identifier and error message, never the Slack token or channel.
|
|
185
222
|
|
|
186
223
|
## Troubleshooting
|
|
187
224
|
|
|
188
225
|
- **CloudWatch Logs:** The construct creates a dedicated Log Group for the Durable Lambda (JSON logs, 3-month retention). After a successful create, the log group uses `RetainExceptOnCreate` so it remains available for incident review after stack delete or replace.
|
|
189
226
|
- **Nothing stopped / no Slack:** Confirm the resource tag matches `tagKey` / `tagValues`. Mismatch is intentional no-op with no Slack message.
|
|
190
227
|
- **Stop attempted but Slack missing:** Slack runs only when this invocation called StopDB* and the resource reached `stopped`, and only when `slackSecretName` is set. Already-stopped resources skip Slack.
|
|
228
|
+
- **`AutoStartPreventFailed` alarm:** Search the Lambda log group for `AutoStartPreventFailed` to find the DB identifier and error message of the failed execution.
|
|
191
229
|
- **Secret errors:** Ensure the secret exists before deploy, JSON has non-empty `token` and `channel`, and the name passed as `slackSecretName` matches Secrets Manager.
|
|
192
230
|
|
|
193
231
|
## License
|