AWS Autoscaling, Launch new instance with current version of AMI - amazon-web-services

In autoscaling group I have four machines. I have modified or added few changes on the instance and took IMAGE/AMI. If load increase autoscaling will add new instances. Now, I want new launched instances with latest AMI. Is this possible?

Your AMI is associated at the Launch Configuration level. You have to update your Launch Configuration to point out to the new AMI you created. Then you associate your new LC with your AutoScalingGroup.

Related

AMI change for EC2 instance is not working

In my workplace, we have a process of changing the EC2's AMI every month with the new patched private AMI.
Our internal operations team makes these patched AMI available for us as private AMI for EC2.
In our terraform script, we change the name of the AMI to the new one before executing the script via Jenkins.
However, we have noticed that after the script is executed EC2 instance is not affected by the AMI name change, we have to manually terminate each EC2 instance for the AMI change to take effect.
What I want to know is-
Is this a problem someone has faced before?
Is there a way to remove the manual termination of instance in Terraform OR is there a way in Terraform by which the changes will be taken cared of automatically?
The instances in ASG are not being updated with the new AMI because by default, only your launch configuration (LC) or launch template (LT) are updated with the new AMI. This does not automatically causes an update of the instances to use the new LC/LT.
However, since not too long ago, AWS has introduce instance refresh to combat this specific issue. Subsequently, this functionality was added to terraform and is configured using instance_refresh block of aws_autoscaling_group resource.
Thus, you could setup instance_refresh in your aws_autoscaling_group and specify what triggers it. Usually the trigger would be changes to the associated launch_configuration or launch_template.

How to take latest AMI always while scaling ASG?

I am using ASG for my application and I am attaching running instance to create ASG
Now the main problem is, Whenever new instance via ASG gets created it does not replicate the EC2 Instance attached to it so I cannot take updated or point in time binaries available on that running instance.
I get a fresh blank AMI to work which won't work for me.
Is there any way that I can replicate or I can use the attached instance as a base image in ASG while scaling out

AWS - Different instance Type of AMI then Instance launched using Auto Scaling Group

I have the following flow for Patch update of web app code in AWS
1) An m4.xlarge instance (Patch Instance) in which development team update code at the particular interval.
2) I, then create an AMI and Launch Configuration using that instance.
3) Using newly created Launch Configuration, I update Autoscaling Group to add the new instance(m4.xlarge) with latest AMI.
Now the questions I have are:
1) Can I make my Patch Instance of t2.micro type and make Autoscaling create the new instance with m4.xlarge? This is just for optimization as Patch Instance is underutilized.
2) Any better way for the patch update?
Yes, you can make an AMI of any instance type and use it on a bigger or smaller one.
Could you collaborate on what the Development team is patching?

AWS auto scaling : could not create exact replica of instance

I created a t2.micro EC2 instance and configured node.js on it. That is running fine.
Next I tried to create an Auto Scaling group with this instance that creates a Launch Configuration then Auto Scaling group with Launch Configuaration also created successfully.
The problem is that when Auto Scaling works, the new instance created is not the exact replica (image) of the old instance. It does not copy my node.js configuaration and the data files.
Where I am going wrong and how achieve this requirement on AWS?
When Auto Scaling launches a new Amazon EC2 instance, it uses the Amazon Machine Image (AMI) specified in the Launch Configuration. The new instance will have the exact same contents as the AMI.
It sounds like you are either using a standard Amazon-issued AMI, or you created your own AMI before you configured your instance. Any configurations done after the AMI creation will not carry across to new instances because it is not part of the AMI.
You should:
Launch an instance and configure it how you wish
Create an AMI (Actions / Image / Create Image)
Create a Launch Configuration that uses that AMI
Edit your Auto Scaling group to use that Launch Configuration
Any new instances launched by Auto Scaling will use the new AMI, which will have all your configurations.
An alternate to create a custom AMI is to use a User Data Script that will automatically run when a new instance starts. This script can download software, change settings and generally personalize the instance. This could be easier to update rather than having to create new AMIs when you want to change something. The User Data script can be entered into the Launch Configuration, which will be used by Auto Scaling when launching new instances.

aws - upgrade autoscale base AMI

I have setup a HA architecture using Autoscaling, load balancer , code deploy.
I have a base-image through which autoscale launch any new instance. This base-image will get outdated with time and I may have to upgrade it.
My confusion is how can I provision this base AMI to install desire version of packages ? and How will I provision the already in-service instances ?
For-example - Currently my base AMI have php5.3 but if in future I need PHP5.5 then how can I provision in-service fleet of EC2 instances and as well as base AMI
I have Chef as provisioning server. So how should I proceed for above problem ?
The AMI that an instance uses is determined through the launch configuration when the instance boots. Therefore, the only way to change the AMI of an instance is to terminate it and launch it again.
In an autoscaling scenario, this is relatively easy: update the launch configuration of the autoscaling group to use the new AMI and terminate all instances you want to upgrade. You can do a rolling upgrade by terminating the instances one-by-one.
When your autoscaling group scales up and down frequently and it's OK for you to have multiple versions of the AMI in your autoscaling group, you can just update the launch configuration and wait. Every time the autoscaling process kicks in and a new instance is launched, the new AMI is used. When the autoscaling group has the right 'termination policy' ("OldestInstance", for example), every time the autoscaling process scales down, an instance running the old AMI will be terminated.
So, let's say your have 4 instances running. You update the launch config to use a new AMI. After 4 scale-up actions and 4 scale-down actions, all instances are running the new AMI.
Autoscale has a feature called Launch Configuration, which includes the ability to pass in userdata, which will get executed at launch time. The userdata can be saved within Launch Configuration so that you can automate the process.
I have never worked with Chef and I'm sure there is a Chef-centric way of doing this, but the quick and dirty would be to use userdata.
Your userdata script (i.e. BASH) would then include the necessary sudo apt-get remove / install commands (assuming Ubuntu OS).
The documentation for this is here:
http://docs.aws.amazon.com/AutoScaling/latest/APIReference/API_CreateLaunchConfiguration.html
UserData The user data to make available to the launched EC2
instances. For more information, see Instance Metadata and User Data
in the Amazon Elastic Compute Cloud User Guide.
At this time, launch configurations don't support compressed (zipped)
user data files.
Type: String
Length constraints: Minimum length of 0. Maximum length of 21847.
Pattern: [\u0020-\uD7FF\uE000-\uFFFD\uD800\uDC00-\uDBFF\uDFFF\r\n\t]*
Required: No