Example: DB2 Replication with InfoCDC and the AWS Stack
Overview
This guide shows how to replicate IBM i DB2 tables to external data sources in near real time. It combines InfoCDC, the Infoview change data capture (CDC) product for IBM i, with the AWS messaging services Amazon SNS and AWS Lambda. Use it when messaging infrastructure is part of your replication architecture.
Note
InfoConnect Hub 3.0.0 and later replicates IBM i data directly to any JDBC-compliant database, without messaging infrastructure or custom code. See IBM i data replication.
The example uses Amazon Simple Notification Service (SNS) and AWS Lambda for an end-to-end replication solution:

Configuring InfoCDC
Install and configure InfoCDC first. See the InfoCDC installation and configuration guide.
Configuring InfoConnect Hub and the AWS services
To replicate IBM i DB2 table data to external data sources with AWS services, complete these steps:
- Configure an SNS topic.
- Configure a Lambda function as a target for the messages sent to the topic.
- Configure a data queue (DQ) poller that moves messages from IBM i DB2 records to the SNS topic.
Step 1: Configure an SNS topic
An Amazon SNS topic is a logical access point that acts as a communication channel.
- Open the Amazon SNS console.
- On the Topics page, choose Create topic.
- On the Create topic page, do the following:
- For Type, choose Standard, which is required for the Lambda subscription protocol.
- Enter the topic name in the Name field.
- Choose Create topic.
-
Copy the topic ARN (Amazon Resource Name). You need it later to configure the DQ poller. For example:
Amazon SNS offers more topic settings, such as encryption and custom access policies. See Creating an Amazon SNS topic.
Step 2: Configure a Lambda function
The Lambda function processes the SNS notifications and sends them to an external database.
- Open the AWS Lambda console.
- Choose Create function.
- On the Create function page, select Author from scratch.
- In Basic configuration, do the following:
- Enter the function name, for example
AWSDataReplication. - For Runtime, choose Python 3.9. Other supported languages also work.
- Enter the function name, for example
- Choose Create function.
-
On the function configuration page, paste the following code:
# Import packages import json import boto3 from decimal import Decimal # Function definition def lambda_handler(event, context): dynamodb = boto3.resource('dynamodb') message = event['Records'][0]['Sns']['Message'] print('Sns message: ' + message) # Table name table = dynamodb.Table('awsdemo') # Insert the values into the table response = table.put_item(Item=json.loads(message, parse_float=Decimal)) return messageThe code reads a message from SNS and writes it to a DynamoDB table named
awsdemo. For InfoCDC replication you can use a different target database. -
Choose Deploy.
- In Function overview, choose Add trigger and select SNS as the source.
- For SNS topic, select the topic that you configured in step 1.
- Choose Add.
Step 3: Configure a DQ poller for Amazon SNS
A DQ poller moves data from an IBM i DB2 record to a sink, in this example Amazon SNS. Call the Admin API of the Hub to create the connection and the poller.
-
Create the connection to the IBM i server:
Use the sample request below.
<public-dns>is the public DNS name that Amazon assigns to the instance.Sample JSON for the connection request
{ "connectionName": "hubdemo", "endpoint": "your-as400-endpoint", "userId": "userid", "password": "encrypted-password", "libraryList": "comma-separated-list-of-libraries", "libraryListMode": "ADD_LAST", "jobTrace": false, "secureConnection": true, "tlsConfig": { "tlsIsInsecure": false, "tlsKeystoreConfigured": false, "tlsTruststoreConfigured": true, "tlsFileName": "info400new.truststore", "truststorePassword": "encrypted-password" }, "connectionPoolConfig": { "operationType": 2, "preStartCountDataQueue": 2, "preStartCountCommand": 2, "maxConnections": 10, "maxInactivity": 3600000, "maxLifeTime": 86400000, "maxUseCount": -1, "maxUseTime": -1, "cleanupInterval": 300000, "pretestConnections": true, "runMaintenance": true, "threadUsed": true, "CCSID": 0 }, "transportConfig": { "licenseFileProtocol": "FILE", "truststoreFileProtocol": "S3", "licenseFileName": "as400-license.lic", "FILE": { "filePath": "license-file-location-in-shared-storage" }, "S3": { "s3Bucket": "as400-bucket", "s3Region": "us-east-2", "s3AccessKey": "encrypted-aws-access-key", "s3SecretKey": "encrypted-aws-secret-key" } } } -
Create the DQ poller with the SNS broker:
Use the sample request below. The value of
snsTopicNameinsnsPropertiesmust match the topic ARN that you created in step 1.Sample JSON for the DQ poller request with SNS
{ "pollerName": "sns-poller", "connectionName": "<connection-name>", "pollerType": "Source", "dqName": "HUBDQ", "libraryName": "INFOCDC", "sinkType": "SNS", "sinkTypeProperties": { "snsProperties": { "snsTopicName": "arn:aws:sns:us-east-2:123456789012:AWSReplicationTopic", "accessKey": "encrypted-aws-access-key", "secretKey": "encrypted-aws-secret-key", "region": "us-east-2" } }, "threadCount": 10, "dqFormatFileName": "HUBFT", "dqFormatFileLibrary": "INFOCDC" }