Created
February 22, 2024 10:35
-
-
Save andreif/76ffc5a8aec70212cc7835a7d610546b to your computer and use it in GitHub Desktop.
This file contains 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 characters
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), | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment