-
Notifications
You must be signed in to change notification settings - Fork 83
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cross-Region/Account References #161
Comments
Proof of ConceptThis is how I make it work: Let's say, there are two stacks viz., To solve the issue, I define two helper functions, one of which is this: export function createLocalExports(
scope: cdk.Construct,
exports: { key: string; value: string }[]
) {
exports.forEach(export => {
new cdk.CfnOutput(scope, export.key, {
value: export.value
});
});
}
createLocalExports(this, [{
key: 'UserIdentityPoolId',
value: userIdentityPool.ref
}]); Then, running To consume outputs, here's another helper function: export function importStackOutput(outputKey: string) {
const outputFilePath = path.join(__dirname, 'relative/path/to/output.json' );
let stackOutputs: {
[key: string]: { [key: string]: string };
};
try {
stackOutputs = JSON.parse(
fs.readFileSync(outputFilePath).toString('UTF-8')
);
} catch (error) {
stackOutputs = {};
}
return Object.keys(stackOutputs).length ? stackOutputs['Stack1'][outputKey] : '';
}
const userIdentityPoolId = importStackOutput('UserIdentityPoolId');
// use userIdentityPoolId wherever you want So, the final command to deploy everything would be: It works! |
|
Hi @SachinShekhar! Thanks for the thoughtful proposal. We know that cross-environment references have interesting use cases and would love to consider ideas for solutions. I am moving this issue to our RFCs repo, which is where we can discuss such topics. Based on our current plans, I doubt that this major feature is something we can commit to in the coming months, but if you wish to continue the conversation, I'd recommend that you follow our RFC process and submit a detailed proposal. From the outset, as you observed, the main challenge I see with this approach is that it breaks a fundamental design tenets which says that synthesis is isolated from deployment. This tenet is important for security reasons and in order to allow CDK apps to be deployed through CI/CD systems. I would encourage you to consider designs that "stay within the bounds" of the current model. For example, use CFN custom resources to query values across environments during deployment. |
"I would encourage you to consider designs that "stay within the bounds" of the current model. For example, use CFN custom resources to query values across environments during deployment." If that's the best practice that needs to go in the docs. |
Marking this RFCs as |
An idea to fix cross-region/account resource sharing issue which goes beyond resource sharing capabilities of CloudFormation.
Use Case
CDK is a wonderful product which should get Best Cloud Innovation Award. It allows us to create super complex cloud infrastructure quickly without needing a team of hundreds or thousands.
Cross-region/account resource sharing is only natural for even small projects. It should have worked smoothly like same env resource sharing. Unfortunately, only those references which doesn't involve CloudFormation work (that's also if we provide
PhysicalName
or usecore.PhysicalName.GENERATE_IF_NEEDED
). To reference CloudFormation generated refs, we need to use complex strategies usingNestedStack
,CustomResource
,ProviderFramework
.This feature will make everything smooth and simple. Users will be able to share resources across stacks without thinking about stack's env. Splitting existing CDK apps across multiple accounts will also become easy.
Proposed Solution
If there are circular dependencies across stacks, throw error.
Synthesize and deploy only those stacks which are dependencies.
Retrieve resolved refs from previous step and use them to synthesize and deploy dependent stacks.
Repeat the last step if there are more dependent stacks.
Other
CDK Synth
won't be able to work without deployment, so it should throw error if there are cross-region/account references. It shouldn't be called BREAKING CHANGE because existing CDK apps won't be affected. This is a small price to pay if someone wants to use new cross-region/account reference feature. Maybe, to make existing behavior same, a new flag inApp
class can be introduced which will need to be turned ON to use this new feature.This is a 🚀 Feature Request
The text was updated successfully, but these errors were encountered: