- Newest
- Most votes
- Most comments
Hello,
Hope you are doing well!
I understand that you want to know if in a single CDK project, you can pass stack output from one stack in account_A to another stack in Account_B. In the CDK example provided, like you said, it is creating exports from "ECRRepositoryStack" stack, which will be imported by Stack "ecsfargateStack" to consume.
The answer is no, CDK does not support this use-case due to underlying Service AWS CloudFormation has limitation around stack exports and imports.
Although CDK is a more programmatic service, but limitations from the heavy lifting service CloudFormation still apply. The Exports/Imports feature of CloudFormation is for cross-reference so stacks that are in the same AWS account and region can import the exported values[1]. Therefore, the CDK cross-stack reference like this are still leveraging the same feature so not even cross region can be achieved:
# Base infrastructure stack, Lambda Functions, DynamoDB Tables, etc....
infra = InfraStack(app, "CDK-L3-infrastructure", env=env)
# Application stack that generally changes independently of the underlying infrastructure stack
application = ComputeStack(app, "CDK-L3-application", referenced_function=infra.main_function, referenced_vpc=infra.main_vpc, env=env)
Please consider store your values need to be retrieved in another regions/accounts in a SecreteManager Secret along with necessary trust policies. So other stack in different region can just get its value by utilizing
static fromSecretNameV2(scope, id, secretName)[2]
Best regards
References:
[1] https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/using-cfn-stack-exports.html
[2] https://docs.aws.amazon.com/cdk/api/v1/docs/@aws-cdk_aws-secretsmanager.Secret.html#methods
Relevant content
- asked 2 years ago
- AWS OFFICIALUpdated a year ago
- AWS OFFICIALUpdated 3 years ago
- AWS OFFICIALUpdated 8 months ago
- AWS OFFICIALUpdated 5 months ago
- AWS OFFICIALUpdated 4 months ago