Replies: 1 comment
-
|
cdk refactor is relatively new and has some rough edges. Here is what typically goes wrong and a working example. Common issues
Working exampleStep 1: Deploy original stackconst app = new cdk.App();
const myStack = new cdk.Stack(app, "MyStack");
const bucket = new s3.Bucket(myStack, "Bucket");
const distribution = new cloudfront.Distribution(myStack, "Distribution", {
defaultBehavior: { origin: new origins.S3BucketOrigin(bucket) },
});cdk deploy MyStackStep 2: Refactor the code (move into a construct)class WebsiteConstruct extends Construct {
constructor(scope: Construct, id: string) {
super(scope, id);
const bucket = new s3.Bucket(this, "Bucket");
new cloudfront.Distribution(this, "Distribution", {
defaultBehavior: { origin: new origins.S3BucketOrigin(bucket) },
});
}
}
const app = new cdk.App();
const myStack = new cdk.Stack(app, "MyStack");
new WebsiteConstruct(myStack, "Website");Step 3: Run refactorcdk refactor --dry-runThis should show the mapping:
If it works in dry-run: cdk refactor
cdk deploy MyStackTroubleshooting
What errors are you seeing specifically? The error message would help narrow it down. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Has anyone managed to get
cdk refactorto do anything at all? I'm following this guide with a simple change: the lambda replieshello world, but I still got some errors...FWIW: I first deployed the stack from the example:
Then, I had to deploy an empty stack (
cdk refactorlimitation). I also added thelogicalIds to confirm my override file was ok (more on that later):And finally, made this stack, which is what I expect to refactor (haven't deployed tho, as refactor should do that):
I tried a
cdk refactor --unstable=refactor, and got an error:So then I made an
override.jsonfile, as those three resource it complains about are actually part of those I want to move (the bucket and the CF distro):But using this override file yields the same result as before. Is there any working example to try this out? Has anyone get this to work?
Beta Was this translation helpful? Give feedback.
All reactions