AWS RDS Database Running Scheduler

3.1.4 · active · verified Wed Apr 22

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.

Common errors

Warnings

Install

Imports

Quickstart

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.

import { App, Stack } from 'aws-cdk-lib';
import { RDSDatabaseRunningScheduler } from 'aws-rds-database-running-scheduler';
import { Secret } from 'aws-cdk-lib/aws-secretsmanager';

const app = new App();
const stack = new Stack(app, 'MyRdsSchedulerStack', {
  env: {
    account: process.env.CDK_DEFAULT_ACCOUNT ?? '',
    region: process.env.CDK_DEFAULT_REGION ?? ''
  }
});

// Create a placeholder secret for Slack webhook (replace with your actual secret management)
const slackWebhookSecret = new Secret(stack, 'SlackWebhookSecret', {
  secretName: 'example/slack/webhook',
  description: 'Secret for Slack webhook URL (for RDS scheduler notifications)',
  secretStringValue: process.env.SLACK_WEBHOOK_URL ?? 'https://hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX'
});

new RDSDatabaseRunningScheduler(stack, 'MyRDSScheduler', {
  targetResource: { tagKey: 'WorkHoursRunning', tagValues: ['YES'] },
  secrets: { slackSecretName: slackWebhookSecret.secretName },
  enableScheduling: true,
  startSchedule: { timezone: 'Asia/Tokyo', minute: '50', hour: '7', week: 'MON-FRI' },
  stopSchedule: { timezone: 'Asia/Tokyo', minute: '5', hour: '19', week: 'MON-FRI' }
});

app.synth();

view raw JSON →