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,
},
});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. |
- Type: constructs.Construct
The scope in which to create this Construct.
Normally this is a stack.
- Type: string
The Construct ID of the backup repository.
The properties for the backup repository, as defined in the AuroraBackupRepositoryProps interface.
| 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. |
public toString(): stringReturns a string representation of this construct.
public grantPull(grantee: IPrincipal): GrantGrants permissions to pull images from the ECR repository.
- Type: aws-cdk-lib.aws_iam.IPrincipal
The IAM principal to grant pull permissions to.
public grantPullPush(grantee: IPrincipal): GrantGrants full permissions to the ECR repository.
- Type: aws-cdk-lib.aws_iam.IPrincipal
The IAM principal to grant full permissions to.
public grantPush(grantee: IPrincipal): GrantGrants permissions to push images to the ECR repository.
- Type: aws-cdk-lib.aws_iam.IPrincipal
The IAM principal to grant push permissions to.
| Name | Description |
|---|---|
isConstruct |
Checks if x is a construct. |
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.
- Type: any
Any object.
| 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. |
public readonly node: Node;- Type: constructs.Node
The tree node.
public readonly imageAsset: DockerImageAsset;- Type: aws-cdk-lib.aws_ecr_assets.DockerImageAsset
The Docker image asset containing the built backup image.
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
public readonly repository: IRepository;- Type: aws-cdk-lib.aws_ecr.IRepository
The ECR repository containing the backup Docker image.
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,
},
});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. |
- Type: constructs.Construct
The scope in which to create this Construct.
Normally this is a stack.
- Type: string
The Construct ID of the backup service.
The properties for the backup service, as defined in the AuroraNativeBackupServiceProps interface.
| Name | Description |
|---|---|
toString |
Returns a string representation of this construct. |
public toString(): stringReturns a string representation of this construct.
| Name | Description |
|---|---|
isConstruct |
Checks if x is a construct. |
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.
- Type: any
Any object.
| 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. |
public readonly node: Node;- Type: constructs.Node
The tree node.
public readonly accessPoint: IAccessPoint;- Type: aws-cdk-lib.aws_efs.IAccessPoint
The EFS access point for backup storage.
public readonly backupBucket: Bucket;- Type: aws-cdk-lib.aws_s3.Bucket
The S3 bucket for backup storage.
public readonly backupSecurityGroup: SecurityGroup;- Type: aws-cdk-lib.aws_ec2.SecurityGroup
The security group for the backup service.
public readonly ecsCluster: Cluster;- Type: aws-cdk-lib.aws_ecs.Cluster
The ECS cluster running the backup service.
public readonly executionRole: Role;- Type: aws-cdk-lib.aws_iam.Role
The IAM execution role for ECS tasks.
public readonly fileSystem: IFileSystem;- Type: aws-cdk-lib.aws_efs.IFileSystem
The EFS file system for backup storage.
public readonly schedule: Schedule;- Type: aws-cdk-lib.aws_scheduler.Schedule
The EventBridge schedule that triggers the backup task.
public readonly schedulerRole: Role;- Type: aws-cdk-lib.aws_iam.Role
The IAM role for the EventBridge Scheduler.
public readonly taskDefinition: FargateTaskDefinition;- Type: aws-cdk-lib.aws_ecs.FargateTaskDefinition
The ECS task definition for the backup container.
public readonly taskRole: Role;- Type: aws-cdk-lib.aws_iam.Role
The IAM role for backup tasks.
Database connection configuration for the Aurora backup service.
import { AuroraBackupConnectionProps } from '@renovosolutions/cdk-library-aurora-native-backup'
const auroraBackupConnectionProps: AuroraBackupConnectionProps = { ... }| 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. |
public readonly passwordSecret: ISecret;- Type: aws-cdk-lib.aws_secretsmanager.ISecret
Secrets Manager secret containing the database password.
Required for database authentication.
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'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.
Configuration properties for the Aurora backup Docker image.
import { AuroraBackupRepositoryProps } from '@renovosolutions/cdk-library-aurora-native-backup'
const auroraBackupRepositoryProps: AuroraBackupRepositoryProps = { ... }| Name | Type | Description |
|---|---|---|
repositoryName |
string |
The name of the ECR repository to create. |
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.
Infrastructure configuration properties for Aurora PostgreSQL native backup service.
import { AuroraNativeBackupServiceProps } from '@renovosolutions/cdk-library-aurora-native-backup'
const auroraNativeBackupServiceProps: AuroraNativeBackupServiceProps = { ... }| 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. |
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.
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.
public readonly connection: AuroraBackupConnectionProps;Database connection configuration.
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.
public readonly vpc: IVpc;- Type: aws-cdk-lib.aws_ec2.IVpc
The VPC where the backup service will run.
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' })public readonly cpu: number;- Type: number
- Default: 256
Fargate task CPU units.
public readonly memoryLimitMiB: number;- Type: number
- Default: 512
Fargate task memory in MB.
public readonly retentionDays: number;- Type: number
- Default: 7
Backup retention period in days.
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.
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.