cdk-remote-stack
Get outputs from cross-regional AWS CDK stacks
Why
AWS CDK cross-regional cross-stack reference is not easy with the native AWS CDK construct library.
cdk-remote-stack
aims to simplify the cross-regional cross-stack reference to help you easily build cross-regional multi-stack AWS CDK apps.
Sample
Let's say we have two cross-region CDK stacks in the same cdk app:
- stackJP - cdk stack in
JP
to create a SNS topic - stackUS - cdk stack in
US
to get the Outputs from stackJP
and print out the SNS TopicName
from stackJP
Outputs.
import { StackOutputs } from 'cdk-remote-stack';
import * as cdk from '@aws-cdk/core';
import * as sns from '@aws-cdk/aws-sns';
const app = new cdk.App();
const envJP = {
region: 'ap-northeast-1',
account: process.env.CDK_DEFAULT_ACCOUNT,
};
const envUS = {
region: 'us-west-2',
account: process.env.CDK_DEFAULT_ACCOUNT,
};
const stackJP = new cdk.Stack(app, 'demo-stack-jp', { env: envJP })
const topic = new sns.Topic(stackJP, 'Topic');
new cdk.CfnOutput(stackJP, 'TopicName', { value: topic.topicName })
const stackUS = new cdk.Stack(app, 'demo-stack-us', { env: envUS })
const outputs = new StackOutputs(stackUS, 'Outputs', { stack: stackJP })
const remoteOutputValue = outputs.getAttString('TopicName')
new cdk.CfnOutput(stackUS, 'RemoteTopicName', { value: remoteOutputValue })