Does anyone have a favourite guide on importing ex...
# sst
d
Does anyone have a favourite guide on importing existing AWS resources into their CDK/SST cloudformation stacks? I’m trying to recreate VPCS, Route53, and foundational stuff without having to destroy & recreate everything
f
Hey @Drew, you can import a VPC like this:
Copy code
ec2.Vpc.fromLookup(this, "ImportedVPC", {
  vpcId
});
More details here
On the app structure side, I’ve seen many folks have a 
CoreStack
that either creates or imports the foundational resources.
d
👍 that makes sense for our core foundation
f
If you want multiple developers (multiple stages) to share the same VPC, you can do somehting like this:
Copy code
if (stage === "dev-main") {
  this.vpc = new ec2.Vpc(...)
}
else if (stage.startsWith ("dev-")) {
  this.vpc = ec2.Vpc.lookup(...)
}
So you create the VPC only in
dev-main
stage, and
dev-drew
,
dev-frank
stages imports its VPC.
d
🤔 this may work….
If we manually created the ec2.Vpc()…. but when we run the
dev-main
deploy we want it to create the VPC if it doesn’t exist….
a
@Frank can you guys document a guide or something like that for best practices? I think we all have the same question around strategies.
j
Yeah we need to do make this more of a priority for sure!
f
@Adrián Mouly 🙌 Agreed!