Created
February 22, 2024 10:35
-
-
Save andreif/76ffc5a8aec70212cc7835a7d610546b to your computer and use it in GitHub Desktop.
Revisions
-
andreif created this gist
Feb 22, 2024 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,36 @@ import { Construct } from 'constructs'; import { CfnOutput, Stack } from 'aws-cdk-lib'; import * as cdk from 'aws-cdk-lib'; export function output(scope: Construct, name: string, value: string) { return new CfnOutput(scope, name, { value, exportName: `${Stack.of(scope).stackName}:${name}`, }); } export function importOutput(output: cdk.CfnOutput) { return cdk.Fn.importValue(output.exportName as string); } export class MyStack extends Stack { outputMyValue; constructor(scope: Construct, id: string, props: MyStackProps) { super(scope, id, props); this.outputMyValue = output(this, 'MyValue', '123'); } } export function construct(app: cdk.App, env: cdk.Environment, orgId: string) { const tags = {team: 'MyTeam'}; const myStack = new MyStack(app, `my-${envName}`, {env, tags, envName}) const myOtherStack = new MyOtherStack(app, `my-other-${envName}`, { myValue: importOutput(myStack.outputMyValue), }); });