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), }); });