Skip to content

Instantly share code, notes, and snippets.

@andreif
Created February 22, 2024 10:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andreif/76ffc5a8aec70212cc7835a7d610546b to your computer and use it in GitHub Desktop.
Save andreif/76ffc5a8aec70212cc7835a7d610546b to your computer and use it in GitHub Desktop.
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