# CloudAssembly

Represents a deployable cloud application.

Extends: CloudAssembly
Implements: ICloudAssembly

- Source: [`cx-api/lib/legacy-moved.ts`](https://github.com/aws/aws-cdk/blob/v2.275.0/packages/aws-cdk-lib/cx-api/lib/legacy-moved.ts#L149)
- Type last changed: v2.232.0 · 5 Dec 2025

## Example

```ts
// The code below shows an example of how to instantiate this type.
// The values are placeholders you should change.
import { cx_api } from 'aws-cdk-lib';
const cloudAssembly = new cx_api.CloudAssembly('directory', /* all optional props */ {
  skipEnumCheck: false,
  skipVersionCheck: false,
  topoSort: false,
  validateSchema: false,
});
```

## Initializer

```ts
new CloudAssembly(directory: string, loadOptions?: LoadManifestOptions)
```

## Properties

- `artifacts`: [CloudArtifact](/cdk/api/v2/docs/aws-cdk-lib.cx_api.CloudArtifact.html)[] — All artifacts included in this assembly.

- `directory`: string — The root directory of the cloud assembly.

- `manifest`: [AssemblyManifest](/cdk/api/v2/docs/aws-cdk-lib.cloud_assembly_schema.AssemblyManifest.html) — The raw assembly manifest.

- `nestedAssemblies`: [NestedCloudAssemblyArtifact](/cdk/api/v2/docs/aws-cdk-lib.cx_api.NestedCloudAssemblyArtifact.html)[] — The nested assembly artifacts in this assembly.

- `runtime`: [RuntimeInfo](/cdk/api/v2/docs/aws-cdk-lib.cloud_assembly_schema.RuntimeInfo.html) — Runtime information such as module versions used to synthesize this assembly.

- `stacks`: [CloudFormationStackArtifact](/cdk/api/v2/docs/aws-cdk-lib.cx_api.CloudFormationStackArtifact.html)[]

- `stacksRecursively`: [CloudFormationStackArtifact](/cdk/api/v2/docs/aws-cdk-lib.cx_api.CloudFormationStackArtifact.html)[] — Returns all the stacks, including the ones in nested assemblies.

- `version`: string — The schema version of the assembly manifest.

## Methods

- `cleanupTemporaryDirectories(): void` (static) — Cleans up any temporary assembly directories that got created in this process.

  If a Cloud Assembly is emitted to a temporary directory, its directory gets
  added to a list. This function iterates over that list and deletes each
  directory in it, to free up disk space.

  This function will normally be called automatically during Node process
  exit and so you don't need to call this. However, some test environments do
  not properly trigger Node's `exit` event. Notably: Jest does not trigger
  the `exit` event (<https://github.com/jestjs/jest/issues/10927>).

  ## Cleaning up temporary directories in jest

  For Jest, you have to make sure this function is called at the end of the
  test suite instead:

  ```js
  import { CloudAssembly } from 'aws-cdk-lib/cx-api';

  afterAll(CloudAssembly.cleanupTemporaryDirectories);
  ```

  Alternatively, you can use the `setupFilesAfterEnv` feature and use a
  provided helper script to automatically inject the above into every
  test file, so you don't have to do it by hand.

  ```
  $ npx jest --setupFilesAfterEnv aws-cdk-lib/testhelpers/jest-autoclean
  ```

  Or put the following into `jest.config.js`:

  ```js
  module.exports = {
    // ...
    setupFilesAfterEnv: ['aws-cdk-lib/testhelpers/jest-autoclean'],
  };
  ```

- `getNestedAssembly(artifactId: string): CloudAssembly // chainable` — Returns a nested assembly.

  **Parameters**

  - `artifactId` — - The artifact ID of the nested assembly.

- `getNestedAssemblyArtifact(artifactId: string): NestedCloudAssemblyArtifact` — Returns a nested assembly artifact.

  **Parameters**

  - `artifactId` — - The artifact ID of the nested assembly.

- `getStackArtifact(artifactId: string): CloudFormationStackArtifact` — Returns a CloudFormation stack artifact from this assembly.

  **Parameters**

  - `artifactId` — - the artifact id of the stack (can be obtained through `stack.artifactId`).

  **Returns:** a `CloudFormationStackArtifact` object.

- `getStackByName(stackName: string): CloudFormationStackArtifact` — Returns a CloudFormation stack artifact from this assembly.

  Will only search the current assembly.

  **Parameters**

  - `stackName` — - the name of the CloudFormation stack.

  **Returns:** a `CloudFormationStackArtifact` object.

- `isCloudAssembly(x: any): boolean` (static) — Return whether the given object is a CloudAssembly.

  We do attribute detection since we can't reliably use 'instanceof'.

- `tree(): TreeCloudArtifact` — Returns the tree metadata artifact from this assembly.

  **Returns:** a `TreeCloudArtifact` object if there is one defined in the manifest, `undefined` otherwise.

- `tryGetArtifact(id: string): CloudArtifact` — Attempts to find an artifact with a specific identity.

  **Parameters**

  - `id` — - The artifact ID.

  **Returns:** A `CloudArtifact` object or `undefined` if the artifact does not exist in this assembly.
