Migrating From CDK
A guide to migrating your CDK app to SST.
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:
There is no
cdk.json
If you have a
context
block in yourcdk.json
, you can move it to acdk.context.json
. You can read more about this here. You'll also need to add asst.json
config file, as talked about here. Here is a sample config for reference.{
"name": "my-sst-app",
"stage": "dev",
"region": "us-east-1"
}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 samplestacks/index.js
for reference.import MyStack from "./MyStack";
export default function main(app) {
new MyStack(app, "my-stack");
// Add more stacks
}Stacks are written as functions
Your classes are written as functions instead of
cdk.Stack
. Here is what the JavaScript version looks like.import * as sst from "sst/constructs";
export function MyStack(ctx) {}And in TypeScript.
import * as sst from "sst/constructs";
export function MyStack(ctx: sst.StackContext) {}Lambdas use
sst.Function
Use the
sst.Function
construct instead ofcdk.lambda.NodejsFunction
.Include the right packages
You don't need the
aws-cdk
package in yourpackage.json
. Instead you'll needsst
package.