Hi,
I have created an empty CDK pipeline and package. In the CDK package, I created a deployment stack for Kinesis stream which created 3 new kinesis streams. There are 3 DDBs existing in the AWS account to which each one of these kinesis streams has to be made consumers of. I can integrate the DDBs with the kinesis stream using the UI but I want to import the DDBs into a CDK stack and add kinesisStream
from TableOptionsV2
.
To do the above, I followed the AWS guide for cdk import
: https://docs.aws.amazon.com/cdk/v2/guide/cli.html#cli-import
- Created an empty stack
DDBStack.ts
and deployed it to CloudFormation using brazil-build cdk deploy DDStack-beta
export class DDBStack extends DeploymentStack {
constructor(app: Construct, id: string, props: DDBStackProps) {
super(app, id, props);
}
}
- Created a CDK construct in that stack for 1st DDB with the same existing model as present in UI and did
cdk-import
(had to provide the name of the DDB to be imported). This created the DDB resource and imported the existing DDB into it.
interface DDBStackProps extends DeploymentStackProps {
kinesisStreamForMyDDB: IStream;
}
export class DDBStack extends DeploymentStack {
MyDDB: TableV2;
constructor(app: Construct, id: string, props: DDBStackProps) {
super(app, id, props);
const { kinesisStreamForMyDDB } = props;
this.MyDDB = new TableV2(this, 'MyDDB', {
partitionKey: { name: 'PK', type: AttributeType.STRING },
sortKey: { name: 'SK', type: AttributeType.STRING },
pointInTimeRecovery: true,
});
}
}
- Added
kinesisStream
from TableOptionsV2
to the DDB construct props and deployed the stack again. Now, the kinesis stream was added as a consumer for that DDB
this.MyDDB = new TableV2(this, 'MyDDB', {
partitionKey: { name: 'PK', type: AttributeType.STRING },
sortKey: { name: 'SK', type: AttributeType.STRING },
pointInTimeRecovery: true,
kinesisStream: kinesisStreamForMyDDB,
});
- Repeated steps 2-3 for the rest of the 2 DDBs.
Now, when I merge my code and it gets propagated thru the CDK pipeline to Prod, the DDBStack-prod
stack will be deployed in the prod AWS account with the 3 DDBs and attached kinesis streams. But, the stack will not import the existing DDBs present in AWS account because cdk import
was never run before the stack was deployed. How do I mimic the above workflow for Prod?