Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
asgs115632yI have no idea but shouldn't changing the instance type create a new one and destroy the old one?
-
Tounai13052yIt should destroy your instance and then recreate a new one. CDK is just a fancy CloudFormation generator though, so it might share the same caveats
-
It’s a good practice to use immutable infastructure. So unless we’re trying to modify a stateful resource like a db, you should always replace. Since you are doing IaC anyways, why would you even need to modify compute instances in-place?
-
AurthurM1202y@100110111 actually the idea is to give user a customised ec2 instance when they buy a plan with some ready made service on ec2 and when user upgrade it i wished to modify ec2 instance.
But as i can see.. it is not possible to modify ec2 .
However the problem will be in changing the existing ebs volume with new updated ec2 instance. -
AurthurM1202y@asgs @asgs i think thats what i need to do, but what about existing storage what needs to attach to new ec2 if i destroy and create new one
-
you can always use an awscli/aws SDK from inside the ec2 to spin up another ec2 from the same AMI and change its specs. Once that's done, switch to that newer instance. And terminate the old one.
Or you could write and trigger a lambda that
- captures your ec2's state (sessid, configurations, whatever)
- scales your _current_ ec2 instance
- when ec2 starts back up - restores state/configs/whatever to the upgraded ec2.
Though lambda has a runtime limit of 15 minutes, so you'll have to make sure this manoeuvre completes sooner, otherwise, it'll all go down the gutter.
To keep your files intact, you can use non-ephemeral storage (EBS) instead of the ephemeral intance-storage -
AurthurM1202yThanks all, for your comments.
I think i have to use either aws cli with bash script or aws sdk to modify ec2 and ebs volume without creating a new one.
Related Rants
How can we modify ec2 instance with cdk stack or pipeline?
I am able to launch the ec2 instance but whenever i modify the stack it creates a new instance.
So, any idea how to launch and manage ec2 instances meaning change instance type , size etc programmatically?
question
cdk
aws