Package Exports
- cdk-remote-stack
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (cdk-remote-stack) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
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
JPto create a SNS topic - stackUS - cdk stack in
USto get the Outputs fromstackJPand print out the SNSTopicNamefromstackJPOutputs.
import { StackOutputs } from 'cdk-remote-stack';
import * as cdk from '@aws-cdk/core';
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,
};
// first stack in JP
const stackJP = new cdk.Stack(app, 'demo-stack-jp', { env: envJP })
new cdk.CfnOutput(stackJP, 'TopicName', { value: 'foo' })
// second stack in US
const stackUS = new cdk.Stack(app, 'demo-stack-us', { env: envUS })
// ensure the dependency
stackUS.addDependency(stackJP)
// get the stackJP stack outputs from stackUS
const outputs = new StackOutputs(stackUS, 'Outputs', { stack: stackJP })
const remoteOutputValue = outputs.getAttString('TopicName')
// the value should be exactly the same with the output value of `TopicName`
new cdk.CfnOutput(stackUS, 'RemoteTopicName', { value: remoteOutputValue })always get the latest stack output
By default, the StackOutputs construct will always try to get the latest output from the source stack, you may opt out by setting alwaysUpdate to false to turn this feature off.
For example:
const outputs = new StackOutputs(stackUS, 'Outputs', {
stack: stackJP,
alwaysUpdate: false,
})