import { Construct } from "constructs"; import * as ec2 from "aws-cdk-lib/aws-ec2"; import * as rds from "aws-cdk-lib/aws-rds"; import * as secretsManager from "aws-cdk-lib/aws-secretsmanager"; import { SSTConstruct } from "./Construct.js"; import { Function as Fn } from "./Function.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" | "postgresql10.14" | "postgresql11.13"; /** * 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 rds.AuroraCapacityUnit; /** * The maximum capacity for the cluster. * * @default "ACU_16" */ maxCapacity?: keyof typeof rds.AuroraCapacityUnit; }; /** * Path to the directory that contains the migration scripts. The `RDS` construct uses [Kysely](https://koskimas.github.io/kysely/) 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?: rds.IServerlessCluster | RDSCdkServerlessClusterProps; /** * Required when importing existing RDS Serverless v1 Cluster. */ secret?: secretsManager.ISecret; }; } export declare type RDSEngineType = RDSProps["engine"]; export interface RDSCdkServerlessClusterProps extends Omit { vpc?: ec2.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 "@serverless-stack/resources"; * * 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: rds.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(): rds.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" | "postgresql10.14" | "postgresql11.13"; secretArn: string; types: RDSTypes | undefined; clusterArn: string; clusterIdentifier: string; defaultDatabaseName: string; migrator: { node: string; stack: string; /** * Name of a database which is automatically created inside the cluster. */ } | undefined; }; }; /** @internal */ getFunctionBinding(): { clientPackage: string; variables: { clusterArn: { environment: string; parameter: string; }; secretArn: { environment: string; parameter: string; }; defaultDatabaseName: { environment: string; parameter: string; }; }; permissions: { "rds-data:*": string[]; "secretsmanager:GetSecretValue": string[]; "secretsmanager:DescribeSecret": string[]; }; }; 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; }