Hi! I discovered this yesterday thanks to a collea...
# general
m
Hi! I discovered this yesterday thanks to a colleague. I have several existing lambdas - has anyone attempted to migrate existing CDK infrastructure to SST constructs (everything's TS so we're ok there). I really want to to improve the dev/debugging experience for myself and my team
t
Yes we've had a few people do this and it seems to be fine. Ultimately sst is 100% compatible with cdk so shouldn't run into issues. Can convert your functions progressively to sst.Function too
m
that's exactly what I want to do - Ideally i can progressively change solely the functions - and not any of the other constructs
we have AppSync, DDB, RDS blah blah blah and i'd prefer not to modify those
t
The thing I've never learned how to do properly is move constructs around to new stacks without messing with the underlying resources. There's a way to do it though
d
You can also just do those things NOT inside an SST app, and deploy only the functions within it. I say this not because SST has any compatibility issues, but just that importing things in Cloudformation in general is not the most fun.
t
^ exactly lol
I'd love to add an
sst import <resource>
command at some point to make this easier
Sometimes I poorly organize a stack and want to move resources to a new one and it's a pain
a
Yup, don't need to change the resources. I'm using the CDK DynamoDB Table construct, not the SST one. I migrated that from CloudFormation, so it was practically 1:1 translation to the CDK version. Works fine.
m
great point, Derek. In fact, I would ideally not change my staging/prod stacks whatsoever and limit this solely to developer environments
thanak you dax, adam, derek
i'm on day 7 of covid exposure isolation (i am completely fine and tested neg twice) so, plenty of time to experiment with this!
d
I have done it a few times @thdxr, I do not recommend it to anyone unless forced. I will say that the CDK actually makes it no more difficult than straight CFn. In general, automating this would be really tough, only because there is no way to be completely sure about what needs to be deleted, recreated, and what needs to be imported. An example is a Opensearch DB. To import/move, I needed to delete 7 different items having to do with IAM and Route53, then import the DB, then recreate those items.
t
I'm mainly thinking about how terraform works and it supports this and was hoping there's a way to recreate it. @Frank is the CFN expert though
d
You also may need to switch things from
Destroy
to
Retain
, "Delete" them from stack1, then do the above.
a
Terraform doesn't use CloudFormation, so it'd be relatively easy there.
d
My thought is that it is likely possible, but that you guys should probably let AWS do it, lol.
m
ideally, I would not move anything - but conditionally create either an sst or a vanilla CDK
function
construct based on an env parameter
i used to work at AWS, best way toget them to do something is demand it!
t
We already do a lot of things CFN should handle natively haha
m
i had a few former CFN colleagues, sharp people but quite overburdened and burnt out - but highly attentive to customers
t
The thing I'm confused about is the steps seem to be 1. Make sure resource is set to retain 2. Remove it from StackA 3. How do you add it to StackB while also telling it to import at the same time? Can you do this through cdk or do you have to use the console with cfn?
d
Dont forget deleting Dependent resources from StackA (this would be step 2)
a
There is some import capability in AWS Console/CloudFormation. The one time I tried to do it though, it told me the resource I wanted to import wasn't supported. 😞
d
But importing would be a SDK thing (or console), THEN CDK gets involved.
m
maybe i'm being myopic - but - why would you WANT to do this?
d
the import would use the
synth
from the CDK, though
Its usually Databases @Mike Nissenbaum. Recreating the Database and all the data can be harder than this.
m
ah fair , i have been narrowly considering only application code
t
sometimes you put a resource in a stack and later realize it should go in a new stack
you're kinda tied to initial organizational decisions
a
The scenario I hit is when trying to delete a stack to recreate it, and something can't be deleted in the stack. Would be great if that resource could be left behind (orphaned) and then picked up when recreating the stack. S3 buckets are a common example.
t
yep