# CfnOutput

Extends: Construct › CfnElement › CfnOutput
Implements: IConstruct, IDependable

- Source: [`core/lib/cfn-output.ts`](https://github.com/aws/aws-cdk/blob/v2.275.0/packages/aws-cdk-lib/core/lib/cfn-output.ts#L43)

## Example

```ts
declare const cluster: eks.Cluster;
// add service account
const serviceAccount = cluster.addServiceAccount('MyServiceAccount');

const bucket = new s3.Bucket(this, 'Bucket');
bucket.grantReadWrite(serviceAccount);

const mypod = cluster.addManifest('mypod', {
  apiVersion: 'v1',
  kind: 'Pod',
  metadata: { name: 'mypod' },
  spec: {
    serviceAccountName: serviceAccount.serviceAccountName,
    containers: [
      {
        name: 'hello',
        image: 'paulbouwer/hello-kubernetes:1.5',
        ports: [ { containerPort: 8080 } ],
      },
    ],
  },
});

// create the resource after the service account.
mypod.node.addDependency(serviceAccount);

// print the IAM role arn for this service account
new CfnOutput(this, 'ServiceAccountIamRole', { value: serviceAccount.role.roleArn });
```

## Initializer

```ts
new CfnOutput(scope: Construct, id: string, props: CfnOutputProps)
```

## Construct Props

- `condition`: [CfnCondition](/cdk/api/v2/docs/aws-cdk-lib.CfnCondition.html) — A condition to associate with this output value.

  **Default:** No condition is associated with the output.

  If the condition evaluates
  to `false`, this output value will not be included in the stack.

- `description`: string — A String type that describes the output value.

  **Default:** No description.

  The description can be a maximum of 4 K in length.

- `exportName`: string — The name used to export the value of this output across stacks.

  **Default:** the output is not exported

  To import the value from another stack, use `Fn.importValue(exportName)`.

- `key`: string — The key of the property returned by aws cloudformation describe-stacks command.

- `value`: string (required) — The value of the property returned by the aws cloudformation describe-stacks command.

  The value of an output can include literals, parameter references, pseudo-parameters,
  a mapping value, or intrinsic functions.

## Properties

- `condition`: [CfnCondition](/cdk/api/v2/docs/aws-cdk-lib.CfnCondition.html) — A condition to associate with this output value.

  **Default:** No condition is associated with the output.

  If the condition evaluates
  to `false`, this output value will not be included in the stack.

- `creationStack`: string[]

- `description`: string — A String type that describes the output value.

  **Default:** No description.

  The description can be a maximum of 4 K in length.

- `exportName`: string — The name used to export the value of this output across stacks.

  **Default:** the output is not exported

  To use the value in another stack, pass the value of
  `output.importValue` to it.

- `importValue`: string — Return the `Fn.importValue` expression to import this value into another stack.

  The returned value should not be used in the same stack, but in a
  different one. It must be deployed to the same environment, as
  CloudFormation exports can only be imported in the same Region and
  account.

  The is no automatic registration of dependencies between stacks when using
  this mechanism, so you should make sure to deploy them in the right order
  yourself.

  You can use this mechanism to share values across Stacks in different
  Stages. If you intend to share the value to another Stack inside the same
  Stage, the automatic cross-stack referencing mechanism is more convenient.

- `logicalId`: string — The logical ID for this CloudFormation stack element.

  The logical ID of the element
  is calculated from the path of the resource node in the construct tree.

  To override this value, use `overrideLogicalId(newLogicalId)`.

- `node`: [Node](/cdk/api/v2/docs/constructs.Node.html) — The tree node.

- `stack`: [Stack](/cdk/api/v2/docs/aws-cdk-lib.Stack.html) — The stack in which this element is defined.

  CfnElements must be defined within a stack scope (directly or indirectly).

- `value`: any — The value of the property returned by the aws cloudformation describe-stacks command.

  The value of an output can include literals, parameter references, pseudo-parameters,
  a mapping value, or intrinsic functions.

## Methods

- `isCfnElement(x: any): boolean` (static) — Returns `true` if a construct is a stack element (i.e. part of the synthesized cloudformation template).

  Uses duck-typing instead of `instanceof` to allow stack elements from different
  versions of this library to be included in the same stack.

  **Returns:** The construct as a stack element or undefined if it is not a stack element.

- `isConstruct(x: any): boolean` (static) — Checks if `x` is a construct.

  Use this method instead of `instanceof` to properly detect `Construct`
  instances, even when the construct library is symlinked.

  Explanation: in JavaScript, multiple copies of the `constructs` library on
  disk are seen as independent, completely different libraries. As a
  consequence, the class `Construct` in each copy of the `constructs` library
  is seen as a different class, and an instance of one class will not test as
  `instanceof` the other class. `npm install` will not create installations
  like this, but users may manually symlink construct libraries together or
  use a monorepo tool: in those cases, multiple copies of the `constructs`
  library can be accidentally installed, and `instanceof` will behave
  unpredictably. It is safest to avoid using `instanceof`, and using
  this type-testing method instead.

  **Parameters**

  - `x` — Any object.

  **Returns:** true if `x` is an object created from a class which extends `Construct`.

- `overrideLogicalId(newLogicalId: string): void` — Overrides the auto-generated logical ID with a specific ID.

  **Parameters**

  - `newLogicalId` — The new logical ID to use for this stack element.

- `toString(): string` — Returns a string representation of this construct.

- `with(...mixins: IMixin[]): IConstruct` — Applies one or more mixins to this construct.

  Mixins are applied in order. The list of constructs is captured at the
  start of the call, so constructs added by a mixin will not be visited.
  Use multiple `with()` calls if subsequent mixins should apply to added
  constructs.
