rds-aurora-bootstrapper 0.1.6 → 0.2.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 +189 -10
- package/API.md +257 -0
- package/README.md +34 -6
- package/assets/funcs/aurora-database-create-owner.lambda/index.js +22 -2
- package/assets/funcs/aurora-database-create-owner.lambda/index.js.map +3 -3
- package/assets/funcs/create-schema.lambda/index.js +111 -0
- package/assets/funcs/create-schema.lambda/index.js.map +7 -0
- package/lib/constructs/aurora-database-create-owner.d.ts +5 -1
- package/lib/constructs/aurora-database-create-owner.js +5 -2
- package/lib/constructs/aurora-database-create-schema.d.ts +51 -0
- package/lib/constructs/aurora-database-create-schema.js +76 -0
- package/lib/constructs/libs/postgresql/assert-identifier.d.ts +10 -0
- package/lib/constructs/libs/postgresql/assert-identifier.js +20 -0
- package/lib/constructs/libs/postgresql/identifier-pattern.d.ts +7 -0
- package/lib/constructs/libs/postgresql/identifier-pattern.js +11 -0
- package/lib/funcs/aurora-database-create-owner.lambda.d.ts +6 -2
- package/lib/funcs/aurora-database-create-owner.lambda.js +14 -5
- package/lib/funcs/create-schema-function.d.ts +13 -0
- package/lib/funcs/create-schema-function.js +56 -0
- package/lib/funcs/create-schema.lambda.d.ts +19 -0
- package/lib/funcs/create-schema.lambda.js +106 -0
- package/lib/funcs/libs/postgresql/quote-identifier.d.ts +13 -0
- package/lib/funcs/libs/postgresql/quote-identifier.js +18 -0
- package/lib/index.d.ts +1 -0
- package/lib/index.js +2 -1
- package/package.json +3 -1
package/.jsii
CHANGED
|
@@ -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[](https://www.npmjs.com/package/rds-aurora-bootstrapper)\n[](https://www.npmjs.com/package/rds-aurora-bootstrapper)\n[](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- Creates a `NOLOGIN NOINHERIT` role and grants it to the master user inside a transaction\n- Idempotent
|
|
8458
|
+
"markdown": "# RDS Aurora Bootstrapper (AWS CDK V2)\n\n[](https://www.npmjs.com/package/rds-aurora-bootstrapper)\n[](https://www.npmjs.com/package/rds-aurora-bootstrapper)\n[](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"
|
|
8459
8459
|
},
|
|
8460
8460
|
"repository": {
|
|
8461
8461
|
"type": "git",
|
|
@@ -8479,11 +8479,14 @@
|
|
|
8479
8479
|
"fqn": "rds-aurora-bootstrapper.AuroraDatabaseCreateOwner",
|
|
8480
8480
|
"initializer": {
|
|
8481
8481
|
"docs": {
|
|
8482
|
+
"custom": {
|
|
8483
|
+
"throws": "Error when `ownerUsername` fails identifier validation."
|
|
8484
|
+
},
|
|
8482
8485
|
"stability": "stable"
|
|
8483
8486
|
},
|
|
8484
8487
|
"locationInModule": {
|
|
8485
8488
|
"filename": "src/constructs/aurora-database-create-owner.ts",
|
|
8486
|
-
"line":
|
|
8489
|
+
"line": 46
|
|
8487
8490
|
},
|
|
8488
8491
|
"parameters": [
|
|
8489
8492
|
{
|
|
@@ -8518,7 +8521,7 @@
|
|
|
8518
8521
|
"kind": "class",
|
|
8519
8522
|
"locationInModule": {
|
|
8520
8523
|
"filename": "src/constructs/aurora-database-create-owner.ts",
|
|
8521
|
-
"line":
|
|
8524
|
+
"line": 39
|
|
8522
8525
|
},
|
|
8523
8526
|
"name": "AuroraDatabaseCreateOwner",
|
|
8524
8527
|
"symbolId": "src/constructs/aurora-database-create-owner:AuroraDatabaseCreateOwner"
|
|
@@ -8534,7 +8537,7 @@
|
|
|
8534
8537
|
"kind": "interface",
|
|
8535
8538
|
"locationInModule": {
|
|
8536
8539
|
"filename": "src/constructs/aurora-database-create-owner.ts",
|
|
8537
|
-
"line":
|
|
8540
|
+
"line": 14
|
|
8538
8541
|
},
|
|
8539
8542
|
"name": "AuroraDatabaseCreateOwnerProps",
|
|
8540
8543
|
"properties": [
|
|
@@ -8547,7 +8550,7 @@
|
|
|
8547
8550
|
"immutable": true,
|
|
8548
8551
|
"locationInModule": {
|
|
8549
8552
|
"filename": "src/constructs/aurora-database-create-owner.ts",
|
|
8550
|
-
"line":
|
|
8553
|
+
"line": 21
|
|
8551
8554
|
},
|
|
8552
8555
|
"name": "dbCluster",
|
|
8553
8556
|
"type": {
|
|
@@ -8564,7 +8567,7 @@
|
|
|
8564
8567
|
"immutable": true,
|
|
8565
8568
|
"locationInModule": {
|
|
8566
8569
|
"filename": "src/constructs/aurora-database-create-owner.ts",
|
|
8567
|
-
"line":
|
|
8570
|
+
"line": 19
|
|
8568
8571
|
},
|
|
8569
8572
|
"name": "dbMasterUserCredentials",
|
|
8570
8573
|
"type": {
|
|
@@ -8580,7 +8583,7 @@
|
|
|
8580
8583
|
"immutable": true,
|
|
8581
8584
|
"locationInModule": {
|
|
8582
8585
|
"filename": "src/constructs/aurora-database-create-owner.ts",
|
|
8583
|
-
"line":
|
|
8586
|
+
"line": 23
|
|
8584
8587
|
},
|
|
8585
8588
|
"name": "dbName",
|
|
8586
8589
|
"type": {
|
|
@@ -8590,13 +8593,14 @@
|
|
|
8590
8593
|
{
|
|
8591
8594
|
"abstract": true,
|
|
8592
8595
|
"docs": {
|
|
8596
|
+
"remarks": "Must match {@link SAFE_POSTGRESQL_IDENTIFIER_PATTERN }.",
|
|
8593
8597
|
"stability": "stable",
|
|
8594
8598
|
"summary": "Username of the owner role to create (`NOLOGIN`, `NOINHERIT`)."
|
|
8595
8599
|
},
|
|
8596
8600
|
"immutable": true,
|
|
8597
8601
|
"locationInModule": {
|
|
8598
8602
|
"filename": "src/constructs/aurora-database-create-owner.ts",
|
|
8599
|
-
"line":
|
|
8603
|
+
"line": 28
|
|
8600
8604
|
},
|
|
8601
8605
|
"name": "ownerUsername",
|
|
8602
8606
|
"type": {
|
|
@@ -8605,8 +8609,183 @@
|
|
|
8605
8609
|
}
|
|
8606
8610
|
],
|
|
8607
8611
|
"symbolId": "src/constructs/aurora-database-create-owner:AuroraDatabaseCreateOwnerProps"
|
|
8612
|
+
},
|
|
8613
|
+
"rds-aurora-bootstrapper.AuroraDatabaseCreateSchema": {
|
|
8614
|
+
"assembly": "rds-aurora-bootstrapper",
|
|
8615
|
+
"base": "constructs.Construct",
|
|
8616
|
+
"docs": {
|
|
8617
|
+
"remarks": "On Create, the handler creates the schema (if missing), assigns ownership to\n{@link AuroraDatabaseCreateSchemaProps.ownerUsername}, and optionally drops\nthe `public` schema. The master username is derived from the `username` field\nof {@link AuroraDatabaseCreateSchemaProps.dbMasterUserCredentials} through a\nSecrets Manager dynamic reference; callers do not pass it explicitly.\n\nEnsure {@link AuroraDatabaseCreateSchemaProps.ownerUsername} already exists\n(for example via {@link AuroraDatabaseCreateOwner }) before this resource runs.",
|
|
8618
|
+
"stability": "stable",
|
|
8619
|
+
"summary": "CDK construct that provisions a PostgreSQL schema on an Aurora cluster using a custom resource backed by the RDS Data API."
|
|
8620
|
+
},
|
|
8621
|
+
"fqn": "rds-aurora-bootstrapper.AuroraDatabaseCreateSchema",
|
|
8622
|
+
"initializer": {
|
|
8623
|
+
"docs": {
|
|
8624
|
+
"custom": {
|
|
8625
|
+
"throws": "Error when `ownerUsername` or `schemaName` fails identifier validation."
|
|
8626
|
+
},
|
|
8627
|
+
"stability": "stable"
|
|
8628
|
+
},
|
|
8629
|
+
"locationInModule": {
|
|
8630
|
+
"filename": "src/constructs/aurora-database-create-schema.ts",
|
|
8631
|
+
"line": 58
|
|
8632
|
+
},
|
|
8633
|
+
"parameters": [
|
|
8634
|
+
{
|
|
8635
|
+
"docs": {
|
|
8636
|
+
"summary": "- Parent construct."
|
|
8637
|
+
},
|
|
8638
|
+
"name": "scope",
|
|
8639
|
+
"type": {
|
|
8640
|
+
"fqn": "constructs.Construct"
|
|
8641
|
+
}
|
|
8642
|
+
},
|
|
8643
|
+
{
|
|
8644
|
+
"docs": {
|
|
8645
|
+
"summary": "- Construct identifier."
|
|
8646
|
+
},
|
|
8647
|
+
"name": "id",
|
|
8648
|
+
"type": {
|
|
8649
|
+
"primitive": "string"
|
|
8650
|
+
}
|
|
8651
|
+
},
|
|
8652
|
+
{
|
|
8653
|
+
"docs": {
|
|
8654
|
+
"summary": "- Configuration for the database schema."
|
|
8655
|
+
},
|
|
8656
|
+
"name": "props",
|
|
8657
|
+
"type": {
|
|
8658
|
+
"fqn": "rds-aurora-bootstrapper.AuroraDatabaseCreateSchemaProps"
|
|
8659
|
+
}
|
|
8660
|
+
}
|
|
8661
|
+
]
|
|
8662
|
+
},
|
|
8663
|
+
"kind": "class",
|
|
8664
|
+
"locationInModule": {
|
|
8665
|
+
"filename": "src/constructs/aurora-database-create-schema.ts",
|
|
8666
|
+
"line": 51
|
|
8667
|
+
},
|
|
8668
|
+
"name": "AuroraDatabaseCreateSchema",
|
|
8669
|
+
"symbolId": "src/constructs/aurora-database-create-schema:AuroraDatabaseCreateSchema"
|
|
8670
|
+
},
|
|
8671
|
+
"rds-aurora-bootstrapper.AuroraDatabaseCreateSchemaProps": {
|
|
8672
|
+
"assembly": "rds-aurora-bootstrapper",
|
|
8673
|
+
"datatype": true,
|
|
8674
|
+
"docs": {
|
|
8675
|
+
"stability": "stable",
|
|
8676
|
+
"summary": "Properties for {@link AuroraDatabaseCreateSchema}."
|
|
8677
|
+
},
|
|
8678
|
+
"fqn": "rds-aurora-bootstrapper.AuroraDatabaseCreateSchemaProps",
|
|
8679
|
+
"kind": "interface",
|
|
8680
|
+
"locationInModule": {
|
|
8681
|
+
"filename": "src/constructs/aurora-database-create-schema.ts",
|
|
8682
|
+
"line": 14
|
|
8683
|
+
},
|
|
8684
|
+
"name": "AuroraDatabaseCreateSchemaProps",
|
|
8685
|
+
"properties": [
|
|
8686
|
+
{
|
|
8687
|
+
"abstract": true,
|
|
8688
|
+
"docs": {
|
|
8689
|
+
"stability": "stable",
|
|
8690
|
+
"summary": "Aurora database cluster where the schema is created."
|
|
8691
|
+
},
|
|
8692
|
+
"immutable": true,
|
|
8693
|
+
"locationInModule": {
|
|
8694
|
+
"filename": "src/constructs/aurora-database-create-schema.ts",
|
|
8695
|
+
"line": 21
|
|
8696
|
+
},
|
|
8697
|
+
"name": "dbCluster",
|
|
8698
|
+
"type": {
|
|
8699
|
+
"fqn": "aws-cdk-lib.aws_rds.DatabaseCluster"
|
|
8700
|
+
}
|
|
8701
|
+
},
|
|
8702
|
+
{
|
|
8703
|
+
"abstract": true,
|
|
8704
|
+
"docs": {
|
|
8705
|
+
"remarks": "The `username` field is passed to the custom resource via a dynamic reference.",
|
|
8706
|
+
"stability": "stable",
|
|
8707
|
+
"summary": "Secrets Manager secret holding the Aurora master user credentials."
|
|
8708
|
+
},
|
|
8709
|
+
"immutable": true,
|
|
8710
|
+
"locationInModule": {
|
|
8711
|
+
"filename": "src/constructs/aurora-database-create-schema.ts",
|
|
8712
|
+
"line": 19
|
|
8713
|
+
},
|
|
8714
|
+
"name": "dbMasterUserCredentials",
|
|
8715
|
+
"type": {
|
|
8716
|
+
"fqn": "aws-cdk-lib.aws_secretsmanager.Secret"
|
|
8717
|
+
}
|
|
8718
|
+
},
|
|
8719
|
+
{
|
|
8720
|
+
"abstract": true,
|
|
8721
|
+
"docs": {
|
|
8722
|
+
"stability": "stable",
|
|
8723
|
+
"summary": "Name of the PostgreSQL database targeted by the custom resource."
|
|
8724
|
+
},
|
|
8725
|
+
"immutable": true,
|
|
8726
|
+
"locationInModule": {
|
|
8727
|
+
"filename": "src/constructs/aurora-database-create-schema.ts",
|
|
8728
|
+
"line": 23
|
|
8729
|
+
},
|
|
8730
|
+
"name": "dbName",
|
|
8731
|
+
"type": {
|
|
8732
|
+
"primitive": "string"
|
|
8733
|
+
}
|
|
8734
|
+
},
|
|
8735
|
+
{
|
|
8736
|
+
"abstract": true,
|
|
8737
|
+
"docs": {
|
|
8738
|
+
"stability": "stable",
|
|
8739
|
+
"summary": "When `true`, drops the `public` schema with `CASCADE` after creating the target schema."
|
|
8740
|
+
},
|
|
8741
|
+
"immutable": true,
|
|
8742
|
+
"locationInModule": {
|
|
8743
|
+
"filename": "src/constructs/aurora-database-create-schema.ts",
|
|
8744
|
+
"line": 35
|
|
8745
|
+
},
|
|
8746
|
+
"name": "isDropPublicSchema",
|
|
8747
|
+
"type": {
|
|
8748
|
+
"primitive": "boolean"
|
|
8749
|
+
}
|
|
8750
|
+
},
|
|
8751
|
+
{
|
|
8752
|
+
"abstract": true,
|
|
8753
|
+
"docs": {
|
|
8754
|
+
"remarks": "Must match {@link SAFE_POSTGRESQL_IDENTIFIER_PATTERN }.",
|
|
8755
|
+
"stability": "stable",
|
|
8756
|
+
"summary": "Username of the existing owner role that will own the new schema."
|
|
8757
|
+
},
|
|
8758
|
+
"immutable": true,
|
|
8759
|
+
"locationInModule": {
|
|
8760
|
+
"filename": "src/constructs/aurora-database-create-schema.ts",
|
|
8761
|
+
"line": 28
|
|
8762
|
+
},
|
|
8763
|
+
"name": "ownerUsername",
|
|
8764
|
+
"type": {
|
|
8765
|
+
"primitive": "string"
|
|
8766
|
+
}
|
|
8767
|
+
},
|
|
8768
|
+
{
|
|
8769
|
+
"abstract": true,
|
|
8770
|
+
"docs": {
|
|
8771
|
+
"remarks": "Must match {@link SAFE_POSTGRESQL_IDENTIFIER_PATTERN }.",
|
|
8772
|
+
"stability": "stable",
|
|
8773
|
+
"summary": "Name of the PostgreSQL schema to create."
|
|
8774
|
+
},
|
|
8775
|
+
"immutable": true,
|
|
8776
|
+
"locationInModule": {
|
|
8777
|
+
"filename": "src/constructs/aurora-database-create-schema.ts",
|
|
8778
|
+
"line": 33
|
|
8779
|
+
},
|
|
8780
|
+
"name": "schemaName",
|
|
8781
|
+
"type": {
|
|
8782
|
+
"primitive": "string"
|
|
8783
|
+
}
|
|
8784
|
+
}
|
|
8785
|
+
],
|
|
8786
|
+
"symbolId": "src/constructs/aurora-database-create-schema:AuroraDatabaseCreateSchemaProps"
|
|
8608
8787
|
}
|
|
8609
8788
|
},
|
|
8610
|
-
"version": "0.
|
|
8611
|
-
"fingerprint": "
|
|
8789
|
+
"version": "0.2.0",
|
|
8790
|
+
"fingerprint": "3yjtHtQWCe10e8TkYnKH1dKBrvRzEbQVy+rzYSrbOPQ="
|
|
8612
8791
|
}
|
package/API.md
CHANGED
|
@@ -149,6 +149,158 @@ The tree node.
|
|
|
149
149
|
---
|
|
150
150
|
|
|
151
151
|
|
|
152
|
+
### AuroraDatabaseCreateSchema <a name="AuroraDatabaseCreateSchema" id="rds-aurora-bootstrapper.AuroraDatabaseCreateSchema"></a>
|
|
153
|
+
|
|
154
|
+
CDK construct that provisions a PostgreSQL schema on an Aurora cluster using a custom resource backed by the RDS Data API.
|
|
155
|
+
|
|
156
|
+
On Create, the handler creates the schema (if missing), assigns ownership to
|
|
157
|
+
{@link AuroraDatabaseCreateSchemaProps.ownerUsername}, and optionally drops
|
|
158
|
+
the `public` schema. The master username is derived from the `username` field
|
|
159
|
+
of {@link AuroraDatabaseCreateSchemaProps.dbMasterUserCredentials} through a
|
|
160
|
+
Secrets Manager dynamic reference; callers do not pass it explicitly.
|
|
161
|
+
|
|
162
|
+
Ensure {@link AuroraDatabaseCreateSchemaProps.ownerUsername} already exists
|
|
163
|
+
(for example via {@link AuroraDatabaseCreateOwner }) before this resource runs.
|
|
164
|
+
|
|
165
|
+
#### Initializers <a name="Initializers" id="rds-aurora-bootstrapper.AuroraDatabaseCreateSchema.Initializer"></a>
|
|
166
|
+
|
|
167
|
+
```typescript
|
|
168
|
+
import { AuroraDatabaseCreateSchema } from 'rds-aurora-bootstrapper'
|
|
169
|
+
|
|
170
|
+
new AuroraDatabaseCreateSchema(scope: Construct, id: string, props: AuroraDatabaseCreateSchemaProps)
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
| **Name** | **Type** | **Description** |
|
|
174
|
+
| --- | --- | --- |
|
|
175
|
+
| <code><a href="#rds-aurora-bootstrapper.AuroraDatabaseCreateSchema.Initializer.parameter.scope">scope</a></code> | <code>constructs.Construct</code> | - Parent construct. |
|
|
176
|
+
| <code><a href="#rds-aurora-bootstrapper.AuroraDatabaseCreateSchema.Initializer.parameter.id">id</a></code> | <code>string</code> | - Construct identifier. |
|
|
177
|
+
| <code><a href="#rds-aurora-bootstrapper.AuroraDatabaseCreateSchema.Initializer.parameter.props">props</a></code> | <code><a href="#rds-aurora-bootstrapper.AuroraDatabaseCreateSchemaProps">AuroraDatabaseCreateSchemaProps</a></code> | - Configuration for the database schema. |
|
|
178
|
+
|
|
179
|
+
---
|
|
180
|
+
|
|
181
|
+
##### `scope`<sup>Required</sup> <a name="scope" id="rds-aurora-bootstrapper.AuroraDatabaseCreateSchema.Initializer.parameter.scope"></a>
|
|
182
|
+
|
|
183
|
+
- *Type:* constructs.Construct
|
|
184
|
+
|
|
185
|
+
Parent construct.
|
|
186
|
+
|
|
187
|
+
---
|
|
188
|
+
|
|
189
|
+
##### `id`<sup>Required</sup> <a name="id" id="rds-aurora-bootstrapper.AuroraDatabaseCreateSchema.Initializer.parameter.id"></a>
|
|
190
|
+
|
|
191
|
+
- *Type:* string
|
|
192
|
+
|
|
193
|
+
Construct identifier.
|
|
194
|
+
|
|
195
|
+
---
|
|
196
|
+
|
|
197
|
+
##### `props`<sup>Required</sup> <a name="props" id="rds-aurora-bootstrapper.AuroraDatabaseCreateSchema.Initializer.parameter.props"></a>
|
|
198
|
+
|
|
199
|
+
- *Type:* <a href="#rds-aurora-bootstrapper.AuroraDatabaseCreateSchemaProps">AuroraDatabaseCreateSchemaProps</a>
|
|
200
|
+
|
|
201
|
+
Configuration for the database schema.
|
|
202
|
+
|
|
203
|
+
---
|
|
204
|
+
|
|
205
|
+
#### Methods <a name="Methods" id="Methods"></a>
|
|
206
|
+
|
|
207
|
+
| **Name** | **Description** |
|
|
208
|
+
| --- | --- |
|
|
209
|
+
| <code><a href="#rds-aurora-bootstrapper.AuroraDatabaseCreateSchema.toString">toString</a></code> | Returns a string representation of this construct. |
|
|
210
|
+
| <code><a href="#rds-aurora-bootstrapper.AuroraDatabaseCreateSchema.with">with</a></code> | Applies one or more mixins to this construct. |
|
|
211
|
+
|
|
212
|
+
---
|
|
213
|
+
|
|
214
|
+
##### `toString` <a name="toString" id="rds-aurora-bootstrapper.AuroraDatabaseCreateSchema.toString"></a>
|
|
215
|
+
|
|
216
|
+
```typescript
|
|
217
|
+
public toString(): string
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
Returns a string representation of this construct.
|
|
221
|
+
|
|
222
|
+
##### `with` <a name="with" id="rds-aurora-bootstrapper.AuroraDatabaseCreateSchema.with"></a>
|
|
223
|
+
|
|
224
|
+
```typescript
|
|
225
|
+
public with(mixins: ...IMixin[]): IConstruct
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
Applies one or more mixins to this construct.
|
|
229
|
+
|
|
230
|
+
Mixins are applied in order. The list of constructs is captured at the
|
|
231
|
+
start of the call, so constructs added by a mixin will not be visited.
|
|
232
|
+
Use multiple `with()` calls if subsequent mixins should apply to added
|
|
233
|
+
constructs.
|
|
234
|
+
|
|
235
|
+
###### `mixins`<sup>Required</sup> <a name="mixins" id="rds-aurora-bootstrapper.AuroraDatabaseCreateSchema.with.parameter.mixins"></a>
|
|
236
|
+
|
|
237
|
+
- *Type:* ...constructs.IMixin[]
|
|
238
|
+
|
|
239
|
+
The mixins to apply.
|
|
240
|
+
|
|
241
|
+
---
|
|
242
|
+
|
|
243
|
+
#### Static Functions <a name="Static Functions" id="Static Functions"></a>
|
|
244
|
+
|
|
245
|
+
| **Name** | **Description** |
|
|
246
|
+
| --- | --- |
|
|
247
|
+
| <code><a href="#rds-aurora-bootstrapper.AuroraDatabaseCreateSchema.isConstruct">isConstruct</a></code> | Checks if `x` is a construct. |
|
|
248
|
+
|
|
249
|
+
---
|
|
250
|
+
|
|
251
|
+
##### `isConstruct` <a name="isConstruct" id="rds-aurora-bootstrapper.AuroraDatabaseCreateSchema.isConstruct"></a>
|
|
252
|
+
|
|
253
|
+
```typescript
|
|
254
|
+
import { AuroraDatabaseCreateSchema } from 'rds-aurora-bootstrapper'
|
|
255
|
+
|
|
256
|
+
AuroraDatabaseCreateSchema.isConstruct(x: any)
|
|
257
|
+
```
|
|
258
|
+
|
|
259
|
+
Checks if `x` is a construct.
|
|
260
|
+
|
|
261
|
+
Use this method instead of `instanceof` to properly detect `Construct`
|
|
262
|
+
instances, even when the construct library is symlinked.
|
|
263
|
+
|
|
264
|
+
Explanation: in JavaScript, multiple copies of the `constructs` library on
|
|
265
|
+
disk are seen as independent, completely different libraries. As a
|
|
266
|
+
consequence, the class `Construct` in each copy of the `constructs` library
|
|
267
|
+
is seen as a different class, and an instance of one class will not test as
|
|
268
|
+
`instanceof` the other class. `npm install` will not create installations
|
|
269
|
+
like this, but users may manually symlink construct libraries together or
|
|
270
|
+
use a monorepo tool: in those cases, multiple copies of the `constructs`
|
|
271
|
+
library can be accidentally installed, and `instanceof` will behave
|
|
272
|
+
unpredictably. It is safest to avoid using `instanceof`, and using
|
|
273
|
+
this type-testing method instead.
|
|
274
|
+
|
|
275
|
+
###### `x`<sup>Required</sup> <a name="x" id="rds-aurora-bootstrapper.AuroraDatabaseCreateSchema.isConstruct.parameter.x"></a>
|
|
276
|
+
|
|
277
|
+
- *Type:* any
|
|
278
|
+
|
|
279
|
+
Any object.
|
|
280
|
+
|
|
281
|
+
---
|
|
282
|
+
|
|
283
|
+
#### Properties <a name="Properties" id="Properties"></a>
|
|
284
|
+
|
|
285
|
+
| **Name** | **Type** | **Description** |
|
|
286
|
+
| --- | --- | --- |
|
|
287
|
+
| <code><a href="#rds-aurora-bootstrapper.AuroraDatabaseCreateSchema.property.node">node</a></code> | <code>constructs.Node</code> | The tree node. |
|
|
288
|
+
|
|
289
|
+
---
|
|
290
|
+
|
|
291
|
+
##### `node`<sup>Required</sup> <a name="node" id="rds-aurora-bootstrapper.AuroraDatabaseCreateSchema.property.node"></a>
|
|
292
|
+
|
|
293
|
+
```typescript
|
|
294
|
+
public readonly node: Node;
|
|
295
|
+
```
|
|
296
|
+
|
|
297
|
+
- *Type:* constructs.Node
|
|
298
|
+
|
|
299
|
+
The tree node.
|
|
300
|
+
|
|
301
|
+
---
|
|
302
|
+
|
|
303
|
+
|
|
152
304
|
## Structs <a name="Structs" id="Structs"></a>
|
|
153
305
|
|
|
154
306
|
### AuroraDatabaseCreateOwnerProps <a name="AuroraDatabaseCreateOwnerProps" id="rds-aurora-bootstrapper.AuroraDatabaseCreateOwnerProps"></a>
|
|
@@ -222,6 +374,111 @@ public readonly ownerUsername: string;
|
|
|
222
374
|
|
|
223
375
|
Username of the owner role to create (`NOLOGIN`, `NOINHERIT`).
|
|
224
376
|
|
|
377
|
+
Must match {@link SAFE_POSTGRESQL_IDENTIFIER_PATTERN }.
|
|
378
|
+
|
|
379
|
+
---
|
|
380
|
+
|
|
381
|
+
### AuroraDatabaseCreateSchemaProps <a name="AuroraDatabaseCreateSchemaProps" id="rds-aurora-bootstrapper.AuroraDatabaseCreateSchemaProps"></a>
|
|
382
|
+
|
|
383
|
+
Properties for {@link AuroraDatabaseCreateSchema}.
|
|
384
|
+
|
|
385
|
+
#### Initializer <a name="Initializer" id="rds-aurora-bootstrapper.AuroraDatabaseCreateSchemaProps.Initializer"></a>
|
|
386
|
+
|
|
387
|
+
```typescript
|
|
388
|
+
import { AuroraDatabaseCreateSchemaProps } from 'rds-aurora-bootstrapper'
|
|
389
|
+
|
|
390
|
+
const auroraDatabaseCreateSchemaProps: AuroraDatabaseCreateSchemaProps = { ... }
|
|
391
|
+
```
|
|
392
|
+
|
|
393
|
+
#### Properties <a name="Properties" id="Properties"></a>
|
|
394
|
+
|
|
395
|
+
| **Name** | **Type** | **Description** |
|
|
396
|
+
| --- | --- | --- |
|
|
397
|
+
| <code><a href="#rds-aurora-bootstrapper.AuroraDatabaseCreateSchemaProps.property.dbCluster">dbCluster</a></code> | <code>aws-cdk-lib.aws_rds.DatabaseCluster</code> | Aurora database cluster where the schema is created. |
|
|
398
|
+
| <code><a href="#rds-aurora-bootstrapper.AuroraDatabaseCreateSchemaProps.property.dbMasterUserCredentials">dbMasterUserCredentials</a></code> | <code>aws-cdk-lib.aws_secretsmanager.Secret</code> | Secrets Manager secret holding the Aurora master user credentials. |
|
|
399
|
+
| <code><a href="#rds-aurora-bootstrapper.AuroraDatabaseCreateSchemaProps.property.dbName">dbName</a></code> | <code>string</code> | Name of the PostgreSQL database targeted by the custom resource. |
|
|
400
|
+
| <code><a href="#rds-aurora-bootstrapper.AuroraDatabaseCreateSchemaProps.property.isDropPublicSchema">isDropPublicSchema</a></code> | <code>boolean</code> | When `true`, drops the `public` schema with `CASCADE` after creating the target schema. |
|
|
401
|
+
| <code><a href="#rds-aurora-bootstrapper.AuroraDatabaseCreateSchemaProps.property.ownerUsername">ownerUsername</a></code> | <code>string</code> | Username of the existing owner role that will own the new schema. |
|
|
402
|
+
| <code><a href="#rds-aurora-bootstrapper.AuroraDatabaseCreateSchemaProps.property.schemaName">schemaName</a></code> | <code>string</code> | Name of the PostgreSQL schema to create. |
|
|
403
|
+
|
|
404
|
+
---
|
|
405
|
+
|
|
406
|
+
##### `dbCluster`<sup>Required</sup> <a name="dbCluster" id="rds-aurora-bootstrapper.AuroraDatabaseCreateSchemaProps.property.dbCluster"></a>
|
|
407
|
+
|
|
408
|
+
```typescript
|
|
409
|
+
public readonly dbCluster: DatabaseCluster;
|
|
410
|
+
```
|
|
411
|
+
|
|
412
|
+
- *Type:* aws-cdk-lib.aws_rds.DatabaseCluster
|
|
413
|
+
|
|
414
|
+
Aurora database cluster where the schema is created.
|
|
415
|
+
|
|
416
|
+
---
|
|
417
|
+
|
|
418
|
+
##### `dbMasterUserCredentials`<sup>Required</sup> <a name="dbMasterUserCredentials" id="rds-aurora-bootstrapper.AuroraDatabaseCreateSchemaProps.property.dbMasterUserCredentials"></a>
|
|
419
|
+
|
|
420
|
+
```typescript
|
|
421
|
+
public readonly dbMasterUserCredentials: Secret;
|
|
422
|
+
```
|
|
423
|
+
|
|
424
|
+
- *Type:* aws-cdk-lib.aws_secretsmanager.Secret
|
|
425
|
+
|
|
426
|
+
Secrets Manager secret holding the Aurora master user credentials.
|
|
427
|
+
|
|
428
|
+
The `username` field is passed to the custom resource via a dynamic reference.
|
|
429
|
+
|
|
430
|
+
---
|
|
431
|
+
|
|
432
|
+
##### `dbName`<sup>Required</sup> <a name="dbName" id="rds-aurora-bootstrapper.AuroraDatabaseCreateSchemaProps.property.dbName"></a>
|
|
433
|
+
|
|
434
|
+
```typescript
|
|
435
|
+
public readonly dbName: string;
|
|
436
|
+
```
|
|
437
|
+
|
|
438
|
+
- *Type:* string
|
|
439
|
+
|
|
440
|
+
Name of the PostgreSQL database targeted by the custom resource.
|
|
441
|
+
|
|
442
|
+
---
|
|
443
|
+
|
|
444
|
+
##### `isDropPublicSchema`<sup>Required</sup> <a name="isDropPublicSchema" id="rds-aurora-bootstrapper.AuroraDatabaseCreateSchemaProps.property.isDropPublicSchema"></a>
|
|
445
|
+
|
|
446
|
+
```typescript
|
|
447
|
+
public readonly isDropPublicSchema: boolean;
|
|
448
|
+
```
|
|
449
|
+
|
|
450
|
+
- *Type:* boolean
|
|
451
|
+
|
|
452
|
+
When `true`, drops the `public` schema with `CASCADE` after creating the target schema.
|
|
453
|
+
|
|
454
|
+
---
|
|
455
|
+
|
|
456
|
+
##### `ownerUsername`<sup>Required</sup> <a name="ownerUsername" id="rds-aurora-bootstrapper.AuroraDatabaseCreateSchemaProps.property.ownerUsername"></a>
|
|
457
|
+
|
|
458
|
+
```typescript
|
|
459
|
+
public readonly ownerUsername: string;
|
|
460
|
+
```
|
|
461
|
+
|
|
462
|
+
- *Type:* string
|
|
463
|
+
|
|
464
|
+
Username of the existing owner role that will own the new schema.
|
|
465
|
+
|
|
466
|
+
Must match {@link SAFE_POSTGRESQL_IDENTIFIER_PATTERN }.
|
|
467
|
+
|
|
468
|
+
---
|
|
469
|
+
|
|
470
|
+
##### `schemaName`<sup>Required</sup> <a name="schemaName" id="rds-aurora-bootstrapper.AuroraDatabaseCreateSchemaProps.property.schemaName"></a>
|
|
471
|
+
|
|
472
|
+
```typescript
|
|
473
|
+
public readonly schemaName: string;
|
|
474
|
+
```
|
|
475
|
+
|
|
476
|
+
- *Type:* string
|
|
477
|
+
|
|
478
|
+
Name of the PostgreSQL schema to create.
|
|
479
|
+
|
|
480
|
+
Must match {@link SAFE_POSTGRESQL_IDENTIFIER_PATTERN }.
|
|
481
|
+
|
|
225
482
|
---
|
|
226
483
|
|
|
227
484
|
|
package/README.md
CHANGED
|
@@ -9,10 +9,12 @@ AWS CDK constructs for bootstrapping Aurora PostgreSQL databases.
|
|
|
9
9
|
## Features
|
|
10
10
|
|
|
11
11
|
- **`AuroraDatabaseCreateOwner`** — provisions a PostgreSQL owner role on an Aurora cluster via the RDS Data API
|
|
12
|
-
-
|
|
13
|
-
-
|
|
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
|
|
15
|
+
- Validates PostgreSQL identifiers at synthesis time (`ownerUsername`, `schemaName`)
|
|
14
16
|
- Master username is resolved from the credentials secret through a CloudFormation dynamic reference
|
|
15
|
-
- Bundled Lambda custom
|
|
17
|
+
- Bundled Lambda custom resources with IAM permissions and Secrets Manager read access configured automatically
|
|
16
18
|
|
|
17
19
|
## Installation
|
|
18
20
|
|
|
@@ -26,6 +28,8 @@ yarn add rds-aurora-bootstrapper aws-cdk-lib constructs
|
|
|
26
28
|
|
|
27
29
|
## Usage
|
|
28
30
|
|
|
31
|
+
Create the owner role first, then create the application schema:
|
|
32
|
+
|
|
29
33
|
```typescript
|
|
30
34
|
import { Stack } from 'aws-cdk-lib';
|
|
31
35
|
import { Vpc } from 'aws-cdk-lib/aws-ec2';
|
|
@@ -37,7 +41,10 @@ import {
|
|
|
37
41
|
} from 'aws-cdk-lib/aws-rds';
|
|
38
42
|
import { Secret } from 'aws-cdk-lib/aws-secretsmanager';
|
|
39
43
|
import { Construct } from 'constructs';
|
|
40
|
-
import {
|
|
44
|
+
import {
|
|
45
|
+
AuroraDatabaseCreateOwner,
|
|
46
|
+
AuroraDatabaseCreateSchema,
|
|
47
|
+
} from 'rds-aurora-bootstrapper';
|
|
41
48
|
|
|
42
49
|
export class MyStack extends Stack {
|
|
43
50
|
constructor(scope: Construct, id: string) {
|
|
@@ -53,12 +60,22 @@ export class MyStack extends Stack {
|
|
|
53
60
|
});
|
|
54
61
|
const masterUserSecret = new Secret(this, 'MasterUserSecret');
|
|
55
62
|
|
|
56
|
-
new AuroraDatabaseCreateOwner(this, 'CreateOwner', {
|
|
63
|
+
const createOwner = new AuroraDatabaseCreateOwner(this, 'CreateOwner', {
|
|
64
|
+
dbMasterUserCredentials: masterUserSecret,
|
|
65
|
+
dbCluster: cluster,
|
|
66
|
+
dbName: 'appdb',
|
|
67
|
+
ownerUsername: 'app_owner',
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
const createSchema = new AuroraDatabaseCreateSchema(this, 'CreateSchema', {
|
|
57
71
|
dbMasterUserCredentials: masterUserSecret,
|
|
58
72
|
dbCluster: cluster,
|
|
59
73
|
dbName: 'appdb',
|
|
60
74
|
ownerUsername: 'app_owner',
|
|
75
|
+
schemaName: 'app_schema',
|
|
76
|
+
isDropPublicSchema: true,
|
|
61
77
|
});
|
|
78
|
+
createSchema.node.addDependency(createOwner);
|
|
62
79
|
}
|
|
63
80
|
}
|
|
64
81
|
```
|
|
@@ -72,7 +89,18 @@ export class MyStack extends Stack {
|
|
|
72
89
|
| `dbMasterUserCredentials` | `Secret` | Secrets Manager secret with Aurora master credentials. The `username` field is passed to the custom resource via a dynamic reference. |
|
|
73
90
|
| `dbCluster` | `DatabaseCluster` | Aurora database cluster where the owner role is created. |
|
|
74
91
|
| `dbName` | `string` | PostgreSQL database name targeted by the custom resource. |
|
|
75
|
-
| `ownerUsername` | `string` | Username of the owner role to create (`NOLOGIN`, `NOINHERIT`). |
|
|
92
|
+
| `ownerUsername` | `string` | Username of the owner role to create (`NOLOGIN`, `NOINHERIT`). Must match `^[a-zA-Z_][a-zA-Z0-9_-]*$`. |
|
|
93
|
+
|
|
94
|
+
### `AuroraDatabaseCreateSchemaProps`
|
|
95
|
+
|
|
96
|
+
| Property | Type | Description |
|
|
97
|
+
| --- | --- | --- |
|
|
98
|
+
| `dbMasterUserCredentials` | `Secret` | Secrets Manager secret with Aurora master credentials. The `username` field is passed to the custom resource via a dynamic reference. |
|
|
99
|
+
| `dbCluster` | `DatabaseCluster` | Aurora database cluster where the schema is created. |
|
|
100
|
+
| `dbName` | `string` | PostgreSQL database name targeted by the custom resource. |
|
|
101
|
+
| `ownerUsername` | `string` | Username of the existing owner role that will own the new schema. Must match `^[a-zA-Z_][a-zA-Z0-9_-]*$`. |
|
|
102
|
+
| `schemaName` | `string` | Name of the PostgreSQL schema to create. Must match `^[a-zA-Z_][a-zA-Z0-9_-]*$`. |
|
|
103
|
+
| `isDropPublicSchema` | `boolean` | When `true`, drops the `public` schema with `CASCADE` after creating the target schema. |
|
|
76
104
|
|
|
77
105
|
## Requirements
|
|
78
106
|
|