rds-aurora-bootstrapper 0.3.7 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/.editorconfig ADDED
@@ -0,0 +1,12 @@
1
+ # ~~ Generated by projen. To modify, edit .projenrc.ts and run "npx projen".
2
+
3
+ root=true
4
+
5
+ [*]
6
+ end_of_line=lf
7
+ charset=utf-8
8
+
9
+ [*\.{js,ts}]
10
+ indent_style=space
11
+ indent_size=2
12
+ max_line_length=120
package/.jsii CHANGED
@@ -8440,7 +8440,7 @@
8440
8440
  "stability": "stable"
8441
8441
  },
8442
8442
  "homepage": "https://github.com/gammarers-aws-cdk-constructs/rds-aurora-bootstrapper.git",
8443
- "jsiiVersion": "6.0.13 (build 5c05d06)",
8443
+ "jsiiVersion": "6.0.14 (build 44649f3)",
8444
8444
  "keywords": [
8445
8445
  "cdk"
8446
8446
  ],
@@ -8456,7 +8456,7 @@
8456
8456
  },
8457
8457
  "name": "rds-aurora-bootstrapper",
8458
8458
  "readme": {
8459
- "markdown": "# RDS Aurora Bootstrapper (AWS CDK V2)\n\n[![npm version](https://img.shields.io/npm/v/rds-aurora-bootstrapper)](https://www.npmjs.com/package/rds-aurora-bootstrapper)\n[![npm license](https://img.shields.io/npm/l/rds-aurora-bootstrapper)](https://www.npmjs.com/package/rds-aurora-bootstrapper)\n[![Node.js](https://img.shields.io/node/v/rds-aurora-bootstrapper)](https://www.npmjs.com/package/rds-aurora-bootstrapper)\n\nAWS CDK constructs for bootstrapping Aurora PostgreSQL databases via the RDS Data API.\n\n## Features\n\n- **`AuroraDatabaseCreateOwner`** — creates a `NOLOGIN NOINHERIT` owner role and grants it to the master user\n- **`AuroraDatabaseCreateSchema`** — creates a schema, assigns ownership to an existing owner role, and optionally drops the `public` schema with `CASCADE`\n- **`AuroraDatabaseCreateUser`** — creates a `LOGIN` application user from a Secrets Manager credential secret, grants `CONNECT` / schema `USAGE` / table DML, and sets default privileges for the owner role\n- Idempotent owner and user role creation — skips creation when the role already exists\n- Validates PostgreSQL identifiers at synthesis time (`ownerUsername`, `schemaName`)\n- Resolves the master username from the credentials secret through a CloudFormation dynamic reference\n- Bundled Lambda custom resources with IAM permissions and Secrets Manager read access configured automatically\n\n## Installation\n\n```bash\nnpm install rds-aurora-bootstrapper aws-cdk-lib constructs\n```\n\n```bash\nyarn add rds-aurora-bootstrapper aws-cdk-lib constructs\n```\n\n## Usage\n\nProvision resources in order: owner role → schema → application user.\n\n```typescript\nimport { Stack } from 'aws-cdk-lib';\nimport { Vpc } from 'aws-cdk-lib/aws-ec2';\nimport {\n AuroraPostgresEngineVersion,\n ClusterInstance,\n DatabaseCluster,\n DatabaseClusterEngine,\n} from 'aws-cdk-lib/aws-rds';\nimport { Secret } from 'aws-cdk-lib/aws-secretsmanager';\nimport { Construct } from 'constructs';\nimport {\n AuroraDatabaseCreateOwner,\n AuroraDatabaseCreateSchema,\n AuroraDatabaseCreateUser,\n} from 'rds-aurora-bootstrapper';\n\nexport class MyStack extends Stack {\n constructor(scope: Construct, id: string) {\n super(scope, id);\n\n const vpc = new Vpc(this, 'Vpc', { maxAzs: 2 });\n const cluster = new DatabaseCluster(this, 'Cluster', {\n engine: DatabaseClusterEngine.auroraPostgres({\n version: AuroraPostgresEngineVersion.VER_17_6,\n }),\n vpc,\n writer: ClusterInstance.provisioned('writer'),\n });\n const masterUserSecret = new Secret(this, 'MasterUserSecret');\n const appUserSecret = new Secret(this, 'AppUserSecret', {\n generateSecretString: {\n secretStringTemplate: JSON.stringify({ username: 'app_user' }),\n generateStringKey: 'password',\n excludePunctuation: true,\n },\n });\n\n const createOwner = new AuroraDatabaseCreateOwner(this, 'CreateOwner', {\n dbMasterUserCredentials: masterUserSecret,\n dbCluster: cluster,\n dbName: 'appdb',\n ownerUsername: 'app_owner',\n });\n\n const createSchema = new AuroraDatabaseCreateSchema(this, 'CreateSchema', {\n dbMasterUserCredentials: masterUserSecret,\n dbCluster: cluster,\n dbName: 'appdb',\n ownerUsername: 'app_owner',\n schemaName: 'app_schema',\n isDropPublicSchema: true,\n });\n createSchema.node.addDependency(createOwner);\n\n const createUser = new AuroraDatabaseCreateUser(this, 'CreateUser', {\n dbMasterUserCredentials: masterUserSecret,\n targetUserCredentials: appUserSecret,\n dbCluster: cluster,\n dbName: 'appdb',\n ownerUsername: 'app_owner',\n schemaName: 'app_schema',\n });\n createUser.node.addDependency(createSchema);\n }\n}\n```\n\n## Options\n\n### `AuroraDatabaseCreateOwnerProps`\n\n| Property | Type | Description |\n| --- | --- | --- |\n| `dbMasterUserCredentials` | `Secret` | Secrets Manager secret with Aurora master credentials. The `username` field is passed to the custom resource via a dynamic reference. |\n| `dbCluster` | `DatabaseCluster` | Aurora database cluster where the owner role is created. |\n| `dbName` | `string` | PostgreSQL database name targeted by the custom resource. |\n| `ownerUsername` | `string` | Username of the owner role to create (`NOLOGIN`, `NOINHERIT`). Must match `^[a-zA-Z_][a-zA-Z0-9_-]*$`. |\n\n### `AuroraDatabaseCreateSchemaProps`\n\n| Property | Type | Description |\n| --- | --- | --- |\n| `dbMasterUserCredentials` | `Secret` | Secrets Manager secret with Aurora master credentials. The `username` field is passed to the custom resource via a dynamic reference. |\n| `dbCluster` | `DatabaseCluster` | Aurora database cluster where the schema is created. |\n| `dbName` | `string` | PostgreSQL database name targeted by the custom resource. |\n| `ownerUsername` | `string` | Username of the existing owner role that will own the new schema. Must match `^[a-zA-Z_][a-zA-Z0-9_-]*$`. |\n| `schemaName` | `string` | Name of the PostgreSQL schema to create. Must match `^[a-zA-Z_][a-zA-Z0-9_-]*$`. |\n| `isDropPublicSchema` | `boolean` | When `true`, drops the `public` schema with `CASCADE` after creating the target schema. |\n\n### `AuroraDatabaseCreateUserProps`\n\n| Property | Type | Description |\n| --- | --- | --- |\n| `dbMasterUserCredentials` | `Secret` | Secrets Manager secret with Aurora master credentials. The `username` field is passed to the custom resource via a dynamic reference. |\n| `targetUserCredentials` | `Secret` | Secrets Manager secret with the application user credentials (`username` and `password`). Used at runtime to create the `LOGIN` role. |\n| `dbCluster` | `DatabaseCluster` | Aurora database cluster where the user role is created. |\n| `dbName` | `string` | PostgreSQL database name targeted by the custom resource. |\n| `ownerUsername` | `string` | Username of the existing owner role used for default privileges. Must match `^[a-zA-Z_][a-zA-Z0-9_-]*$`. |\n| `schemaName` | `string` | Name of the PostgreSQL schema the new user is granted access to. Must match `^[a-zA-Z_][a-zA-Z0-9_-]*$`. |\n\n## Requirements\n\n- Node.js `>= 20.0.0`\n- `aws-cdk-lib` `^2.232.0`\n- `constructs` `^10.5.1`\n- Aurora PostgreSQL cluster with the [RDS Data API](https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/data-api.html) enabled\n- Secrets Manager secrets containing `username` and `password` fields (master credentials, and application user credentials for `AuroraDatabaseCreateUser`)\n\n## License\n\nThis project is licensed under the Apache-2.0 License.\n"
8459
+ "markdown": "# RDS Aurora Bootstrapper (AWS CDK V2)\n\n[![npm version](https://img.shields.io/npm/v/rds-aurora-bootstrapper)](https://www.npmjs.com/package/rds-aurora-bootstrapper)\n[![npm license](https://img.shields.io/npm/l/rds-aurora-bootstrapper)](https://www.npmjs.com/package/rds-aurora-bootstrapper)\n[![Node.js](https://img.shields.io/node/v/rds-aurora-bootstrapper)](https://www.npmjs.com/package/rds-aurora-bootstrapper)\n\nAWS CDK constructs for bootstrapping Aurora PostgreSQL databases via the RDS Data API.\n\n## Features\n\n- **`AuroraDatabaseCreateOwner`** — creates a `NOLOGIN NOINHERIT` owner role and grants it to the master user\n- **`AuroraDatabaseCreateSchema`** — creates a schema, assigns ownership to an existing owner role, and optionally drops the `public` schema with `CASCADE`\n- **`AuroraDatabaseCreateUser`** — creates a `LOGIN` application user from a Secrets Manager credential secret, grants `CONNECT` / schema `USAGE` / table DML, and sets default privileges for the owner role\n- **`AuroraDatabaseCreateMigrator`** — creates a `LOGIN` migrator user from a Secrets Manager credential secret, grants `CONNECT`, grants membership in the owner role, and sets `search_path` to the target schema\n- Idempotent owner, user, and migrator role creation — skips creation when the role already exists\n- Validates PostgreSQL identifiers at synthesis time (`ownerUsername`, `schemaName`)\n- Resolves the master username from the credentials secret through a CloudFormation dynamic reference\n- Bundled Lambda custom resources with IAM permissions and Secrets Manager read access configured automatically\n\n## Installation\n\n```bash\nnpm install rds-aurora-bootstrapper aws-cdk-lib constructs\n```\n\n```bash\nyarn add rds-aurora-bootstrapper aws-cdk-lib constructs\n```\n\n## Usage\n\nProvision resources in order: owner role → schema → migrator user → application user.\n\n```typescript\nimport { Stack } from 'aws-cdk-lib';\nimport { Vpc } from 'aws-cdk-lib/aws-ec2';\nimport {\n AuroraPostgresEngineVersion,\n ClusterInstance,\n DatabaseCluster,\n DatabaseClusterEngine,\n} from 'aws-cdk-lib/aws-rds';\nimport { Secret } from 'aws-cdk-lib/aws-secretsmanager';\nimport { Construct } from 'constructs';\nimport {\n AuroraDatabaseCreateOwner,\n AuroraDatabaseCreateSchema,\n AuroraDatabaseCreateMigrator,\n AuroraDatabaseCreateUser,\n} from 'rds-aurora-bootstrapper';\n\nexport class MyStack extends Stack {\n constructor(scope: Construct, id: string) {\n super(scope, id);\n\n const vpc = new Vpc(this, 'Vpc', { maxAzs: 2 });\n const cluster = new DatabaseCluster(this, 'Cluster', {\n engine: DatabaseClusterEngine.auroraPostgres({\n version: AuroraPostgresEngineVersion.VER_17_6,\n }),\n vpc,\n writer: ClusterInstance.provisioned('writer'),\n });\n const masterUserSecret = new Secret(this, 'MasterUserSecret');\n const migratorUserSecret = new Secret(this, 'MigratorUserSecret', {\n generateSecretString: {\n secretStringTemplate: JSON.stringify({ username: 'app_migrator' }),\n generateStringKey: 'password',\n excludePunctuation: true,\n },\n });\n const appUserSecret = new Secret(this, 'AppUserSecret', {\n generateSecretString: {\n secretStringTemplate: JSON.stringify({ username: 'app_user' }),\n generateStringKey: 'password',\n excludePunctuation: true,\n },\n });\n\n const createOwner = new AuroraDatabaseCreateOwner(this, 'CreateOwner', {\n dbMasterUserCredentials: masterUserSecret,\n dbCluster: cluster,\n dbName: 'appdb',\n ownerUsername: 'app_owner',\n });\n\n const createSchema = new AuroraDatabaseCreateSchema(this, 'CreateSchema', {\n dbMasterUserCredentials: masterUserSecret,\n dbCluster: cluster,\n dbName: 'appdb',\n ownerUsername: 'app_owner',\n schemaName: 'app_schema',\n isDropPublicSchema: true,\n });\n createSchema.node.addDependency(createOwner);\n\n const createMigrator = new AuroraDatabaseCreateMigrator(this, 'CreateMigrator', {\n dbMasterUserCredentials: masterUserSecret,\n migratorUserCredentials: migratorUserSecret,\n dbCluster: cluster,\n dbName: 'appdb',\n ownerUsername: 'app_owner',\n schemaName: 'app_schema',\n });\n createMigrator.node.addDependency(createSchema);\n\n const createUser = new AuroraDatabaseCreateUser(this, 'CreateUser', {\n dbMasterUserCredentials: masterUserSecret,\n targetUserCredentials: appUserSecret,\n dbCluster: cluster,\n dbName: 'appdb',\n ownerUsername: 'app_owner',\n schemaName: 'app_schema',\n });\n createUser.node.addDependency(createSchema);\n }\n}\n```\n\n## Options\n\n### `AuroraDatabaseCreateOwnerProps`\n\n| Property | Type | Description |\n| --- | --- | --- |\n| `dbMasterUserCredentials` | `Secret` | Secrets Manager secret with Aurora master credentials. The `username` field is passed to the custom resource via a dynamic reference. |\n| `dbCluster` | `DatabaseCluster` | Aurora database cluster where the owner role is created. |\n| `dbName` | `string` | PostgreSQL database name targeted by the custom resource. |\n| `ownerUsername` | `string` | Username of the owner role to create (`NOLOGIN`, `NOINHERIT`). Must match `^[a-zA-Z_][a-zA-Z0-9_-]*$`. |\n\n### `AuroraDatabaseCreateSchemaProps`\n\n| Property | Type | Description |\n| --- | --- | --- |\n| `dbMasterUserCredentials` | `Secret` | Secrets Manager secret with Aurora master credentials. The `username` field is passed to the custom resource via a dynamic reference. |\n| `dbCluster` | `DatabaseCluster` | Aurora database cluster where the schema is created. |\n| `dbName` | `string` | PostgreSQL database name targeted by the custom resource. |\n| `ownerUsername` | `string` | Username of the existing owner role that will own the new schema. Must match `^[a-zA-Z_][a-zA-Z0-9_-]*$`. |\n| `schemaName` | `string` | Name of the PostgreSQL schema to create. Must match `^[a-zA-Z_][a-zA-Z0-9_-]*$`. |\n| `isDropPublicSchema` | `boolean` | When `true`, drops the `public` schema with `CASCADE` after creating the target schema. |\n\n### `AuroraDatabaseCreateMigratorProps`\n\n| Property | Type | Description |\n| --- | --- | --- |\n| `dbMasterUserCredentials` | `Secret` | Secrets Manager secret with Aurora master credentials. The `username` field is passed to the custom resource via a dynamic reference. |\n| `migratorUserCredentials` | `Secret` | Secrets Manager secret with the migrator user credentials (`username` and `password`). Used at runtime to create the `LOGIN` role. |\n| `dbCluster` | `DatabaseCluster` | Aurora database cluster where the migrator role is created. |\n| `dbName` | `string` | PostgreSQL database name targeted by the custom resource. |\n| `ownerUsername` | `string` | Username of the existing owner role granted to the migrator. Must match `^[a-zA-Z_][a-zA-Z0-9_-]*$`. |\n| `schemaName` | `string` | Name of the PostgreSQL schema used as the migrator's `search_path`. Must match `^[a-zA-Z_][a-zA-Z0-9_-]*$`. |\n\n### `AuroraDatabaseCreateUserProps`\n\n| Property | Type | Description |\n| --- | --- | --- |\n| `dbMasterUserCredentials` | `Secret` | Secrets Manager secret with Aurora master credentials. The `username` field is passed to the custom resource via a dynamic reference. |\n| `targetUserCredentials` | `Secret` | Secrets Manager secret with the application user credentials (`username` and `password`). Used at runtime to create the `LOGIN` role. |\n| `dbCluster` | `DatabaseCluster` | Aurora database cluster where the user role is created. |\n| `dbName` | `string` | PostgreSQL database name targeted by the custom resource. |\n| `ownerUsername` | `string` | Username of the existing owner role used for default privileges. Must match `^[a-zA-Z_][a-zA-Z0-9_-]*$`. |\n| `schemaName` | `string` | Name of the PostgreSQL schema the new user is granted access to. Must match `^[a-zA-Z_][a-zA-Z0-9_-]*$`. |\n\n## Requirements\n\n- Node.js `>= 20.0.0`\n- `aws-cdk-lib` `^2.232.0`\n- `constructs` `^10.5.1`\n- Aurora PostgreSQL cluster with the [RDS Data API](https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/data-api.html) enabled\n- Secrets Manager secrets containing `username` and `password` fields (master credentials, and application / migrator user credentials for `AuroraDatabaseCreateUser` / `AuroraDatabaseCreateMigrator`)\n\n## License\n\nThis project is licensed under the Apache-2.0 License.\n"
8460
8460
  },
8461
8461
  "repository": {
8462
8462
  "type": "git",
@@ -8469,6 +8469,183 @@
8469
8469
  }
8470
8470
  },
8471
8471
  "types": {
8472
+ "rds-aurora-bootstrapper.AuroraDatabaseCreateMigrator": {
8473
+ "assembly": "rds-aurora-bootstrapper",
8474
+ "base": "constructs.Construct",
8475
+ "docs": {
8476
+ "remarks": "On Create, the handler creates a `LOGIN` role from\n{@link AuroraDatabaseCreateMigratorProps.migratorUserCredentials} when the\nrole is missing, grants `CONNECT` on the database, grants membership in\n{@link AuroraDatabaseCreateMigratorProps.ownerUsername}, and sets\n`search_path` to {@link AuroraDatabaseCreateMigratorProps.schemaName}. Role\ncreation is idempotent when the username already exists.\n\nThe master username is derived from the `username` field of\n{@link AuroraDatabaseCreateMigratorProps.dbMasterUserCredentials} through a\nSecrets Manager dynamic reference; callers do not pass it explicitly.\n\nEnsure {@link AuroraDatabaseCreateMigratorProps.ownerUsername} and\n{@link AuroraDatabaseCreateMigratorProps.schemaName} already exist (for\nexample via {@link AuroraDatabaseCreateOwner } and\n{@link AuroraDatabaseCreateSchema }) before this resource runs.",
8477
+ "stability": "stable",
8478
+ "summary": "CDK construct that provisions a PostgreSQL migrator user on an Aurora cluster using a custom resource backed by the RDS Data API."
8479
+ },
8480
+ "fqn": "rds-aurora-bootstrapper.AuroraDatabaseCreateMigrator",
8481
+ "initializer": {
8482
+ "docs": {
8483
+ "custom": {
8484
+ "throws": "Error when `ownerUsername` or `schemaName` fails identifier validation."
8485
+ },
8486
+ "stability": "stable",
8487
+ "summary": "Creates the custom resource that provisions the migrator database user."
8488
+ },
8489
+ "locationInModule": {
8490
+ "filename": "src/constructs/aurora-database-create-migrator.ts",
8491
+ "line": 70
8492
+ },
8493
+ "parameters": [
8494
+ {
8495
+ "docs": {
8496
+ "summary": "- Parent construct."
8497
+ },
8498
+ "name": "scope",
8499
+ "type": {
8500
+ "fqn": "constructs.Construct"
8501
+ }
8502
+ },
8503
+ {
8504
+ "docs": {
8505
+ "summary": "- Construct identifier."
8506
+ },
8507
+ "name": "id",
8508
+ "type": {
8509
+ "primitive": "string"
8510
+ }
8511
+ },
8512
+ {
8513
+ "docs": {
8514
+ "summary": "- Configuration for the migrator user."
8515
+ },
8516
+ "name": "props",
8517
+ "type": {
8518
+ "fqn": "rds-aurora-bootstrapper.AuroraDatabaseCreateMigratorProps"
8519
+ }
8520
+ }
8521
+ ]
8522
+ },
8523
+ "kind": "class",
8524
+ "locationInModule": {
8525
+ "filename": "src/constructs/aurora-database-create-migrator.ts",
8526
+ "line": 61
8527
+ },
8528
+ "name": "AuroraDatabaseCreateMigrator",
8529
+ "symbolId": "src/constructs/aurora-database-create-migrator:AuroraDatabaseCreateMigrator"
8530
+ },
8531
+ "rds-aurora-bootstrapper.AuroraDatabaseCreateMigratorProps": {
8532
+ "assembly": "rds-aurora-bootstrapper",
8533
+ "datatype": true,
8534
+ "docs": {
8535
+ "stability": "stable",
8536
+ "summary": "Properties for {@link AuroraDatabaseCreateMigrator}."
8537
+ },
8538
+ "fqn": "rds-aurora-bootstrapper.AuroraDatabaseCreateMigratorProps",
8539
+ "kind": "interface",
8540
+ "locationInModule": {
8541
+ "filename": "src/constructs/aurora-database-create-migrator.ts",
8542
+ "line": 14
8543
+ },
8544
+ "name": "AuroraDatabaseCreateMigratorProps",
8545
+ "properties": [
8546
+ {
8547
+ "abstract": true,
8548
+ "docs": {
8549
+ "stability": "stable",
8550
+ "summary": "Aurora database cluster where the migrator role is created."
8551
+ },
8552
+ "immutable": true,
8553
+ "locationInModule": {
8554
+ "filename": "src/constructs/aurora-database-create-migrator.ts",
8555
+ "line": 26
8556
+ },
8557
+ "name": "dbCluster",
8558
+ "type": {
8559
+ "fqn": "aws-cdk-lib.aws_rds.DatabaseCluster"
8560
+ }
8561
+ },
8562
+ {
8563
+ "abstract": true,
8564
+ "docs": {
8565
+ "remarks": "The `username` field is passed to the custom resource via a dynamic reference.",
8566
+ "stability": "stable",
8567
+ "summary": "Secrets Manager secret holding the Aurora master user credentials."
8568
+ },
8569
+ "immutable": true,
8570
+ "locationInModule": {
8571
+ "filename": "src/constructs/aurora-database-create-migrator.ts",
8572
+ "line": 19
8573
+ },
8574
+ "name": "dbMasterUserCredentials",
8575
+ "type": {
8576
+ "fqn": "aws-cdk-lib.aws_secretsmanager.Secret"
8577
+ }
8578
+ },
8579
+ {
8580
+ "abstract": true,
8581
+ "docs": {
8582
+ "stability": "stable",
8583
+ "summary": "Name of the PostgreSQL database targeted by the custom resource."
8584
+ },
8585
+ "immutable": true,
8586
+ "locationInModule": {
8587
+ "filename": "src/constructs/aurora-database-create-migrator.ts",
8588
+ "line": 28
8589
+ },
8590
+ "name": "dbName",
8591
+ "type": {
8592
+ "primitive": "string"
8593
+ }
8594
+ },
8595
+ {
8596
+ "abstract": true,
8597
+ "docs": {
8598
+ "remarks": "The handler reads `username` and `password` at runtime to create the role.",
8599
+ "stability": "stable",
8600
+ "summary": "Secrets Manager secret holding the migrator user credentials."
8601
+ },
8602
+ "immutable": true,
8603
+ "locationInModule": {
8604
+ "filename": "src/constructs/aurora-database-create-migrator.ts",
8605
+ "line": 24
8606
+ },
8607
+ "name": "migratorUserCredentials",
8608
+ "type": {
8609
+ "fqn": "aws-cdk-lib.aws_secretsmanager.Secret"
8610
+ }
8611
+ },
8612
+ {
8613
+ "abstract": true,
8614
+ "docs": {
8615
+ "remarks": "Must match {@link SAFE_POSTGRESQL_IDENTIFIER_PATTERN }.",
8616
+ "stability": "stable",
8617
+ "summary": "Username of the existing owner role granted to the migrator."
8618
+ },
8619
+ "immutable": true,
8620
+ "locationInModule": {
8621
+ "filename": "src/constructs/aurora-database-create-migrator.ts",
8622
+ "line": 33
8623
+ },
8624
+ "name": "ownerUsername",
8625
+ "type": {
8626
+ "primitive": "string"
8627
+ }
8628
+ },
8629
+ {
8630
+ "abstract": true,
8631
+ "docs": {
8632
+ "remarks": "Must match {@link SAFE_POSTGRESQL_IDENTIFIER_PATTERN }.",
8633
+ "stability": "stable",
8634
+ "summary": "Name of the PostgreSQL schema used as the migrator's `search_path`."
8635
+ },
8636
+ "immutable": true,
8637
+ "locationInModule": {
8638
+ "filename": "src/constructs/aurora-database-create-migrator.ts",
8639
+ "line": 38
8640
+ },
8641
+ "name": "schemaName",
8642
+ "type": {
8643
+ "primitive": "string"
8644
+ }
8645
+ }
8646
+ ],
8647
+ "symbolId": "src/constructs/aurora-database-create-migrator:AuroraDatabaseCreateMigratorProps"
8648
+ },
8472
8649
  "rds-aurora-bootstrapper.AuroraDatabaseCreateOwner": {
8473
8650
  "assembly": "rds-aurora-bootstrapper",
8474
8651
  "base": "constructs.Construct",
@@ -8964,6 +9141,6 @@
8964
9141
  "symbolId": "src/constructs/aurora-database-create-user:AuroraDatabaseCreateUserProps"
8965
9142
  }
8966
9143
  },
8967
- "version": "0.3.7",
8968
- "fingerprint": "95kA64H4UhHzj1RgNVhcHPnVhdj3xHoiEY2zVhWu5cA="
9144
+ "version": "0.4.0",
9145
+ "fingerprint": "p3X/SuawteEclyZRqjkSqWuCLp8fxp9jaaT+OKTSxxk="
8969
9146
  }
package/API.md CHANGED
@@ -2,6 +2,165 @@
2
2
 
3
3
  ## Constructs <a name="Constructs" id="Constructs"></a>
4
4
 
5
+ ### AuroraDatabaseCreateMigrator <a name="AuroraDatabaseCreateMigrator" id="rds-aurora-bootstrapper.AuroraDatabaseCreateMigrator"></a>
6
+
7
+ CDK construct that provisions a PostgreSQL migrator user on an Aurora cluster using a custom resource backed by the RDS Data API.
8
+
9
+ On Create, the handler creates a `LOGIN` role from
10
+ {@link AuroraDatabaseCreateMigratorProps.migratorUserCredentials} when the
11
+ role is missing, grants `CONNECT` on the database, grants membership in
12
+ {@link AuroraDatabaseCreateMigratorProps.ownerUsername}, and sets
13
+ `search_path` to {@link AuroraDatabaseCreateMigratorProps.schemaName}. Role
14
+ creation is idempotent when the username already exists.
15
+
16
+ The master username is derived from the `username` field of
17
+ {@link AuroraDatabaseCreateMigratorProps.dbMasterUserCredentials} through a
18
+ Secrets Manager dynamic reference; callers do not pass it explicitly.
19
+
20
+ Ensure {@link AuroraDatabaseCreateMigratorProps.ownerUsername} and
21
+ {@link AuroraDatabaseCreateMigratorProps.schemaName} already exist (for
22
+ example via {@link AuroraDatabaseCreateOwner } and
23
+ {@link AuroraDatabaseCreateSchema }) before this resource runs.
24
+
25
+ #### Initializers <a name="Initializers" id="rds-aurora-bootstrapper.AuroraDatabaseCreateMigrator.Initializer"></a>
26
+
27
+ ```typescript
28
+ import { AuroraDatabaseCreateMigrator } from 'rds-aurora-bootstrapper'
29
+
30
+ new AuroraDatabaseCreateMigrator(scope: Construct, id: string, props: AuroraDatabaseCreateMigratorProps)
31
+ ```
32
+
33
+ | **Name** | **Type** | **Description** |
34
+ | --- | --- | --- |
35
+ | <code><a href="#rds-aurora-bootstrapper.AuroraDatabaseCreateMigrator.Initializer.parameter.scope">scope</a></code> | <code>constructs.Construct</code> | - Parent construct. |
36
+ | <code><a href="#rds-aurora-bootstrapper.AuroraDatabaseCreateMigrator.Initializer.parameter.id">id</a></code> | <code>string</code> | - Construct identifier. |
37
+ | <code><a href="#rds-aurora-bootstrapper.AuroraDatabaseCreateMigrator.Initializer.parameter.props">props</a></code> | <code><a href="#rds-aurora-bootstrapper.AuroraDatabaseCreateMigratorProps">AuroraDatabaseCreateMigratorProps</a></code> | - Configuration for the migrator user. |
38
+
39
+ ---
40
+
41
+ ##### `scope`<sup>Required</sup> <a name="scope" id="rds-aurora-bootstrapper.AuroraDatabaseCreateMigrator.Initializer.parameter.scope"></a>
42
+
43
+ - *Type:* constructs.Construct
44
+
45
+ Parent construct.
46
+
47
+ ---
48
+
49
+ ##### `id`<sup>Required</sup> <a name="id" id="rds-aurora-bootstrapper.AuroraDatabaseCreateMigrator.Initializer.parameter.id"></a>
50
+
51
+ - *Type:* string
52
+
53
+ Construct identifier.
54
+
55
+ ---
56
+
57
+ ##### `props`<sup>Required</sup> <a name="props" id="rds-aurora-bootstrapper.AuroraDatabaseCreateMigrator.Initializer.parameter.props"></a>
58
+
59
+ - *Type:* <a href="#rds-aurora-bootstrapper.AuroraDatabaseCreateMigratorProps">AuroraDatabaseCreateMigratorProps</a>
60
+
61
+ Configuration for the migrator user.
62
+
63
+ ---
64
+
65
+ #### Methods <a name="Methods" id="Methods"></a>
66
+
67
+ | **Name** | **Description** |
68
+ | --- | --- |
69
+ | <code><a href="#rds-aurora-bootstrapper.AuroraDatabaseCreateMigrator.toString">toString</a></code> | Returns a string representation of this construct. |
70
+ | <code><a href="#rds-aurora-bootstrapper.AuroraDatabaseCreateMigrator.with">with</a></code> | Applies one or more mixins to this construct. |
71
+
72
+ ---
73
+
74
+ ##### `toString` <a name="toString" id="rds-aurora-bootstrapper.AuroraDatabaseCreateMigrator.toString"></a>
75
+
76
+ ```typescript
77
+ public toString(): string
78
+ ```
79
+
80
+ Returns a string representation of this construct.
81
+
82
+ ##### `with` <a name="with" id="rds-aurora-bootstrapper.AuroraDatabaseCreateMigrator.with"></a>
83
+
84
+ ```typescript
85
+ public with(mixins: ...IMixin[]): IConstruct
86
+ ```
87
+
88
+ Applies one or more mixins to this construct.
89
+
90
+ Mixins are applied in order. The list of constructs is captured at the
91
+ start of the call, so constructs added by a mixin will not be visited.
92
+ Use multiple `with()` calls if subsequent mixins should apply to added
93
+ constructs.
94
+
95
+ ###### `mixins`<sup>Required</sup> <a name="mixins" id="rds-aurora-bootstrapper.AuroraDatabaseCreateMigrator.with.parameter.mixins"></a>
96
+
97
+ - *Type:* ...constructs.IMixin[]
98
+
99
+ The mixins to apply.
100
+
101
+ ---
102
+
103
+ #### Static Functions <a name="Static Functions" id="Static Functions"></a>
104
+
105
+ | **Name** | **Description** |
106
+ | --- | --- |
107
+ | <code><a href="#rds-aurora-bootstrapper.AuroraDatabaseCreateMigrator.isConstruct">isConstruct</a></code> | Checks if `x` is a construct. |
108
+
109
+ ---
110
+
111
+ ##### `isConstruct` <a name="isConstruct" id="rds-aurora-bootstrapper.AuroraDatabaseCreateMigrator.isConstruct"></a>
112
+
113
+ ```typescript
114
+ import { AuroraDatabaseCreateMigrator } from 'rds-aurora-bootstrapper'
115
+
116
+ AuroraDatabaseCreateMigrator.isConstruct(x: any)
117
+ ```
118
+
119
+ Checks if `x` is a construct.
120
+
121
+ Use this method instead of `instanceof` to properly detect `Construct`
122
+ instances, even when the construct library is symlinked.
123
+
124
+ Explanation: in JavaScript, multiple copies of the `constructs` library on
125
+ disk are seen as independent, completely different libraries. As a
126
+ consequence, the class `Construct` in each copy of the `constructs` library
127
+ is seen as a different class, and an instance of one class will not test as
128
+ `instanceof` the other class. `npm install` will not create installations
129
+ like this, but users may manually symlink construct libraries together or
130
+ use a monorepo tool: in those cases, multiple copies of the `constructs`
131
+ library can be accidentally installed, and `instanceof` will behave
132
+ unpredictably. It is safest to avoid using `instanceof`, and using
133
+ this type-testing method instead.
134
+
135
+ ###### `x`<sup>Required</sup> <a name="x" id="rds-aurora-bootstrapper.AuroraDatabaseCreateMigrator.isConstruct.parameter.x"></a>
136
+
137
+ - *Type:* any
138
+
139
+ Any object.
140
+
141
+ ---
142
+
143
+ #### Properties <a name="Properties" id="Properties"></a>
144
+
145
+ | **Name** | **Type** | **Description** |
146
+ | --- | --- | --- |
147
+ | <code><a href="#rds-aurora-bootstrapper.AuroraDatabaseCreateMigrator.property.node">node</a></code> | <code>constructs.Node</code> | The tree node. |
148
+
149
+ ---
150
+
151
+ ##### `node`<sup>Required</sup> <a name="node" id="rds-aurora-bootstrapper.AuroraDatabaseCreateMigrator.property.node"></a>
152
+
153
+ ```typescript
154
+ public readonly node: Node;
155
+ ```
156
+
157
+ - *Type:* constructs.Node
158
+
159
+ The tree node.
160
+
161
+ ---
162
+
163
+
5
164
  ### AuroraDatabaseCreateOwner <a name="AuroraDatabaseCreateOwner" id="rds-aurora-bootstrapper.AuroraDatabaseCreateOwner"></a>
6
165
 
7
166
  CDK construct that provisions a PostgreSQL owner role on an Aurora cluster using a custom resource backed by the RDS Data API.
@@ -462,6 +621,111 @@ The tree node.
462
621
 
463
622
  ## Structs <a name="Structs" id="Structs"></a>
464
623
 
624
+ ### AuroraDatabaseCreateMigratorProps <a name="AuroraDatabaseCreateMigratorProps" id="rds-aurora-bootstrapper.AuroraDatabaseCreateMigratorProps"></a>
625
+
626
+ Properties for {@link AuroraDatabaseCreateMigrator}.
627
+
628
+ #### Initializer <a name="Initializer" id="rds-aurora-bootstrapper.AuroraDatabaseCreateMigratorProps.Initializer"></a>
629
+
630
+ ```typescript
631
+ import { AuroraDatabaseCreateMigratorProps } from 'rds-aurora-bootstrapper'
632
+
633
+ const auroraDatabaseCreateMigratorProps: AuroraDatabaseCreateMigratorProps = { ... }
634
+ ```
635
+
636
+ #### Properties <a name="Properties" id="Properties"></a>
637
+
638
+ | **Name** | **Type** | **Description** |
639
+ | --- | --- | --- |
640
+ | <code><a href="#rds-aurora-bootstrapper.AuroraDatabaseCreateMigratorProps.property.dbCluster">dbCluster</a></code> | <code>aws-cdk-lib.aws_rds.DatabaseCluster</code> | Aurora database cluster where the migrator role is created. |
641
+ | <code><a href="#rds-aurora-bootstrapper.AuroraDatabaseCreateMigratorProps.property.dbMasterUserCredentials">dbMasterUserCredentials</a></code> | <code>aws-cdk-lib.aws_secretsmanager.Secret</code> | Secrets Manager secret holding the Aurora master user credentials. |
642
+ | <code><a href="#rds-aurora-bootstrapper.AuroraDatabaseCreateMigratorProps.property.dbName">dbName</a></code> | <code>string</code> | Name of the PostgreSQL database targeted by the custom resource. |
643
+ | <code><a href="#rds-aurora-bootstrapper.AuroraDatabaseCreateMigratorProps.property.migratorUserCredentials">migratorUserCredentials</a></code> | <code>aws-cdk-lib.aws_secretsmanager.Secret</code> | Secrets Manager secret holding the migrator user credentials. |
644
+ | <code><a href="#rds-aurora-bootstrapper.AuroraDatabaseCreateMigratorProps.property.ownerUsername">ownerUsername</a></code> | <code>string</code> | Username of the existing owner role granted to the migrator. |
645
+ | <code><a href="#rds-aurora-bootstrapper.AuroraDatabaseCreateMigratorProps.property.schemaName">schemaName</a></code> | <code>string</code> | Name of the PostgreSQL schema used as the migrator's `search_path`. |
646
+
647
+ ---
648
+
649
+ ##### `dbCluster`<sup>Required</sup> <a name="dbCluster" id="rds-aurora-bootstrapper.AuroraDatabaseCreateMigratorProps.property.dbCluster"></a>
650
+
651
+ ```typescript
652
+ public readonly dbCluster: DatabaseCluster;
653
+ ```
654
+
655
+ - *Type:* aws-cdk-lib.aws_rds.DatabaseCluster
656
+
657
+ Aurora database cluster where the migrator role is created.
658
+
659
+ ---
660
+
661
+ ##### `dbMasterUserCredentials`<sup>Required</sup> <a name="dbMasterUserCredentials" id="rds-aurora-bootstrapper.AuroraDatabaseCreateMigratorProps.property.dbMasterUserCredentials"></a>
662
+
663
+ ```typescript
664
+ public readonly dbMasterUserCredentials: Secret;
665
+ ```
666
+
667
+ - *Type:* aws-cdk-lib.aws_secretsmanager.Secret
668
+
669
+ Secrets Manager secret holding the Aurora master user credentials.
670
+
671
+ The `username` field is passed to the custom resource via a dynamic reference.
672
+
673
+ ---
674
+
675
+ ##### `dbName`<sup>Required</sup> <a name="dbName" id="rds-aurora-bootstrapper.AuroraDatabaseCreateMigratorProps.property.dbName"></a>
676
+
677
+ ```typescript
678
+ public readonly dbName: string;
679
+ ```
680
+
681
+ - *Type:* string
682
+
683
+ Name of the PostgreSQL database targeted by the custom resource.
684
+
685
+ ---
686
+
687
+ ##### `migratorUserCredentials`<sup>Required</sup> <a name="migratorUserCredentials" id="rds-aurora-bootstrapper.AuroraDatabaseCreateMigratorProps.property.migratorUserCredentials"></a>
688
+
689
+ ```typescript
690
+ public readonly migratorUserCredentials: Secret;
691
+ ```
692
+
693
+ - *Type:* aws-cdk-lib.aws_secretsmanager.Secret
694
+
695
+ Secrets Manager secret holding the migrator user credentials.
696
+
697
+ The handler reads `username` and `password` at runtime to create the role.
698
+
699
+ ---
700
+
701
+ ##### `ownerUsername`<sup>Required</sup> <a name="ownerUsername" id="rds-aurora-bootstrapper.AuroraDatabaseCreateMigratorProps.property.ownerUsername"></a>
702
+
703
+ ```typescript
704
+ public readonly ownerUsername: string;
705
+ ```
706
+
707
+ - *Type:* string
708
+
709
+ Username of the existing owner role granted to the migrator.
710
+
711
+ Must match {@link SAFE_POSTGRESQL_IDENTIFIER_PATTERN }.
712
+
713
+ ---
714
+
715
+ ##### `schemaName`<sup>Required</sup> <a name="schemaName" id="rds-aurora-bootstrapper.AuroraDatabaseCreateMigratorProps.property.schemaName"></a>
716
+
717
+ ```typescript
718
+ public readonly schemaName: string;
719
+ ```
720
+
721
+ - *Type:* string
722
+
723
+ Name of the PostgreSQL schema used as the migrator's `search_path`.
724
+
725
+ Must match {@link SAFE_POSTGRESQL_IDENTIFIER_PATTERN }.
726
+
727
+ ---
728
+
465
729
  ### AuroraDatabaseCreateOwnerProps <a name="AuroraDatabaseCreateOwnerProps" id="rds-aurora-bootstrapper.AuroraDatabaseCreateOwnerProps"></a>
466
730
 
467
731
  Properties for {@link AuroraDatabaseCreateOwner}.
package/README.md CHANGED
@@ -11,7 +11,8 @@ AWS CDK constructs for bootstrapping Aurora PostgreSQL databases via the RDS Dat
11
11
  - **`AuroraDatabaseCreateOwner`** — creates a `NOLOGIN NOINHERIT` owner role and grants it to the master user
12
12
  - **`AuroraDatabaseCreateSchema`** — creates a schema, assigns ownership to an existing owner role, and optionally drops the `public` schema with `CASCADE`
13
13
  - **`AuroraDatabaseCreateUser`** — creates a `LOGIN` application user from a Secrets Manager credential secret, grants `CONNECT` / schema `USAGE` / table DML, and sets default privileges for the owner role
14
- - Idempotent owner and user role creation — skips creation when the role already exists
14
+ - **`AuroraDatabaseCreateMigrator`** — creates a `LOGIN` migrator user from a Secrets Manager credential secret, grants `CONNECT`, grants membership in the owner role, and sets `search_path` to the target schema
15
+ - Idempotent owner, user, and migrator role creation — skips creation when the role already exists
15
16
  - Validates PostgreSQL identifiers at synthesis time (`ownerUsername`, `schemaName`)
16
17
  - Resolves the master username from the credentials secret through a CloudFormation dynamic reference
17
18
  - Bundled Lambda custom resources with IAM permissions and Secrets Manager read access configured automatically
@@ -28,7 +29,7 @@ yarn add rds-aurora-bootstrapper aws-cdk-lib constructs
28
29
 
29
30
  ## Usage
30
31
 
31
- Provision resources in order: owner role → schema → application user.
32
+ Provision resources in order: owner role → schema → migrator user → application user.
32
33
 
33
34
  ```typescript
34
35
  import { Stack } from 'aws-cdk-lib';
@@ -44,6 +45,7 @@ import { Construct } from 'constructs';
44
45
  import {
45
46
  AuroraDatabaseCreateOwner,
46
47
  AuroraDatabaseCreateSchema,
48
+ AuroraDatabaseCreateMigrator,
47
49
  AuroraDatabaseCreateUser,
48
50
  } from 'rds-aurora-bootstrapper';
49
51
 
@@ -60,6 +62,13 @@ export class MyStack extends Stack {
60
62
  writer: ClusterInstance.provisioned('writer'),
61
63
  });
62
64
  const masterUserSecret = new Secret(this, 'MasterUserSecret');
65
+ const migratorUserSecret = new Secret(this, 'MigratorUserSecret', {
66
+ generateSecretString: {
67
+ secretStringTemplate: JSON.stringify({ username: 'app_migrator' }),
68
+ generateStringKey: 'password',
69
+ excludePunctuation: true,
70
+ },
71
+ });
63
72
  const appUserSecret = new Secret(this, 'AppUserSecret', {
64
73
  generateSecretString: {
65
74
  secretStringTemplate: JSON.stringify({ username: 'app_user' }),
@@ -85,6 +94,16 @@ export class MyStack extends Stack {
85
94
  });
86
95
  createSchema.node.addDependency(createOwner);
87
96
 
97
+ const createMigrator = new AuroraDatabaseCreateMigrator(this, 'CreateMigrator', {
98
+ dbMasterUserCredentials: masterUserSecret,
99
+ migratorUserCredentials: migratorUserSecret,
100
+ dbCluster: cluster,
101
+ dbName: 'appdb',
102
+ ownerUsername: 'app_owner',
103
+ schemaName: 'app_schema',
104
+ });
105
+ createMigrator.node.addDependency(createSchema);
106
+
88
107
  const createUser = new AuroraDatabaseCreateUser(this, 'CreateUser', {
89
108
  dbMasterUserCredentials: masterUserSecret,
90
109
  targetUserCredentials: appUserSecret,
@@ -120,6 +139,17 @@ export class MyStack extends Stack {
120
139
  | `schemaName` | `string` | Name of the PostgreSQL schema to create. Must match `^[a-zA-Z_][a-zA-Z0-9_-]*$`. |
121
140
  | `isDropPublicSchema` | `boolean` | When `true`, drops the `public` schema with `CASCADE` after creating the target schema. |
122
141
 
142
+ ### `AuroraDatabaseCreateMigratorProps`
143
+
144
+ | Property | Type | Description |
145
+ | --- | --- | --- |
146
+ | `dbMasterUserCredentials` | `Secret` | Secrets Manager secret with Aurora master credentials. The `username` field is passed to the custom resource via a dynamic reference. |
147
+ | `migratorUserCredentials` | `Secret` | Secrets Manager secret with the migrator user credentials (`username` and `password`). Used at runtime to create the `LOGIN` role. |
148
+ | `dbCluster` | `DatabaseCluster` | Aurora database cluster where the migrator role is created. |
149
+ | `dbName` | `string` | PostgreSQL database name targeted by the custom resource. |
150
+ | `ownerUsername` | `string` | Username of the existing owner role granted to the migrator. Must match `^[a-zA-Z_][a-zA-Z0-9_-]*$`. |
151
+ | `schemaName` | `string` | Name of the PostgreSQL schema used as the migrator's `search_path`. Must match `^[a-zA-Z_][a-zA-Z0-9_-]*$`. |
152
+
123
153
  ### `AuroraDatabaseCreateUserProps`
124
154
 
125
155
  | Property | Type | Description |
@@ -137,7 +167,7 @@ export class MyStack extends Stack {
137
167
  - `aws-cdk-lib` `^2.232.0`
138
168
  - `constructs` `^10.5.1`
139
169
  - Aurora PostgreSQL cluster with the [RDS Data API](https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/data-api.html) enabled
140
- - Secrets Manager secrets containing `username` and `password` fields (master credentials, and application user credentials for `AuroraDatabaseCreateUser`)
170
+ - Secrets Manager secrets containing `username` and `password` fields (master credentials, and application / migrator user credentials for `AuroraDatabaseCreateUser` / `AuroraDatabaseCreateMigrator`)
141
171
 
142
172
  ## License
143
173