UNPKG

cdk-drizzle-migrate

Version:

AWS CDK construct for running Drizzle ORM migrations

67 lines (66 loc) 2.58 kB
import { CustomResource } from "aws-cdk-lib"; import * as dsql from "aws-cdk-lib/aws-dsql"; import * as ec2 from "aws-cdk-lib/aws-ec2"; import { NodejsFunction, NodejsFunctionProps } from "aws-cdk-lib/aws-lambda-nodejs"; import * as rds from "aws-cdk-lib/aws-rds"; import * as secretsmanager from "aws-cdk-lib/aws-secretsmanager"; import { Construct } from "constructs"; /** * Properties for DrizzleMigrate */ export interface DrizzleMigrateProps { /** * The database secret containing connection details * Must contain standard CDK database secret properties: username, * password, host, port, engine, etc. * Not required when relying on IAM authentication (such as DSQL). * @default - undefined for DSQL clusters using IAM authentication */ readonly dbSecret?: secretsmanager.ISecret; /** * The path to the migrations directory * This directory will be bundled with the Lambda function */ readonly migrationsPath: string; /** * Optional properties to customize the Lambda function * Excludes runtime, entry, and handler which are managed by the construct * @default - Default Lambda configuration is used */ readonly handlerProps?: NodejsFunctionProps; /** * The VPC where the Lambda function will be deployed * Required when your database is only accessible in a VPC. * Not required for DSQL as it uses public endpoints with IAM authentication * @default - use VPC of your RDS/Aurora cluster */ readonly vpc?: ec2.IVpc; /** * Optional subnet selection to deploy the Lambda function * Only used when vpc is specified * @default - PRIVATE_WITH_EGRESS subnets */ readonly vpcSubnets?: ec2.SubnetSelection; /** * Optional database cluster or instance * Supports both traditional RDS/Aurora clusters and DSQL clusters * - For RDS/Aurora: security groups will be configured to allow access * - For DSQL: IAM authentication will be used instead of secrets * @default - No database connection is configured */ readonly cluster?: rds.IDatabaseCluster | rds.IDatabaseInstance | dsql.CfnCluster; } /** * A custom resource that runs Drizzle migrations */ export declare class DrizzleMigrate extends Construct { /** * The custom resource that was created */ readonly resource: CustomResource; /** * The Lambda function that executes the migrations */ readonly handler: NodejsFunction; constructor(scope: Construct, id: string, props: DrizzleMigrateProps); }