Forem uses Fedora CoreOS to allow you save the OS Configuration state of your VM.
This is great at the OS level, but what happens if let us say a junior comes in mistaken terminates our instance. Will lose everything.
Also what happens if we wanted to run a second server in another multiple availability zones to ensure if one datacenter goes out that our app remains running?
This is where we want to take advantage of Amazon Linux Images (AMIs) Elastic Block Store (EBS) Snapshot and Launch Templates.
What is EBS?
EBS is virtual harddrive that is attached to your EC2 instance. This is where your app, your database and all your data resides.
We can create a snapshot of the EBS volume (which is stored in S3) and will be redundantly stored across multiple datacenters so its highly durable.
But we don't need to do this because when we create an Amazon Machine Image (AMI) it will also create an EBS snapshot
What is AMI?
AMI is a machine image of the OS configuration and and an EBS snapshot. When we have an AMI we can easily launch another virtual machine with the exact OS configuration and data. We will still have to configure our virtual networking like VPCs, Security Groups and etc.
Before we create our AMI lets first create a Launch Template that will store all our cloud networking configuration.
Creating a Launch Template
Lets create a Launch template from our running EC2 instance
Give your launch template a name and description
Observe that you have the current Instance Size and Type
Create your Launch Template
Creating an AMI
We have our Launch Template, but if we were to terminate our instance and launch a new EC2 server it would cloud our Forem installation or SSM agent we installed because it would just be the base image.
So we need to create a new AMI and then add a layer.
So go back to your EC2 instance and create an Image
When you create Images most Cloud Service Providers recommend you stop your instance before doing so, but I rarely do this in practice with AWS. On Azure they will make you stop the instance before hand.
Name your image and create. I find it best to put the ISO date in there followed by an incremental version when you are manually creating AMIs.
At the time of writing this article the default size of Forem uses to provision the EBS volume is 100 GB and that really big. EBS snapshots is a common hidden cost so if you are early days with your Forem Server here you can change the size down to 30 GB.
Navigate over to AMI in the left hand column and wait for the AMI to finish creating. It takes a few minutes.
Sometimes you need to hit the refresh button in the AWS Console.
Updating our Launch Template
Now that we have a new AMI we will go to our Launch Templates and create a new version
You can go ahead and search your AMI
If you resize your EBS volume size you may need to accept the prompt
Go ahead and create a new version
Launch a new VM
We can now launch ourselves a new VM to replace our old one. So launch a new instance from our Launch Template
Scroll to the bottom and Launch the template
Make your way over to EC2, just so we don't get confused between the old and new I am going to rename the Instance while its in the initializing state
While I wait for this new instance I am going to terminate the old one. This will cause downtime but I don't have anyone on my platform right now so its alright for me.
Best practice would be verifying the new server is working before terminating the old one.
I get a warning about termination because it will delete the old EBS volume.
Our new instance is running, we need to take the Public IP address and update our routes to point to the new server.
I use Route53 so I just updated my record with the new IP address
Considerations
Whenever you make changes, even though Fedora CoreOS will version OS configuration changes, you will want to periodically create AMIs and managed the versions in an EC2 Launch Template.
You will notice that there is risk of downtime because we have to swap out the IP Address. We can use a Elastic Load Balancer or an Elastic IP (static IP) to mitigate that issue.
Top comments (0)