Speeding up the creation of AMI and ASG

using Ansible I create an AMI of an ubuntu instance and then using this AMI to create a launch configuration and then an update group and auto-scale, are there any shortcuts I can take to speed up the ASG and AMI steps, take 10mins +

+10
amazon-web-services amazon-ec2 autoscaling ami ansible
source share
2 answers

Use AMI with EBS instead of AMI with Instance Store. From AWS docs :

Amazon EBS-Backed Amazon Instance Store-Backed Boot time Usually less than 1 minute Usually less than 5 minutes 

- http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ComponentsAMIs.html#storage-for-the-root-device

+4
source share

I asked a similar question through an AWS support ticket, here was the answer:

The main process, which takes a lot of time to start a new EC2 instance, is the process of loading the OS in the instance: the presence of more or less security groups / network ACLs, a different number of SSH keys and the roles associated with the instance should not have the time required to start it. Most of the time it takes to start an instance is consumed by the OS itself.

With this in mind, let me consider some of the main points that can take the most time when an instance boots up - for all below, I will focus exclusively on Linux from the EC2 point of view:

  • The local file system mounts: if your instance needs to mount a large number of file systems, this will add a little time to process to process. Depending on the type of file system you are using, you may need to periodically check each fixed number of days - for example, on Linux you may need to run fsck on the ext4 file system every 90 days (this period may vary depending on your settings) and the OS automatically runs this check when the file system is mounted if it detects that the period has been exceeded. One strategy to prevent this may be to perform these checks before creating the AMI, which you will use to start new instances, so that any instances launched from this AMI will have their file system checked recently and you will not encounter unexpected fsck actions when starting instances in the first time. Depending on the type of file system you may possibly turn off these periodic checks altogether, but I would not recommend it because they are necessary to maintain the integrity of the file system over time.

  • The remote file system mounts: if your instance needs to connect any remote file system (for example, an EFS share or any regular NFS share), your download process may be delayed depending on the network connection to the server using this remote file system. In the worst case scenario, if the server using the file system is disconnected, your download process will be interrupted until this connection time ends. If you install remote file systems by default when starting your instances, make sure that the servers sharing them are accessible before starting your instances.

  • Common OS initialization scenarios: most of the time spent by the boot process will be executed when the OS starts. There are two types of models on Linux: the traditional SystemV init (which starts services in a sequential order, one after the other) and the relatively new system (which is able to run services in parallel and thus reduce boot time in some circumstances). Which one you will use will depend on the Linux distribution that you run in your instances. For example, if you need to start the database server, which can take a lot of time at each boot. For example, it would be advisable to consider systemd, as this will allow the rest of the unrelated services to be launched in parallel, since they do not have this database server conditions.

  • User data and cloud-init scripts: they are executed after completion of regular OS scripts. As in previous articles, you may need to verify that any of these user scripts that you run are optimized so that they can take a minimal amount of time; It is recommended that you test any custom user data scenarios individually to measure your time before adding them to a new instance launch, so that you can better understand their effect on the total instance launch time. If your scripts extract any files external to the instance (if you download something from the S3 bucket, start the automatic update of installed packages, etc.), the same considerations that I mentioned in the Remote File System element mentioned above - make sure there are no network problems that can slow down or prevent this connection, as this will add more time to the entire process of starting your instance.

  • Instance Type: The instance type affects the time required to complete the OS boot. Under the same circumstances, a t2.large instance will load faster than t2.nano, simply because it has more RAM, vCPU and more CPU credits - all this allows the OS to speed up the boot process. In addition, if you need to extract large amounts of data as part of the instance startup process, you can use advanced network mode and optimized EBS to provide maximum throughput for your needs; see the links at the end of this post for more information on this.

  • EBS Volume Type: As with the instance type, the performance of your EBS volumes is also a factor that can affect the overall instance startup time. If your instance needs to read large amounts of data during the boot process from volume sc1 (a low-capacity hard disk drive designed for readily available data), the boot process will be slower than if your instance reads the same data from a much higher PIOPS volume performance - if your use case contains a scenario in which you are affected by this, you may want to test different types of volumes to choose the one that best suits your needs. Similarly, the type of your instance root volume will also affect boot performance, as in all cases you will need to read information from it. In most cases, the default value is โ€œGeneral SSDโ€. aka gp2 EBS volumes are good enough, for example, root volumes.

Ultimately, the time taken to launch a new instance by running tests for your specific use case will be determined; General considerations, which I mentioned above, can help you reduce this time, but in order to determine which settings are best suited to your environment, you need to check and fine-tune each parameter until you reach the point where the startup time suits your needs.

I am attaching a couple of links at the end of this answer with more details about the elements that I mentioned in this answer.

I hope this information was useful to you. Please let me know if you have any questions.

Thanks,

Related links: - Types of EC2 instances: https://aws.amazon.com/ec2/instance-types/ - Types of EBS volumes: http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/EBSVolumeTypes. html - Optimized EBS instances: http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/EBSOptimized.html - Performance recommendations for EBS volumes: http://docs.aws.amazon.com/AWSEC2/latest /UserGuide/EBSPerformance.html - Improving Network Mode on Linux EC2 Instances: http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/enhanced-networking.html

+15
source share

All Articles