cdk-aurora-globaldatabase

2.4.18 · active · verified Thu Apr 16

cdk-aurora-globaldatabase is an AWS CDK construct library, currently at version 2.4.18, that simplifies the creation of cross-region AWS Aurora Global Databases. It provides high-level constructs to deploy Aurora clusters across different regions, manage replication, and handle failover scenarios, following the AWS CDK v2 best practices. The library's release cadence generally aligns with updates to the AWS CDK and underlying AWS Aurora features.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart deploys an AWS Aurora Global Database with a MySQL-compatible engine across two AWS regions. It provisions a new VPC for the database. Before running, ensure your AWS account is bootstrapped for CDK in 'us-east-1' and 'us-east-2', and your `CDK_DEFAULT_ACCOUNT` and `CDK_DEFAULT_REGION` environment variables are set, or replace the placeholder values. The `synth` command generates the CloudFormation templates.

import os
from aws_cdk import App, Stack, Environment
from aws_cdk import aws_ec2 as ec2
from aws_cdk import aws_rds as rds
from cdk_aurora_globaldatabase import AuroraGlobalDatabase

class GlobalDatabaseStack(Stack):
    def __init__(self, scope: App, id: str, **kwargs) -> None:
        super().__init__(scope, id, **kwargs)

        # For a quickstart, we create a new VPC. In a production environment,
        # you would typically look up an existing VPC: 
        # vpc = ec2.Vpc.from_lookup(self, "MyExistingVpc", vpc_name="YourVpcName")
        vpc = ec2.Vpc(
            self, "AuroraGlobalDbVpc",
            max_azs=2,  # Deploy resources across 2 availability zones
            cidr="10.0.0.0/16",
            enable_dns_hostnames=True,
            enable_dns_support=True
        )

        AuroraGlobalDatabase(
            self, "MyAuroraGlobalDatabase",
            primary_region="us-east-1",
            secondary_regions=["us-east-2"], # Add more regions as needed
            aurora_version=rds.AuroraMysqlEngineVersion.VER_3_06_0, # Example MySQL version
            vpc=vpc,
            # Optional: specify instance type, credentials, storage encryption, etc.
            # instance_type=ec2.InstanceType.of(ec2.InstanceClass.R6G, ec2.InstanceSize.LARGE),
            # credentials=rds.Credentials.from_generated_secret("auroraglobaladmin"),
            # encryption_key=kms.Key(self, "AuroraKey")
        )

app = App()
# Define an environment for the primary stack
primary_env = Environment(
    account=os.environ.get('CDK_DEFAULT_ACCOUNT', '123456789012'),
    region=os.environ.get('CDK_DEFAULT_REGION', 'us-east-1')
)
GlobalDatabaseStack(app, "AuroraGlobalDbStack", env=primary_env)
app.synth()

view raw JSON →