{"id":16298,"library":"aws-rds-database-running-scheduler","title":"AWS RDS Database Running Scheduler","description":"This AWS CDK construct provides an automated solution for managing the operational hours of Amazon RDS DB instances and Aurora clusters. It identifies target resources based on user-defined tags and leverages AWS EventBridge Scheduler to trigger a Lambda function at specified times, ensuring databases only run during active working hours. This significantly reduces costs for non-production environments. The current stable version is 3.1.4, with frequent patch and minor releases. Key differentiators include its tag-based targeting, 'Durable Execution' Lambda that polls for desired resource states, and optional Slack notifications for operational status. It supports cron-based scheduling with configurable timezones, times, and weekdays, enabling precise control over database availability and cost optimization.","status":"active","version":"3.1.4","language":"javascript","source_language":"en","source_url":"https://github.com/gammarers-aws-cdk-constructs/aws-rds-database-running-scheduler","tags":["javascript","aws","aws-cdk","cdk","cost","rds","saving","scheduler","typescript"],"install":[{"cmd":"npm install aws-rds-database-running-scheduler","lang":"bash","label":"npm"},{"cmd":"yarn add aws-rds-database-running-scheduler","lang":"bash","label":"yarn"},{"cmd":"pnpm add aws-rds-database-running-scheduler","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Core AWS CDK constructs and types for defining cloud infrastructure.","package":"aws-cdk-lib","optional":false},{"reason":"Fundamental building blocks for AWS CDK applications, providing the construct programming model.","package":"constructs","optional":false}],"imports":[{"note":"This is the primary construct for embedding the scheduler into an existing CDK stack. Use ESM import syntax.","wrong":"const { RDSDatabaseRunningScheduler } = require('aws-rds-database-running-scheduler');","symbol":"RDSDatabaseRunningScheduler","correct":"import { RDSDatabaseRunningScheduler } from 'aws-rds-database-running-scheduler';"},{"note":"Use this specific Stack construct when creating a dedicated CDK stack solely for the scheduler. It's a named import.","wrong":"import RDSDatabaseRunningScheduleStack from 'aws-rds-database-running-scheduler';","symbol":"RDSDatabaseRunningScheduleStack","correct":"import { RDSDatabaseRunningScheduleStack } from 'aws-rds-database-running-scheduler';"},{"note":"When using CDK constructs, you typically need to import `App` and `Stack` from `aws-cdk-lib` to define your application and environment.","symbol":"App","correct":"import { App, Stack } from 'aws-cdk-lib';"}],"quickstart":{"code":"import { App, Stack } from 'aws-cdk-lib';\nimport { RDSDatabaseRunningScheduler } from 'aws-rds-database-running-scheduler';\nimport { Secret } from 'aws-cdk-lib/aws-secretsmanager';\n\nconst app = new App();\nconst stack = new Stack(app, 'MyRdsSchedulerStack', {\n  env: {\n    account: process.env.CDK_DEFAULT_ACCOUNT ?? '',\n    region: process.env.CDK_DEFAULT_REGION ?? ''\n  }\n});\n\n// Create a placeholder secret for Slack webhook (replace with your actual secret management)\nconst slackWebhookSecret = new Secret(stack, 'SlackWebhookSecret', {\n  secretName: 'example/slack/webhook',\n  description: 'Secret for Slack webhook URL (for RDS scheduler notifications)',\n  secretStringValue: process.env.SLACK_WEBHOOK_URL ?? 'https://hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX'\n});\n\nnew RDSDatabaseRunningScheduler(stack, 'MyRDSScheduler', {\n  targetResource: { tagKey: 'WorkHoursRunning', tagValues: ['YES'] },\n  secrets: { slackSecretName: slackWebhookSecret.secretName },\n  enableScheduling: true,\n  startSchedule: { timezone: 'Asia/Tokyo', minute: '50', hour: '7', week: 'MON-FRI' },\n  stopSchedule: { timezone: 'Asia/Tokyo', minute: '5', hour: '19', week: 'MON-FRI' }\n});\n\napp.synth();","lang":"typescript","description":"This code deploys the RDS Database Running Scheduler as a construct within a new AWS CDK stack. It configures the scheduler to manage RDS instances and Aurora clusters tagged with 'WorkHoursRunning=YES', setting a daily start/stop schedule for weekdays in the 'Asia/Tokyo' timezone. It also includes a placeholder for Slack notification secret."},"warnings":[{"fix":"Upgrade your Node.js environment to version 20.0.0 or newer (e.g., using nvm: `nvm install 20 && nvm use 20`).","message":"This package requires Node.js version 20.0.0 or higher. Older Node.js versions are not supported and will lead to errors during CDK synthesis or deployment.","severity":"breaking","affected_versions":">=3.0.0"},{"fix":"Carefully verify that the tags on your AWS RDS resources (both key and value) precisely match the configuration in your CDK code.","message":"The `targetResource.tagKey` and `targetResource.tagValues` must exactly match the tags applied to your RDS instances or Aurora clusters. Mismatched casing or values will result in resources not being managed by the scheduler.","severity":"gotcha","affected_versions":">=3.0.0"},{"fix":"Ensure the specified secret exists in AWS Secrets Manager, contains a valid Slack webhook URL, and the IAM role associated with the scheduler's Lambda function has `secretsmanager:GetSecretValue` permissions for that secret.","message":"The `slackSecretName` property expects the name of an AWS Secrets Manager secret that contains the Slack webhook URL. If the secret does not exist or the Lambda function lacks permissions to access it, Slack notifications will fail silently or cause Lambda invocation errors.","severity":"gotcha","affected_versions":">=3.0.0"},{"fix":"Consult a list of IANA timezones and use a valid identifier for your desired schedule. Examples include 'UTC', 'America/Los_Angeles', 'Europe/Berlin'.","message":"The `timezone` string for `startSchedule` and `stopSchedule` must be a valid IANA timezone identifier (e.g., 'America/New_York', 'Europe/London', 'Asia/Tokyo'). Invalid timezone strings may lead to incorrect scheduling or deployment failures.","severity":"gotcha","affected_versions":">=3.0.0"}],"env_vars":null,"last_verified":"2026-04-22T00:00:00.000Z","next_check":"2026-07-21T00:00:00.000Z","problems":[{"fix":"Ensure each construct instance (e.g., `new RDSDatabaseRunningScheduler(...)`) has a unique string ID within its parent scope (e.g., `stack`).","cause":"Attempting to create two constructs with the same ID within the same parent scope.","error":"Error: Invariant Violation: The construct ID 'MyRDSScheduler' is already in use by a sibling construct. Choose a unique ID for each construct within the same scope."},{"fix":"Review the properties passed to `RDSDatabaseRunningSchedulerProps`, especially for `targetResource` and `secrets`, ensuring all values are correctly typed as strings or construct references.","cause":"Common CDK synthesis error indicating an issue with how references or intrinsic functions are used, often due to passing non-string values where strings are expected.","error":"Error: Unable to resolve object: Fn::Join: Invalid type for Fn::Join"},{"fix":"Define the `env` property for your `Stack` with explicit `account` and `region` values, or ensure `CDK_DEFAULT_ACCOUNT` and `CDK_DEFAULT_REGION` are set in your environment (e.g., `export CDK_DEFAULT_ACCOUNT=\"123456789012\"`).","cause":"CDK environment variables (CDK_DEFAULT_ACCOUNT, CDK_DEFAULT_REGION) are not set when synthesizing or deploying, and the stack's `env` property is not explicitly provided or correctly conditionally accessed.","error":"TypeError: Cannot read properties of undefined (reading 'account')"}],"ecosystem":"npm"}