> ## Documentation Index
> Fetch the complete documentation index at: https://docs.deplify.com/llms.txt
> Use this file to discover all available pages before exploring further.

# CDK Provider Blueprint

Need full control of what infrastructure gets deployed? Link your own CDK repository to define all of your own infrastructure in AWS.  Let Deplify handle managing the deployments of that infrastructure across multiple environments.

## Getting Started

Deploying your CDK project is easy, just follow the steps below.

<Steps>
  <Step title="Inject DEPLIFY_STACK_ID env variable as part of your cdk stack names.">
    <Info>
      **Note** This step is optional, but highly reccommended.
    </Info>

    As part of the build step, Deplify will provide a **DEPLIFY\_STACK\_ID** environment variable.  This is the unique identifier for a stack, this can be used to generate a unique cloudformation stack names to avoid naming collisions when deploying multiple versions of the same stack into the same AWS account.

    In your cdk code repo, when defining a CDK stack, you should use **DEPLIFY\_STACK\_ID** as part of the prefix.  Below is an example.

    ```java theme={null}
      const app = new cdk.App();
      new TestCdkStack(app, `${process.env.DEPLIFY_STACK_ID}-Stack`, {
        // ..props
      });
    ```
  </Step>

  <Step title="Ensure CDK code is environment agnostic">
    Deplify will handle deploying your CDK code to the correct AWS account + region.  So ensure you are not hardcoding any environment details in your CDK code.

    ```java theme={null}
    const app = new cdk.App();
    new TestCdkStack(app, `${process.env.DEPLIFY_STACK_ID}-Stack`, {
    // REMOVE THIS LINE IF YOU HAVE IT!!
    env: { account: '123456789012', region: 'us-east-1' },
    });
    ```
  </Step>

  <Step title="Create a CDK Provider stack in Deplify">
    <Warning>
      **Note** Deplify will handle running `cdk synth` & `cdk deploy` so do not add them in your build configuration. Deplify will always use the version of CDK defined in your package dependencies.
    </Warning>

    * Hit the `Add a Stack` button in the environment view.
    * Choose the `CDK Provider` blueprint.
    * If your project requires custom build commands, ensure you fill them in.  In most cases, you can leave the defaults.
    * Click `Create Stack`
  </Step>

  <Step title="All Done">
    Your project will begin deployment.  Track the deployment in the dashboard.
  </Step>
</Steps>
