rds-aurora-bootstrapper 0.2.2 → 0.3.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/.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": "5.9.44 (build 150b837)",
8443
+ "jsiiVersion": "6.0.5 (build 4738da5)",
8444
8444
  "keywords": [
8445
8445
  "cdk"
8446
8446
  ],
@@ -8455,7 +8455,7 @@
8455
8455
  },
8456
8456
  "name": "rds-aurora-bootstrapper",
8457
8457
  "readme": {
8458
- "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.\n\n## Features\n\n- **`AuroraDatabaseCreateOwner`** — provisions a PostgreSQL owner role on an Aurora cluster via the RDS Data API\n- **`AuroraDatabaseCreateSchema`** — creates a PostgreSQL schema, assigns ownership to an existing owner role, and optionally drops the `public` schema with `CASCADE`\n- Creates a `NOLOGIN NOINHERIT` owner role and grants it to the master user inside a transaction\n- Idempotent owner creation — skips role creation when the owner role already exists\n- Validates PostgreSQL identifiers at synthesis time (`ownerUsername`, `schemaName`)\n- Master username is resolved 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\nCreate the owner role first, then create the application schema:\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} 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\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}\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## 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 secret containing `username` and `password` fields (standard RDS master credential format)\n\n## License\n\nThis project is licensed under the Apache-2.0 License.\n"
8458
+ "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
8459
  },
8460
8460
  "repository": {
8461
8461
  "type": "git",
@@ -8784,8 +8784,185 @@
8784
8784
  }
8785
8785
  ],
8786
8786
  "symbolId": "src/constructs/aurora-database-create-schema:AuroraDatabaseCreateSchemaProps"
8787
+ },
8788
+ "rds-aurora-bootstrapper.AuroraDatabaseCreateUser": {
8789
+ "assembly": "rds-aurora-bootstrapper",
8790
+ "base": "constructs.Construct",
8791
+ "docs": {
8792
+ "remarks": "On Create, the handler creates a `LOGIN` role from\n{@link AuroraDatabaseCreateUserProps.targetUserCredentials} when the role is\nmissing, grants `CONNECT` on the database, `USAGE` on the schema, DML on\nexisting tables, and default privileges for future tables owned by\n{@link AuroraDatabaseCreateUserProps.ownerUsername}. Role creation is\nidempotent when the username already exists.\n\nThe master username is derived from the `username` field of\n{@link AuroraDatabaseCreateUserProps.dbMasterUserCredentials} through a\nSecrets Manager dynamic reference; callers do not pass it explicitly.\n\nEnsure {@link AuroraDatabaseCreateUserProps.ownerUsername} and\n{@link AuroraDatabaseCreateUserProps.schemaName} already exist (for example\nvia {@link AuroraDatabaseCreateOwner } and {@link AuroraDatabaseCreateSchema })\nbefore this resource runs.",
8793
+ "stability": "stable",
8794
+ "summary": "CDK construct that provisions a PostgreSQL application user on an Aurora cluster using a custom resource backed by the RDS Data API."
8795
+ },
8796
+ "fqn": "rds-aurora-bootstrapper.AuroraDatabaseCreateUser",
8797
+ "initializer": {
8798
+ "docs": {
8799
+ "custom": {
8800
+ "throws": "Error when `ownerUsername` or `schemaName` fails identifier validation."
8801
+ },
8802
+ "stability": "stable",
8803
+ "summary": "Creates the custom resource that provisions the application database user."
8804
+ },
8805
+ "locationInModule": {
8806
+ "filename": "src/constructs/aurora-database-create-user.ts",
8807
+ "line": 70
8808
+ },
8809
+ "parameters": [
8810
+ {
8811
+ "docs": {
8812
+ "summary": "- Parent construct."
8813
+ },
8814
+ "name": "scope",
8815
+ "type": {
8816
+ "fqn": "constructs.Construct"
8817
+ }
8818
+ },
8819
+ {
8820
+ "docs": {
8821
+ "summary": "- Construct identifier."
8822
+ },
8823
+ "name": "id",
8824
+ "type": {
8825
+ "primitive": "string"
8826
+ }
8827
+ },
8828
+ {
8829
+ "docs": {
8830
+ "summary": "- Configuration for the database user."
8831
+ },
8832
+ "name": "props",
8833
+ "type": {
8834
+ "fqn": "rds-aurora-bootstrapper.AuroraDatabaseCreateUserProps"
8835
+ }
8836
+ }
8837
+ ]
8838
+ },
8839
+ "kind": "class",
8840
+ "locationInModule": {
8841
+ "filename": "src/constructs/aurora-database-create-user.ts",
8842
+ "line": 61
8843
+ },
8844
+ "name": "AuroraDatabaseCreateUser",
8845
+ "symbolId": "src/constructs/aurora-database-create-user:AuroraDatabaseCreateUser"
8846
+ },
8847
+ "rds-aurora-bootstrapper.AuroraDatabaseCreateUserProps": {
8848
+ "assembly": "rds-aurora-bootstrapper",
8849
+ "datatype": true,
8850
+ "docs": {
8851
+ "stability": "stable",
8852
+ "summary": "Properties for {@link AuroraDatabaseCreateUser}."
8853
+ },
8854
+ "fqn": "rds-aurora-bootstrapper.AuroraDatabaseCreateUserProps",
8855
+ "kind": "interface",
8856
+ "locationInModule": {
8857
+ "filename": "src/constructs/aurora-database-create-user.ts",
8858
+ "line": 14
8859
+ },
8860
+ "name": "AuroraDatabaseCreateUserProps",
8861
+ "properties": [
8862
+ {
8863
+ "abstract": true,
8864
+ "docs": {
8865
+ "stability": "stable",
8866
+ "summary": "Aurora database cluster where the user role is created."
8867
+ },
8868
+ "immutable": true,
8869
+ "locationInModule": {
8870
+ "filename": "src/constructs/aurora-database-create-user.ts",
8871
+ "line": 26
8872
+ },
8873
+ "name": "dbCluster",
8874
+ "type": {
8875
+ "fqn": "aws-cdk-lib.aws_rds.DatabaseCluster"
8876
+ }
8877
+ },
8878
+ {
8879
+ "abstract": true,
8880
+ "docs": {
8881
+ "remarks": "The `username` field is passed to the custom resource via a dynamic reference.",
8882
+ "stability": "stable",
8883
+ "summary": "Secrets Manager secret holding the Aurora master user credentials."
8884
+ },
8885
+ "immutable": true,
8886
+ "locationInModule": {
8887
+ "filename": "src/constructs/aurora-database-create-user.ts",
8888
+ "line": 19
8889
+ },
8890
+ "name": "dbMasterUserCredentials",
8891
+ "type": {
8892
+ "fqn": "aws-cdk-lib.aws_secretsmanager.Secret"
8893
+ }
8894
+ },
8895
+ {
8896
+ "abstract": true,
8897
+ "docs": {
8898
+ "stability": "stable",
8899
+ "summary": "Name of the PostgreSQL database targeted by the custom resource."
8900
+ },
8901
+ "immutable": true,
8902
+ "locationInModule": {
8903
+ "filename": "src/constructs/aurora-database-create-user.ts",
8904
+ "line": 28
8905
+ },
8906
+ "name": "dbName",
8907
+ "type": {
8908
+ "primitive": "string"
8909
+ }
8910
+ },
8911
+ {
8912
+ "abstract": true,
8913
+ "docs": {
8914
+ "remarks": "Must match {@link SAFE_POSTGRESQL_IDENTIFIER_PATTERN }.",
8915
+ "stability": "stable",
8916
+ "summary": "Username of the existing owner role used for default privileges."
8917
+ },
8918
+ "immutable": true,
8919
+ "locationInModule": {
8920
+ "filename": "src/constructs/aurora-database-create-user.ts",
8921
+ "line": 33
8922
+ },
8923
+ "name": "ownerUsername",
8924
+ "type": {
8925
+ "primitive": "string"
8926
+ }
8927
+ },
8928
+ {
8929
+ "abstract": true,
8930
+ "docs": {
8931
+ "remarks": "Must match {@link SAFE_POSTGRESQL_IDENTIFIER_PATTERN }.",
8932
+ "stability": "stable",
8933
+ "summary": "Name of the PostgreSQL schema that the new user is granted access to."
8934
+ },
8935
+ "immutable": true,
8936
+ "locationInModule": {
8937
+ "filename": "src/constructs/aurora-database-create-user.ts",
8938
+ "line": 38
8939
+ },
8940
+ "name": "schemaName",
8941
+ "type": {
8942
+ "primitive": "string"
8943
+ }
8944
+ },
8945
+ {
8946
+ "abstract": true,
8947
+ "docs": {
8948
+ "remarks": "The handler reads `username` and `password` at runtime to create the role.",
8949
+ "stability": "stable",
8950
+ "summary": "Secrets Manager secret holding the target application user credentials."
8951
+ },
8952
+ "immutable": true,
8953
+ "locationInModule": {
8954
+ "filename": "src/constructs/aurora-database-create-user.ts",
8955
+ "line": 24
8956
+ },
8957
+ "name": "targetUserCredentials",
8958
+ "type": {
8959
+ "fqn": "aws-cdk-lib.aws_secretsmanager.Secret"
8960
+ }
8961
+ }
8962
+ ],
8963
+ "symbolId": "src/constructs/aurora-database-create-user:AuroraDatabaseCreateUserProps"
8787
8964
  }
8788
8965
  },
8789
- "version": "0.2.2",
8790
- "fingerprint": "IC/2/w83myy1bAK/v7Tpl9navSMhQ64omhmNaTCpyAQ="
8966
+ "version": "0.3.0",
8967
+ "fingerprint": "7qLp/J996ios3AoC31PV/+r7cSo9cBSPyLH/ri0jtKw="
8791
8968
  }
package/API.md CHANGED
@@ -301,6 +301,165 @@ The tree node.
301
301
  ---
302
302
 
303
303
 
304
+ ### AuroraDatabaseCreateUser <a name="AuroraDatabaseCreateUser" id="rds-aurora-bootstrapper.AuroraDatabaseCreateUser"></a>
305
+
306
+ CDK construct that provisions a PostgreSQL application user on an Aurora cluster using a custom resource backed by the RDS Data API.
307
+
308
+ On Create, the handler creates a `LOGIN` role from
309
+ {@link AuroraDatabaseCreateUserProps.targetUserCredentials} when the role is
310
+ missing, grants `CONNECT` on the database, `USAGE` on the schema, DML on
311
+ existing tables, and default privileges for future tables owned by
312
+ {@link AuroraDatabaseCreateUserProps.ownerUsername}. Role creation is
313
+ idempotent when the username already exists.
314
+
315
+ The master username is derived from the `username` field of
316
+ {@link AuroraDatabaseCreateUserProps.dbMasterUserCredentials} through a
317
+ Secrets Manager dynamic reference; callers do not pass it explicitly.
318
+
319
+ Ensure {@link AuroraDatabaseCreateUserProps.ownerUsername} and
320
+ {@link AuroraDatabaseCreateUserProps.schemaName} already exist (for example
321
+ via {@link AuroraDatabaseCreateOwner } and {@link AuroraDatabaseCreateSchema })
322
+ before this resource runs.
323
+
324
+ #### Initializers <a name="Initializers" id="rds-aurora-bootstrapper.AuroraDatabaseCreateUser.Initializer"></a>
325
+
326
+ ```typescript
327
+ import { AuroraDatabaseCreateUser } from 'rds-aurora-bootstrapper'
328
+
329
+ new AuroraDatabaseCreateUser(scope: Construct, id: string, props: AuroraDatabaseCreateUserProps)
330
+ ```
331
+
332
+ | **Name** | **Type** | **Description** |
333
+ | --- | --- | --- |
334
+ | <code><a href="#rds-aurora-bootstrapper.AuroraDatabaseCreateUser.Initializer.parameter.scope">scope</a></code> | <code>constructs.Construct</code> | - Parent construct. |
335
+ | <code><a href="#rds-aurora-bootstrapper.AuroraDatabaseCreateUser.Initializer.parameter.id">id</a></code> | <code>string</code> | - Construct identifier. |
336
+ | <code><a href="#rds-aurora-bootstrapper.AuroraDatabaseCreateUser.Initializer.parameter.props">props</a></code> | <code><a href="#rds-aurora-bootstrapper.AuroraDatabaseCreateUserProps">AuroraDatabaseCreateUserProps</a></code> | - Configuration for the database user. |
337
+
338
+ ---
339
+
340
+ ##### `scope`<sup>Required</sup> <a name="scope" id="rds-aurora-bootstrapper.AuroraDatabaseCreateUser.Initializer.parameter.scope"></a>
341
+
342
+ - *Type:* constructs.Construct
343
+
344
+ Parent construct.
345
+
346
+ ---
347
+
348
+ ##### `id`<sup>Required</sup> <a name="id" id="rds-aurora-bootstrapper.AuroraDatabaseCreateUser.Initializer.parameter.id"></a>
349
+
350
+ - *Type:* string
351
+
352
+ Construct identifier.
353
+
354
+ ---
355
+
356
+ ##### `props`<sup>Required</sup> <a name="props" id="rds-aurora-bootstrapper.AuroraDatabaseCreateUser.Initializer.parameter.props"></a>
357
+
358
+ - *Type:* <a href="#rds-aurora-bootstrapper.AuroraDatabaseCreateUserProps">AuroraDatabaseCreateUserProps</a>
359
+
360
+ Configuration for the database user.
361
+
362
+ ---
363
+
364
+ #### Methods <a name="Methods" id="Methods"></a>
365
+
366
+ | **Name** | **Description** |
367
+ | --- | --- |
368
+ | <code><a href="#rds-aurora-bootstrapper.AuroraDatabaseCreateUser.toString">toString</a></code> | Returns a string representation of this construct. |
369
+ | <code><a href="#rds-aurora-bootstrapper.AuroraDatabaseCreateUser.with">with</a></code> | Applies one or more mixins to this construct. |
370
+
371
+ ---
372
+
373
+ ##### `toString` <a name="toString" id="rds-aurora-bootstrapper.AuroraDatabaseCreateUser.toString"></a>
374
+
375
+ ```typescript
376
+ public toString(): string
377
+ ```
378
+
379
+ Returns a string representation of this construct.
380
+
381
+ ##### `with` <a name="with" id="rds-aurora-bootstrapper.AuroraDatabaseCreateUser.with"></a>
382
+
383
+ ```typescript
384
+ public with(mixins: ...IMixin[]): IConstruct
385
+ ```
386
+
387
+ Applies one or more mixins to this construct.
388
+
389
+ Mixins are applied in order. The list of constructs is captured at the
390
+ start of the call, so constructs added by a mixin will not be visited.
391
+ Use multiple `with()` calls if subsequent mixins should apply to added
392
+ constructs.
393
+
394
+ ###### `mixins`<sup>Required</sup> <a name="mixins" id="rds-aurora-bootstrapper.AuroraDatabaseCreateUser.with.parameter.mixins"></a>
395
+
396
+ - *Type:* ...constructs.IMixin[]
397
+
398
+ The mixins to apply.
399
+
400
+ ---
401
+
402
+ #### Static Functions <a name="Static Functions" id="Static Functions"></a>
403
+
404
+ | **Name** | **Description** |
405
+ | --- | --- |
406
+ | <code><a href="#rds-aurora-bootstrapper.AuroraDatabaseCreateUser.isConstruct">isConstruct</a></code> | Checks if `x` is a construct. |
407
+
408
+ ---
409
+
410
+ ##### `isConstruct` <a name="isConstruct" id="rds-aurora-bootstrapper.AuroraDatabaseCreateUser.isConstruct"></a>
411
+
412
+ ```typescript
413
+ import { AuroraDatabaseCreateUser } from 'rds-aurora-bootstrapper'
414
+
415
+ AuroraDatabaseCreateUser.isConstruct(x: any)
416
+ ```
417
+
418
+ Checks if `x` is a construct.
419
+
420
+ Use this method instead of `instanceof` to properly detect `Construct`
421
+ instances, even when the construct library is symlinked.
422
+
423
+ Explanation: in JavaScript, multiple copies of the `constructs` library on
424
+ disk are seen as independent, completely different libraries. As a
425
+ consequence, the class `Construct` in each copy of the `constructs` library
426
+ is seen as a different class, and an instance of one class will not test as
427
+ `instanceof` the other class. `npm install` will not create installations
428
+ like this, but users may manually symlink construct libraries together or
429
+ use a monorepo tool: in those cases, multiple copies of the `constructs`
430
+ library can be accidentally installed, and `instanceof` will behave
431
+ unpredictably. It is safest to avoid using `instanceof`, and using
432
+ this type-testing method instead.
433
+
434
+ ###### `x`<sup>Required</sup> <a name="x" id="rds-aurora-bootstrapper.AuroraDatabaseCreateUser.isConstruct.parameter.x"></a>
435
+
436
+ - *Type:* any
437
+
438
+ Any object.
439
+
440
+ ---
441
+
442
+ #### Properties <a name="Properties" id="Properties"></a>
443
+
444
+ | **Name** | **Type** | **Description** |
445
+ | --- | --- | --- |
446
+ | <code><a href="#rds-aurora-bootstrapper.AuroraDatabaseCreateUser.property.node">node</a></code> | <code>constructs.Node</code> | The tree node. |
447
+
448
+ ---
449
+
450
+ ##### `node`<sup>Required</sup> <a name="node" id="rds-aurora-bootstrapper.AuroraDatabaseCreateUser.property.node"></a>
451
+
452
+ ```typescript
453
+ public readonly node: Node;
454
+ ```
455
+
456
+ - *Type:* constructs.Node
457
+
458
+ The tree node.
459
+
460
+ ---
461
+
462
+
304
463
  ## Structs <a name="Structs" id="Structs"></a>
305
464
 
306
465
  ### AuroraDatabaseCreateOwnerProps <a name="AuroraDatabaseCreateOwnerProps" id="rds-aurora-bootstrapper.AuroraDatabaseCreateOwnerProps"></a>
@@ -481,5 +640,110 @@ Must match {@link SAFE_POSTGRESQL_IDENTIFIER_PATTERN }.
481
640
 
482
641
  ---
483
642
 
643
+ ### AuroraDatabaseCreateUserProps <a name="AuroraDatabaseCreateUserProps" id="rds-aurora-bootstrapper.AuroraDatabaseCreateUserProps"></a>
644
+
645
+ Properties for {@link AuroraDatabaseCreateUser}.
646
+
647
+ #### Initializer <a name="Initializer" id="rds-aurora-bootstrapper.AuroraDatabaseCreateUserProps.Initializer"></a>
648
+
649
+ ```typescript
650
+ import { AuroraDatabaseCreateUserProps } from 'rds-aurora-bootstrapper'
651
+
652
+ const auroraDatabaseCreateUserProps: AuroraDatabaseCreateUserProps = { ... }
653
+ ```
654
+
655
+ #### Properties <a name="Properties" id="Properties"></a>
656
+
657
+ | **Name** | **Type** | **Description** |
658
+ | --- | --- | --- |
659
+ | <code><a href="#rds-aurora-bootstrapper.AuroraDatabaseCreateUserProps.property.dbCluster">dbCluster</a></code> | <code>aws-cdk-lib.aws_rds.DatabaseCluster</code> | Aurora database cluster where the user role is created. |
660
+ | <code><a href="#rds-aurora-bootstrapper.AuroraDatabaseCreateUserProps.property.dbMasterUserCredentials">dbMasterUserCredentials</a></code> | <code>aws-cdk-lib.aws_secretsmanager.Secret</code> | Secrets Manager secret holding the Aurora master user credentials. |
661
+ | <code><a href="#rds-aurora-bootstrapper.AuroraDatabaseCreateUserProps.property.dbName">dbName</a></code> | <code>string</code> | Name of the PostgreSQL database targeted by the custom resource. |
662
+ | <code><a href="#rds-aurora-bootstrapper.AuroraDatabaseCreateUserProps.property.ownerUsername">ownerUsername</a></code> | <code>string</code> | Username of the existing owner role used for default privileges. |
663
+ | <code><a href="#rds-aurora-bootstrapper.AuroraDatabaseCreateUserProps.property.schemaName">schemaName</a></code> | <code>string</code> | Name of the PostgreSQL schema that the new user is granted access to. |
664
+ | <code><a href="#rds-aurora-bootstrapper.AuroraDatabaseCreateUserProps.property.targetUserCredentials">targetUserCredentials</a></code> | <code>aws-cdk-lib.aws_secretsmanager.Secret</code> | Secrets Manager secret holding the target application user credentials. |
665
+
666
+ ---
667
+
668
+ ##### `dbCluster`<sup>Required</sup> <a name="dbCluster" id="rds-aurora-bootstrapper.AuroraDatabaseCreateUserProps.property.dbCluster"></a>
669
+
670
+ ```typescript
671
+ public readonly dbCluster: DatabaseCluster;
672
+ ```
673
+
674
+ - *Type:* aws-cdk-lib.aws_rds.DatabaseCluster
675
+
676
+ Aurora database cluster where the user role is created.
677
+
678
+ ---
679
+
680
+ ##### `dbMasterUserCredentials`<sup>Required</sup> <a name="dbMasterUserCredentials" id="rds-aurora-bootstrapper.AuroraDatabaseCreateUserProps.property.dbMasterUserCredentials"></a>
681
+
682
+ ```typescript
683
+ public readonly dbMasterUserCredentials: Secret;
684
+ ```
685
+
686
+ - *Type:* aws-cdk-lib.aws_secretsmanager.Secret
687
+
688
+ Secrets Manager secret holding the Aurora master user credentials.
689
+
690
+ The `username` field is passed to the custom resource via a dynamic reference.
691
+
692
+ ---
693
+
694
+ ##### `dbName`<sup>Required</sup> <a name="dbName" id="rds-aurora-bootstrapper.AuroraDatabaseCreateUserProps.property.dbName"></a>
695
+
696
+ ```typescript
697
+ public readonly dbName: string;
698
+ ```
699
+
700
+ - *Type:* string
701
+
702
+ Name of the PostgreSQL database targeted by the custom resource.
703
+
704
+ ---
705
+
706
+ ##### `ownerUsername`<sup>Required</sup> <a name="ownerUsername" id="rds-aurora-bootstrapper.AuroraDatabaseCreateUserProps.property.ownerUsername"></a>
707
+
708
+ ```typescript
709
+ public readonly ownerUsername: string;
710
+ ```
711
+
712
+ - *Type:* string
713
+
714
+ Username of the existing owner role used for default privileges.
715
+
716
+ Must match {@link SAFE_POSTGRESQL_IDENTIFIER_PATTERN }.
717
+
718
+ ---
719
+
720
+ ##### `schemaName`<sup>Required</sup> <a name="schemaName" id="rds-aurora-bootstrapper.AuroraDatabaseCreateUserProps.property.schemaName"></a>
721
+
722
+ ```typescript
723
+ public readonly schemaName: string;
724
+ ```
725
+
726
+ - *Type:* string
727
+
728
+ Name of the PostgreSQL schema that the new user is granted access to.
729
+
730
+ Must match {@link SAFE_POSTGRESQL_IDENTIFIER_PATTERN }.
731
+
732
+ ---
733
+
734
+ ##### `targetUserCredentials`<sup>Required</sup> <a name="targetUserCredentials" id="rds-aurora-bootstrapper.AuroraDatabaseCreateUserProps.property.targetUserCredentials"></a>
735
+
736
+ ```typescript
737
+ public readonly targetUserCredentials: Secret;
738
+ ```
739
+
740
+ - *Type:* aws-cdk-lib.aws_secretsmanager.Secret
741
+
742
+ Secrets Manager secret holding the target application user credentials.
743
+
744
+ The handler reads `username` and `password` at runtime to create the role.
745
+
746
+ ---
747
+
484
748
 
485
749
 
package/README.md CHANGED
@@ -4,16 +4,16 @@
4
4
  [![npm license](https://img.shields.io/npm/l/rds-aurora-bootstrapper)](https://www.npmjs.com/package/rds-aurora-bootstrapper)
5
5
  [![Node.js](https://img.shields.io/node/v/rds-aurora-bootstrapper)](https://www.npmjs.com/package/rds-aurora-bootstrapper)
6
6
 
7
- AWS CDK constructs for bootstrapping Aurora PostgreSQL databases.
7
+ AWS CDK constructs for bootstrapping Aurora PostgreSQL databases via the RDS Data API.
8
8
 
9
9
  ## Features
10
10
 
11
- - **`AuroraDatabaseCreateOwner`** — provisions a PostgreSQL owner role on an Aurora cluster via the RDS Data API
12
- - **`AuroraDatabaseCreateSchema`** — creates a PostgreSQL schema, assigns ownership to an existing owner role, and optionally drops the `public` schema with `CASCADE`
13
- - Creates a `NOLOGIN NOINHERIT` owner role and grants it to the master user inside a transaction
14
- - Idempotent owner creation — skips role creation when the owner role already exists
11
+ - **`AuroraDatabaseCreateOwner`** — creates a `NOLOGIN NOINHERIT` owner role and grants it to the master user
12
+ - **`AuroraDatabaseCreateSchema`** — creates a schema, assigns ownership to an existing owner role, and optionally drops the `public` schema with `CASCADE`
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
15
15
  - Validates PostgreSQL identifiers at synthesis time (`ownerUsername`, `schemaName`)
16
- - Master username is resolved from the credentials secret through a CloudFormation dynamic reference
16
+ - Resolves the master username from the credentials secret through a CloudFormation dynamic reference
17
17
  - Bundled Lambda custom resources with IAM permissions and Secrets Manager read access configured automatically
18
18
 
19
19
  ## Installation
@@ -28,7 +28,7 @@ yarn add rds-aurora-bootstrapper aws-cdk-lib constructs
28
28
 
29
29
  ## Usage
30
30
 
31
- Create the owner role first, then create the application schema:
31
+ Provision resources in order: owner role → schema → application user.
32
32
 
33
33
  ```typescript
34
34
  import { Stack } from 'aws-cdk-lib';
@@ -44,6 +44,7 @@ import { Construct } from 'constructs';
44
44
  import {
45
45
  AuroraDatabaseCreateOwner,
46
46
  AuroraDatabaseCreateSchema,
47
+ AuroraDatabaseCreateUser,
47
48
  } from 'rds-aurora-bootstrapper';
48
49
 
49
50
  export class MyStack extends Stack {
@@ -59,6 +60,13 @@ export class MyStack extends Stack {
59
60
  writer: ClusterInstance.provisioned('writer'),
60
61
  });
61
62
  const masterUserSecret = new Secret(this, 'MasterUserSecret');
63
+ const appUserSecret = new Secret(this, 'AppUserSecret', {
64
+ generateSecretString: {
65
+ secretStringTemplate: JSON.stringify({ username: 'app_user' }),
66
+ generateStringKey: 'password',
67
+ excludePunctuation: true,
68
+ },
69
+ });
62
70
 
63
71
  const createOwner = new AuroraDatabaseCreateOwner(this, 'CreateOwner', {
64
72
  dbMasterUserCredentials: masterUserSecret,
@@ -76,6 +84,16 @@ export class MyStack extends Stack {
76
84
  isDropPublicSchema: true,
77
85
  });
78
86
  createSchema.node.addDependency(createOwner);
87
+
88
+ const createUser = new AuroraDatabaseCreateUser(this, 'CreateUser', {
89
+ dbMasterUserCredentials: masterUserSecret,
90
+ targetUserCredentials: appUserSecret,
91
+ dbCluster: cluster,
92
+ dbName: 'appdb',
93
+ ownerUsername: 'app_owner',
94
+ schemaName: 'app_schema',
95
+ });
96
+ createUser.node.addDependency(createSchema);
79
97
  }
80
98
  }
81
99
  ```
@@ -102,13 +120,24 @@ export class MyStack extends Stack {
102
120
  | `schemaName` | `string` | Name of the PostgreSQL schema to create. Must match `^[a-zA-Z_][a-zA-Z0-9_-]*$`. |
103
121
  | `isDropPublicSchema` | `boolean` | When `true`, drops the `public` schema with `CASCADE` after creating the target schema. |
104
122
 
123
+ ### `AuroraDatabaseCreateUserProps`
124
+
125
+ | Property | Type | Description |
126
+ | --- | --- | --- |
127
+ | `dbMasterUserCredentials` | `Secret` | Secrets Manager secret with Aurora master credentials. The `username` field is passed to the custom resource via a dynamic reference. |
128
+ | `targetUserCredentials` | `Secret` | Secrets Manager secret with the application user credentials (`username` and `password`). Used at runtime to create the `LOGIN` role. |
129
+ | `dbCluster` | `DatabaseCluster` | Aurora database cluster where the user role is created. |
130
+ | `dbName` | `string` | PostgreSQL database name targeted by the custom resource. |
131
+ | `ownerUsername` | `string` | Username of the existing owner role used for default privileges. Must match `^[a-zA-Z_][a-zA-Z0-9_-]*$`. |
132
+ | `schemaName` | `string` | Name of the PostgreSQL schema the new user is granted access to. Must match `^[a-zA-Z_][a-zA-Z0-9_-]*$`. |
133
+
105
134
  ## Requirements
106
135
 
107
136
  - Node.js `>= 20.0.0`
108
137
  - `aws-cdk-lib` `^2.232.0`
109
138
  - `constructs` `^10.5.1`
110
139
  - Aurora PostgreSQL cluster with the [RDS Data API](https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/data-api.html) enabled
111
- - Secrets Manager secret containing `username` and `password` fields (standard RDS master credential format)
140
+ - Secrets Manager secrets containing `username` and `password` fields (master credentials, and application user credentials for `AuroraDatabaseCreateUser`)
112
141
 
113
142
  ## License
114
143