Skip to main content

Get outputs from cross-regional AWS CDK stacks

Project description

awscdk-jsii-template NPM version PyPI version Release

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:

  1. stackJP - cdk stack in JP to create a SNS topic
  2. stackUS - cdk stack in US to get the Outputs from stackJP and print out the SNS TopicName from stackJP Outputs.
# Example automatically generated without compilation. See https://github.com/aws/jsii/issues/826
from cdk_remote_stack import StackOutputs
import aws_cdk.core as cdk
import aws_cdk.aws_sns as sns

app = cdk.App()

env_jP = {
    "region": "ap-northeast-1",
    "account": process.env.CDK_DEFAULT_ACCOUNT
}

env_uS = {
    "region": "us-west-2",
    "account": process.env.CDK_DEFAULT_ACCOUNT
}

# first stack in JP
stack_jP = cdk.Stack(app, "demo-stack-jp", env=env_jP)

topic = sns.Topic(stack_jP, "Topic")

cdk.CfnOutput(stack_jP, "TopicName", value=topic.topic_name)

# second stack in US
stack_uS = cdk.Stack(app, "demo-stack-us", env=env_uS)

# ensure the dependency
stack_uS.add_dependency(stack_jP)

# get the stackJP stack outputs from stackUS
outputs = StackOutputs(stack_uS, "Outputs", stack=stack_jP)

remote_output_value = outputs.get_att_string("TopicName")

# the value should be exactly the same with the output value of `TopicName`
cdk.CfnOutput(stack_uS, "RemoteTopicName", value=remote_output_value)

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cdk-remote-stack-0.1.61.tar.gz (19.8 kB view hashes)

Uploaded source

Built Distribution

cdk_remote_stack-0.1.61-py3-none-any.whl (19.9 kB view hashes)

Uploaded py3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page