import { Construct } from "constructs"; import { IVpc } from "aws-cdk-lib/aws-ec2"; import { AuroraCapacityUnit, Endpoint, IServerlessCluster, ServerlessCluster, ServerlessClusterProps } from "aws-cdk-lib/aws-rds"; import { ISecret } from "aws-cdk-lib/aws-secretsmanager"; import { SSTConstruct } from "./Construct.js"; import { Function as Fn } from "./Function.js"; import { BindingProps } from "./util/binding.js"; export interface RDSTypes { path: string; camelCase?: boolean; } export interface RDSProps { /** * Database engine of the cluster. Cannot be changed once set. */ engine: "mysql5.6" | "mysql5.7" | "mysql8.0" | "postgresql11.13" | "postgresql11.16" | "postgresql13.12" | "postgresql13.9" | "postgresql14.10" | "postgresql15.5" | "postgresql16.1"; /** * Name of a database which is automatically created inside the cluster. */ defaultDatabaseName: string; scaling?: { /** * The time before the cluster is paused. * * Pass in true to pause after 5 minutes of inactive. And pass in false to * disable pausing. * * Or pass in the number of minutes to wait before the cluster is paused. * * @default true * * @example * ```js * new RDS(stack, "Database", { * scaling: { * autoPause: props.app.stage !== "prod" * } * }) * ``` */ autoPause?: boolean | number; /** * The minimum capacity for the cluster. * * @default "ACU_2" */ minCapacity?: keyof typeof AuroraCapacityUnit; /** * The maximum capacity for the cluster. * * @default "ACU_16" */ maxCapacity?: keyof typeof AuroraCapacityUnit; }; /** * Path to the directory that contains the migration scripts. The `RDS` construct uses [Kysely](https://kysely.dev/) to run and manage schema migrations. The `migrations` prop should point to the folder where your migration files are. * * @example * * ```js * new RDS(stack, "Database", { * engine: "postgresql11.13", * defaultDatabaseName: "acme", * migrations: "path/to/migration/scripts", * }); * ``` */ migrations?: string; /** * Path to place generated typescript types after running migrations * * @example * * ```js * new RDS(stack, "Database", { * engine: "postgresql11.13", * defaultDatabaseName: "acme", * migrations: "path/to/migration/scripts", * types: "backend/core/sql/types.ts", * }); * ``` * @example * ```js * new RDS(stack, "Database", { * engine: "postgresql11.13", * defaultDatabaseName: "acme", * migrations: "path/to/migration/scripts", * types: { * path: "backend/core/sql/types.ts", * camelCase: true * } * }); * ``` */ types?: string | RDSTypes; cdk?: { /** * Allows you to override default id for this construct. */ id?: string; /** * Configure the internallly created RDS cluster. * * @example * ```js * new RDS(stack, "Database", { * cdk: { * cluster: { * clusterIdentifier: "my-cluster", * } * }, * }); * ``` * * Alternatively, you can import an existing RDS Serverless v1 Cluster in your AWS account. * * @example * ```js * new RDS(stack, "Database", { * cdk: { * cluster: rds.ServerlessCluster.fromServerlessClusterAttributes(stack, "ICluster", { * clusterIdentifier: "my-cluster", * }), * secret: secretsManager.Secret.fromSecretAttributes(stack, "ISecret", { * secretPartialArn: "arn:aws:secretsmanager:us-east-1:123456789012:secret:my-secret", * }), * }, * }); * ``` */ cluster?: IServerlessCluster | RDSCdkServerlessClusterProps; /** * Required when importing existing RDS Serverless v1 Cluster. */ secret?: ISecret; }; } export type RDSEngineType = RDSProps["engine"]; export interface RDSCdkServerlessClusterProps extends Omit { vpc?: IVpc; } /** * The `RDS` construct is a higher level CDK construct that makes it easy to create an [RDS Serverless Cluster](https://aws.amazon.com/rds/). * * @example * * ```js * import { RDS } from "sst/constructs"; * * new RDS(stack, "Database", { * engine: "postgresql11.13", * defaultDatabaseName: "my_database", * }); * ``` */ export declare class RDS extends Construct implements SSTConstruct { readonly id: string; readonly cdk: { /** * The ARN of the internally created CDK ServerlessCluster instance. */ cluster: ServerlessCluster; }; /** * The ARN of the internally created CDK ServerlessCluster instance. */ migratorFunction?: Fn; private props; private secret; constructor(scope: Construct, id: string, props: RDSProps); /** * The ARN of the internally created RDS Serverless Cluster. */ get clusterArn(): string; /** * The ARN of the internally created RDS Serverless Cluster. */ get clusterIdentifier(): string; /** * The ARN of the internally created RDS Serverless Cluster. */ get clusterEndpoint(): Endpoint; /** * The default database name of the RDS Serverless Cluster. */ get defaultDatabaseName(): string; /** * The ARN of the internally created Secrets Manager Secret. */ get secretArn(): string; getConstructMetadata(): { type: "RDS"; data: { engine: "mysql5.6" | "mysql5.7" | "mysql8.0" | "postgresql11.13" | "postgresql11.16" | "postgresql13.12" | "postgresql13.9" | "postgresql14.10" | "postgresql15.5" | "postgresql16.1"; secretArn: string; types: RDSTypes | undefined; clusterArn: string; clusterIdentifier: string; defaultDatabaseName: string; migrator: { node: string; stack: string; } | undefined; }; }; /** @internal */ getBindings(): BindingProps; runMigrations(migrations: string, database?: string): void; private validateRequiredProps; private validateCDKPropWhenIsConstruct; private validateCDKPropWhenIsClusterProps; private validateMigrationsFileExists; private getEngine; private getScaling; private getVpc; private getVpcSubnets; private createCluster; private importCluster; private createMigrationsFunction; private createMigrationCustomResource; private generateMigrationsHash; }