Skip to content

Latest commit

 

History

History
825 lines (511 loc) · 32.6 KB

File metadata and controls

825 lines (511 loc) · 32.6 KB

API Reference

Constructs

AuroraBackupRepository

A construct that creates and manages a Docker image for Aurora PostgreSQL native backups.

Creates an ECR repository and builds a Docker image containing PostgreSQL 17 client tools, AWS CLI v2, and backup scripts. The image is designed for use with the AuroraNativeBackupService construct in this same library.

Example

const backupRepository = new AuroraBackupRepository(this, 'BackupRepository', {
  repositoryName: 'aurora-postgres-backup',
});

const backupService = new AuroraNativeBackupService(this, 'BackupService', {
  cluster: myAuroraCluster,
  vpc: vpc,
  backupBucketName: 'my-aurora-backups',
  ecrRepository: backupRepository.repository,
  connection: {
    username: 'backup_user',
    databaseNames: ['production'],
    passwordSecret: backupUserSecret,
  },
});

Initializers

import { AuroraBackupRepository } from '@renovosolutions/cdk-library-aurora-native-backup'

new AuroraBackupRepository(scope: Construct, id: string, props: AuroraBackupRepositoryProps)
Name Type Description
scope constructs.Construct The scope in which to create this Construct.
id string The Construct ID of the backup repository.
props AuroraBackupRepositoryProps The properties for the backup repository, as defined in the AuroraBackupRepositoryProps interface.

scopeRequired
  • Type: constructs.Construct

The scope in which to create this Construct.

Normally this is a stack.


idRequired
  • Type: string

The Construct ID of the backup repository.


propsRequired

The properties for the backup repository, as defined in the AuroraBackupRepositoryProps interface.


Methods

Name Description
toString Returns a string representation of this construct.
grantPull Grants permissions to pull images from the ECR repository.
grantPullPush Grants full permissions to the ECR repository.
grantPush Grants permissions to push images to the ECR repository.

toString
public toString(): string

Returns a string representation of this construct.

grantPull
public grantPull(grantee: IPrincipal): Grant

Grants permissions to pull images from the ECR repository.

granteeRequired
  • Type: aws-cdk-lib.aws_iam.IPrincipal

The IAM principal to grant pull permissions to.


grantPullPush
public grantPullPush(grantee: IPrincipal): Grant

Grants full permissions to the ECR repository.

granteeRequired
  • Type: aws-cdk-lib.aws_iam.IPrincipal

The IAM principal to grant full permissions to.


grantPush
public grantPush(grantee: IPrincipal): Grant

Grants permissions to push images to the ECR repository.

granteeRequired
  • Type: aws-cdk-lib.aws_iam.IPrincipal

The IAM principal to grant push permissions to.


Static Functions

Name Description
isConstruct Checks if x is a construct.

isConstruct
import { AuroraBackupRepository } from '@renovosolutions/cdk-library-aurora-native-backup'

AuroraBackupRepository.isConstruct(x: any)

Checks if x is a construct.

Use this method instead of instanceof to properly detect Construct instances, even when the construct library is symlinked.

Explanation: in JavaScript, multiple copies of the constructs library on disk are seen as independent, completely different libraries. As a consequence, the class Construct in each copy of the constructs library is seen as a different class, and an instance of one class will not test as instanceof the other class. npm install will not create installations like this, but users may manually symlink construct libraries together or use a monorepo tool: in those cases, multiple copies of the constructs library can be accidentally installed, and instanceof will behave unpredictably. It is safest to avoid using instanceof, and using this type-testing method instead.

xRequired
  • Type: any

Any object.


Properties

Name Type Description
node constructs.Node The tree node.
imageAsset aws-cdk-lib.aws_ecr_assets.DockerImageAsset The Docker image asset containing the built backup image.
imageUri string The complete URI of the Docker image for ECS task definitions.
repository aws-cdk-lib.aws_ecr.IRepository The ECR repository containing the backup Docker image.

nodeRequired
public readonly node: Node;
  • Type: constructs.Node

The tree node.


imageAssetRequired
public readonly imageAsset: DockerImageAsset;
  • Type: aws-cdk-lib.aws_ecr_assets.DockerImageAsset

The Docker image asset containing the built backup image.


imageUriRequired
public readonly imageUri: string;
  • Type: string

The complete URI of the Docker image for ECS task definitions.

Format: <account-id>.dkr.ecr.<region>.amazonaws.com/<repository-name>:latest


repositoryRequired
public readonly repository: IRepository;
  • Type: aws-cdk-lib.aws_ecr.IRepository

The ECR repository containing the backup Docker image.


AuroraNativeBackupService

A construct for Aurora PostgreSQL native backup service.

Creates a scheduled ECS Fargate service that performs PostgreSQL backups using pg_dump. Backups are written to EFS and then copied to S3. They are removed from EFS after the configured retentionDays. The S3 bucket for backups can be provided or will be created automatically.

Example

const backupService = new AuroraNativeBackupService(this, 'BackupService', {
  cluster: dbCluster,
  vpc: vpc,
  backupBucketName: 'my-aurora-backups',
  ecrRepository: backupRepository.repository,
  connection: {
    username: 'backup_user',
    databaseNames: ['production', 'analytics', 'reporting'],
    passwordSecret: backupUserSecret,
  },
});

Initializers

import { AuroraNativeBackupService } from '@renovosolutions/cdk-library-aurora-native-backup'

new AuroraNativeBackupService(scope: Construct, id: string, props: AuroraNativeBackupServiceProps)
Name Type Description
scope constructs.Construct The scope in which to create this Construct.
id string The Construct ID of the backup service.
props AuroraNativeBackupServiceProps The properties for the backup service, as defined in the AuroraNativeBackupServiceProps interface.

scopeRequired
  • Type: constructs.Construct

The scope in which to create this Construct.

Normally this is a stack.


idRequired
  • Type: string

The Construct ID of the backup service.


propsRequired

The properties for the backup service, as defined in the AuroraNativeBackupServiceProps interface.


Methods

Name Description
toString Returns a string representation of this construct.

toString
public toString(): string

Returns a string representation of this construct.

Static Functions

Name Description
isConstruct Checks if x is a construct.

isConstruct
import { AuroraNativeBackupService } from '@renovosolutions/cdk-library-aurora-native-backup'

AuroraNativeBackupService.isConstruct(x: any)

Checks if x is a construct.

Use this method instead of instanceof to properly detect Construct instances, even when the construct library is symlinked.

Explanation: in JavaScript, multiple copies of the constructs library on disk are seen as independent, completely different libraries. As a consequence, the class Construct in each copy of the constructs library is seen as a different class, and an instance of one class will not test as instanceof the other class. npm install will not create installations like this, but users may manually symlink construct libraries together or use a monorepo tool: in those cases, multiple copies of the constructs library can be accidentally installed, and instanceof will behave unpredictably. It is safest to avoid using instanceof, and using this type-testing method instead.

xRequired
  • Type: any

Any object.


Properties

Name Type Description
node constructs.Node The tree node.
accessPoint aws-cdk-lib.aws_efs.IAccessPoint The EFS access point for backup storage.
backupBucket aws-cdk-lib.aws_s3.Bucket The S3 bucket for backup storage.
backupSecurityGroup aws-cdk-lib.aws_ec2.SecurityGroup The security group for the backup service.
ecsCluster aws-cdk-lib.aws_ecs.Cluster The ECS cluster running the backup service.
executionRole aws-cdk-lib.aws_iam.Role The IAM execution role for ECS tasks.
fileSystem aws-cdk-lib.aws_efs.IFileSystem The EFS file system for backup storage.
schedule aws-cdk-lib.aws_scheduler.Schedule The EventBridge schedule that triggers the backup task.
schedulerRole aws-cdk-lib.aws_iam.Role The IAM role for the EventBridge Scheduler.
taskDefinition aws-cdk-lib.aws_ecs.FargateTaskDefinition The ECS task definition for the backup container.
taskRole aws-cdk-lib.aws_iam.Role The IAM role for backup tasks.

nodeRequired
public readonly node: Node;
  • Type: constructs.Node

The tree node.


accessPointRequired
public readonly accessPoint: IAccessPoint;
  • Type: aws-cdk-lib.aws_efs.IAccessPoint

The EFS access point for backup storage.


backupBucketRequired
public readonly backupBucket: Bucket;
  • Type: aws-cdk-lib.aws_s3.Bucket

The S3 bucket for backup storage.


backupSecurityGroupRequired
public readonly backupSecurityGroup: SecurityGroup;
  • Type: aws-cdk-lib.aws_ec2.SecurityGroup

The security group for the backup service.


ecsClusterRequired
public readonly ecsCluster: Cluster;
  • Type: aws-cdk-lib.aws_ecs.Cluster

The ECS cluster running the backup service.


executionRoleRequired
public readonly executionRole: Role;
  • Type: aws-cdk-lib.aws_iam.Role

The IAM execution role for ECS tasks.


fileSystemRequired
public readonly fileSystem: IFileSystem;
  • Type: aws-cdk-lib.aws_efs.IFileSystem

The EFS file system for backup storage.


scheduleRequired
public readonly schedule: Schedule;
  • Type: aws-cdk-lib.aws_scheduler.Schedule

The EventBridge schedule that triggers the backup task.


schedulerRoleRequired
public readonly schedulerRole: Role;
  • Type: aws-cdk-lib.aws_iam.Role

The IAM role for the EventBridge Scheduler.


taskDefinitionRequired
public readonly taskDefinition: FargateTaskDefinition;
  • Type: aws-cdk-lib.aws_ecs.FargateTaskDefinition

The ECS task definition for the backup container.


taskRoleRequired
public readonly taskRole: Role;
  • Type: aws-cdk-lib.aws_iam.Role

The IAM role for backup tasks.


Structs

AuroraBackupConnectionProps

Database connection configuration for the Aurora backup service.

Initializer

import { AuroraBackupConnectionProps } from '@renovosolutions/cdk-library-aurora-native-backup'

const auroraBackupConnectionProps: AuroraBackupConnectionProps = { ... }

Properties

Name Type Description
passwordSecret aws-cdk-lib.aws_secretsmanager.ISecret Secrets Manager secret containing the database password.
username string The database username for backup operations.
databaseNames string[] The database names to backup.

passwordSecretRequired
public readonly passwordSecret: ISecret;
  • Type: aws-cdk-lib.aws_secretsmanager.ISecret

Secrets Manager secret containing the database password.

Required for database authentication.


usernameRequired
public readonly username: string;
  • Type: string

The database username for backup operations.

Must exist in the Aurora PostgreSQL database cluster with read permissions on ALL databases to be backed up.

For PostgreSQL 14+ (recommended), use the pg_read_all_data role:

  • GRANT CONNECT ON DATABASE your_database TO backup_user;
  • GRANT pg_read_all_data TO backup_user;

The pg_read_all_data role automatically provides SELECT on all tables/views, USAGE on schemas/sequences, and access to future objects without additional grants.


Example

'backup_user'
databaseNamesOptional
public readonly databaseNames: string[];
  • Type: string[]
  • Default: ['postgres'] - Uses the cluster's default database

The database names to backup.

The backup user must have appropriate permissions on all databases in this array.


AuroraBackupRepositoryProps

Configuration properties for the Aurora backup Docker image.

Initializer

import { AuroraBackupRepositoryProps } from '@renovosolutions/cdk-library-aurora-native-backup'

const auroraBackupRepositoryProps: AuroraBackupRepositoryProps = { ... }

Properties

Name Type Description
repositoryName string The name of the ECR repository to create.

repositoryNameOptional
public readonly repositoryName: string;
  • Type: string
  • Default: CDK-generated name

The name of the ECR repository to create.

If not provided, CDK will generate a unique name based on the stack and construct ID.


AuroraNativeBackupServiceProps

Infrastructure configuration properties for Aurora PostgreSQL native backup service.

Initializer

import { AuroraNativeBackupServiceProps } from '@renovosolutions/cdk-library-aurora-native-backup'

const auroraNativeBackupServiceProps: AuroraNativeBackupServiceProps = { ... }

Properties

Name Type Description
backupBucketName string Name for the S3 backup bucket that will be created by the construct.
cluster aws-cdk-lib.aws_rds.IDatabaseCluster & aws-cdk-lib.aws_ec2.IConnectable The Aurora PostgreSQL database cluster to backup.
connection AuroraBackupConnectionProps Database connection configuration.
ecrRepository aws-cdk-lib.aws_ecr.IRepository ECR repository containing the backup Docker image.
vpc aws-cdk-lib.aws_ec2.IVpc The VPC where the backup service will run.
backupSchedule aws-cdk-lib.aws_scheduler.ScheduleExpression Backup schedule using EventBridge Scheduler ScheduleExpression.
cpu number Fargate task CPU units.
memoryLimitMiB number Fargate task memory in MB.
retentionDays number Backup retention period in days.
scheduleTimeWindow aws-cdk-lib.aws_scheduler.TimeWindow The time window during which the scheduled task is allowed to be invoked.
subnetSelection aws-cdk-lib.aws_ec2.SubnetSelection Subnet selection for the backup task.

backupBucketNameRequired
public readonly backupBucketName: string;
  • Type: string

Name for the S3 backup bucket that will be created by the construct.

The bucket will be configured with appropriate settings for backup storage.


clusterRequired
public readonly cluster: IDatabaseCluster & IConnectable;
  • Type: aws-cdk-lib.aws_rds.IDatabaseCluster & aws-cdk-lib.aws_ec2.IConnectable

The Aurora PostgreSQL database cluster to backup.

Must implement IConnectable for security group configuration.


connectionRequired
public readonly connection: AuroraBackupConnectionProps;

Database connection configuration.


ecrRepositoryRequired
public readonly ecrRepository: IRepository;
  • Type: aws-cdk-lib.aws_ecr.IRepository

ECR repository containing the backup Docker image.

The image will be pulled using the imageUri from the AuroraBackupRepository construct.


vpcRequired
public readonly vpc: IVpc;
  • Type: aws-cdk-lib.aws_ec2.IVpc

The VPC where the backup service will run.


backupScheduleOptional
public readonly backupSchedule: ScheduleExpression;
  • Type: aws-cdk-lib.aws_scheduler.ScheduleExpression
  • Default: scheduler.ScheduleExpression.cron({ minute: '0', hour: '5' }) - Daily at 5:00 AM UTC

Backup schedule using EventBridge Scheduler ScheduleExpression.

Use scheduler.ScheduleExpression.cron() or scheduler.ScheduleExpression.rate() to define the schedule.

https://docs.aws.amazon.com/eventbridge/latest/userguide/eb-cron-expressions.html


Example

// Weekly on Sundays at 2 AM UTC
backupSchedule: scheduler.ScheduleExpression.cron({ minute: '0', hour: '2', weekDay: 'SUN' })
cpuOptional
public readonly cpu: number;
  • Type: number
  • Default: 256

Fargate task CPU units.


memoryLimitMiBOptional
public readonly memoryLimitMiB: number;
  • Type: number
  • Default: 512

Fargate task memory in MB.


retentionDaysOptional
public readonly retentionDays: number;
  • Type: number
  • Default: 7

Backup retention period in days.


scheduleTimeWindowOptional
public readonly scheduleTimeWindow: TimeWindow;
  • Type: aws-cdk-lib.aws_scheduler.TimeWindow
  • Default: scheduler.TimeWindow.flexible(Duration.minutes(60))

The time window during which the scheduled task is allowed to be invoked.

This is passed to the EventBridge Scheduler Schedule as timeWindow.


subnetSelectionOptional
public readonly subnetSelection: SubnetSelection;
  • Type: aws-cdk-lib.aws_ec2.SubnetSelection
  • Default: { subnetType: ec2.SubnetType.PRIVATE_WITH_EGRESS } - Uses private subnets with egress

Subnet selection for the backup task.