mecanizou-cdk-pgsql
TypeScript icon, indicating that this package has built-in type declarations

2.1.0 • Public • Published

cdk-pgsql

AWS CDK constructs for Postgresql

Installation

npm install mecanizou-cdk-pgsql or yarn add mecanizou-cdk-pgsql

Usage

Provider

A Provider instance is required in order to establish a connection to your Postgresql instance

const theMasterSecret: secretsmanager.ISecret;

// you can connect to to a publicly available instance
const provider = new Provider(this, "Provider", {
  host: "your.db.host.net",
  username: "master",
  password: theMasterSecret,
  port: 5432,
  vpc,
  securityGroups: [dbClusterSecurityGroup],
});

// or a private instance in your VPC
const provider = new Provider(this, "Provider", {
  host: "your.db.host.net",
  username: "master",
  password: theMasterSecret,
  port: 5432,
  vpc,
  securityGroups: [yourDatabaseSecurityGroup],
});

You can reuse the same Provider instance when creating your different Role and Database instances.

Database

import { Database } from "mecanizou-cdk-pgsql";

const db = new Database(this, "Database", {
  provider,
  name: "mynewdb",
  owner: "somerole",
  removalPolicy: cdk.RemovalPolicy.RETAIN, // default is RETAIN
});

Role

import { Role } from "mecanizou-cdk-pgsql";

const rolePassword: secretsmanager.ISecret;
const role = new Role(this, "Role", {
  provider,
  name: "newrole",
  password: rolePassword,
  removalPolicy: cdk.RemovalPolicy.RETAIN, // Default is DESTROY
});

Tips

Creating a Role before a Database

In many cases, you want to create a Role and use that role as the Database owner. You can achieve this by adding an explicit dependency between the two instances:

const roleName = "newRole";
const role = new Role(this, "Role", {
  provider,
  name: roleName,
  password: rolePassword,
});
const db = new Database(this, "Database", {
  provider,
  name: "mydb",
  owner: roleName,
});

db.node.addDependency(role);

Readme

Keywords

none

Package Sidebar

Install

npm i mecanizou-cdk-pgsql

Weekly Downloads

2

Version

2.1.0

License

ISC

Unpacked Size

111 kB

Total Files

26

Last publish

Collaborators

  • giogiannichi