1. Answers
  2. Set Up PostgreSQL on AWS with Debezium CDC

How do I set up PostgreSQL on AWS with Debezium CDC?

To set up PostgreSQL on AWS and configure Debezium for Change Data Capture (CDC), we need to create several resources and configurations.

  1. VPC and Subnets: We’ll start by setting up a VPC and the necessary subnets for our database.
  2. RDS Instance: Next, we’ll launch an Amazon RDS instance for PostgreSQL.
  3. Security Groups: Configure security groups to allow necessary traffic to the database.
  4. Debezium on EC2: Set up an EC2 instance to run Debezium for CDC.

Here is the complete setup for creating a PostgreSQL RDS instance and installing Debezium on an EC2 instance within AWS.

import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";

const dbVpc = new aws.ec2.Vpc("db_vpc", {cidrBlock: "10.0.0.0/16"});
const dbSubnet = new aws.ec2.Subnet("db_subnet", {
    vpcId: dbVpc.id,
    cidrBlock: "10.0.1.0/24",
});
const dbSg = new aws.ec2.SecurityGroup("db_sg", {
    name: "db_sg",
    vpcId: dbVpc.id,
    ingress: [{
        fromPort: 5432,
        toPort: 5432,
        protocol: "tcp",
        cidrBlocks: ["0.0.0.0/0"],
    }],
    egress: [{
        fromPort: 0,
        toPort: 0,
        protocol: "-1",
        cidrBlocks: ["0.0.0.0/0"],
    }],
});
const dbSubnetSubnetGroup = new aws.rds.SubnetGroup("db_subnet", {
    name: "db_subnet_group",
    subnetIds: [dbSubnet.id],
});
const postgresql = new aws.rds.Instance("postgresql", {
    allocatedStorage: 20,
    storageType: aws.rds.StorageType.GP2,
    engine: "postgres",
    engineVersion: "13.3",
    instanceClass: aws.rds.InstanceType.T2_Micro,
    name: "mydatabase",
    username: "admin",
    password: "password123",
    vpcSecurityGroupIds: [dbSg.id],
    dbSubnetGroupName: dbSubnetSubnetGroup.id,
});
const debezium = new aws.ec2.Instance("debezium", {
    ami: "ami-0c55b159cbfafe1f0",
    instanceType: aws.ec2.InstanceType.T2_Micro,
    subnetId: dbSubnet.id,
    userData: `#!/bin/bash
yum update -y
yum install docker -y
service docker start
usermod -a -G docker ec2-user
docker run -d -p 8083:8083 --name debezium debezium/connect
`,
    tags: {
        Name: "DebeziumInstance",
    },
});
export const dbInstanceEndpoint = postgresql.endpoint;
export const dbInstanceIdentifier = postgresql.id;
export const debeziumInstancePrivateIp = debezium.privateIp;

In this setup:

  • We created a VPC and a subnet for our resources.
  • An RDS instance running PostgreSQL is provisioned.
  • Security Groups are configured to allow traffic to the PostgreSQL instance.
  • An EC2 instance is spawned and configured to run Debezium, which includes setting it up to run Docker and launching the Debezium Connect container.

This configuration sets up a PostgreSQL database on AWS and prepares an instance with Debezium for CDC tasks.

Deploy this code

Want to deploy this code? Sign up for a free Pulumi account to deploy in a few clicks.

Sign up

New to Pulumi?

Want to deploy this code? Sign up with Pulumi to deploy in a few clicks.

Sign up