Skip to main content

Migrating From CDK

note

You can use all the CDK constructs in an SST app. This doc describes how to turn a CDK app into an SST app.

SST is an extension of AWS CDK. It's fairly simple to move a CDK app to SST. You just need to account for a couple of small differences:

  1. There is no cdk.json

    If you have a context block in your cdk.json, you can move it to a cdk.context.json. You can read more about this here. You'll also need to add a sst.json config file, as talked about here. Here is a sample config for reference.

    {
    "name": "my-sst-app",
    "stage": "dev",
    "region": "us-east-1"
    }
  2. There is no bin/*.js

    Instead there is a stacks/index.js that has a default export function where you can add your stacks. SST creates the App object for you. This is what allows SST to ensure that the stage, region, and AWS accounts are set uniformly across all the stacks. Here is a sample stacks/index.js for reference.

    import MyStack from "./MyStack";

    export default function main(app) {
    new MyStack(app, "my-stack");

    // Add more stacks
    }
  3. Stacks extend sst.Stack

    Your stack classes extend sst.Stack instead of cdk.Stack. Here is what the JavaScript version looks like.

    import * as sst from "@serverless-stack/resources";

    export default class MyStack extends sst.Stack {
    constructor(scope, id, props) {}
    }

    And in TypeScript.

    import * as sst from "@serverless-stack/resources";

    export class MyStack extends sst.Stack {
    constructor(scope: sst.App, id: string, props?: sst.StackProps) {}
    }
  4. Lambdas use sst.Function

    Use the sst.Function construct instead of cdk.lambda.NodejsFunction.

  5. Include the right packages

    You don't need the aws-cdk package in your package.json. Instead you'll need @serverless-stack/cli and @serverless-stack/resources.