Rds - SoftupTechnologies/infrastructure-components GitHub Wiki
Path: /lib/rds/index.ts
Exports: RdsInfrastructure
Required construct packages: @aws-cdk/aws-ec2
, @aws-cdk/aws-rds
This construct creates a RDS database instance with your desired database engine that AWS supports. The instance by default will accept connections only from the ip ranges of the vpc. To allow extra ingress trafic in your database you need to pass an array of Security groups.
You can configure the database placement in the vpc by setting one of these two props: publicAccessible
or dbSubnets
. The first one will add the RDS instance in the public subnet of your vpc.
Usage
import * as cdk from '@aws-cdk/core';
import { RdsInfrastructure } from './rds';
export class ServerlessInfrastructureCdkStack extends cdk.Stack {
constructor(scope: cdk.App, id: string, props: StackProps) {
super(scope, id);
const { vpc } = new MyVpc(this, 'MyAwesomeVpc', {
vpcCidr: '10.0.0.0/16',
publicSubnetsNo: 2,
maxAzs: 2,
privateSubnetsNo: 1,
});
// props include the projectName, clientName and env
const db = new RdsInfrastructure(this, 'MyCoolDbService', {
...props,
dbMasterUserName: 'coolUsername',
vpc,
databaseName: 'coolDatabase',
publicAccessible: true,
dbAllocatedStorage: 10,
dbBackupRetention: 30,
});
}
}
This will create a database instance with Postgres engine and place it in our public subnets group. Since we dont define a password for our database, it will automatically generate one and store it in Secrets Manager service in AWS.
Construct props
Name | Type | Required | Default | Description |
---|---|---|---|---|
projectName | string | true | undefined | The project name, which is used to compose different names and defining keys. |
env | Envs { dev, stage, prod } | true | undefined | The environment, which is used to set different properties and compose different names and keys. |
clientName | string | true | undefined | The client name, which is used to compose different names and defining keys. |
dbMasterUserName | string | true | undefined | Database username. |
dbMasterUserPassword | string | false | undefined | Database password. If not set it will be generated automatically and will be stored in Secrets Manager |
vpc | ec2.Vpc | true | undefined | The Vpc in which the database will be set. |
databaseName | string | true | undefined | Name of the database that will be created. |
ingressSgs | ec2.SecurityGroup[] | false | undefined | Extra security groups for the database to accept connections beside the vpc ip range. |
dbPort | number | false | 5432 | Database port. |
dbEngine | rds.IInstanceEngine | false | POSTGRES | Database engine. |
dbSubnets | ec2.ISubnet[] | false | undefined | Subnets to place the database (sets vpcPlacement property for rds). |
publicAccessible | boolean | false | undefined | Places the database in public subnets group (sets vpcPlacement property for rds). |
dbInstanceType | ec2.InstanceType | false | T2 MICRO | Database server instance type. |
dbAllocatedStorage | number | false | Envs.PROD => 20, Envs.DEV => 5 | Disk storage. |
dbBackupRetention | number | false | 10 | Number of days for RDS service to store the database snapshots. |
multiAz | boolean | false | false | Specifies if the RDS will be highly available or not. |
Properties
Name | Type | Description |
---|---|---|
dbInstance | rds.DatabaseInstance | Created database instance. |