Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Really slow AMI launches

There is a huge variance in the launch times of Windows AMIs (EBS-backed) that I am using. Some start up in just 3 minutes. Others can take 20+ minutes. My understanding is that the default Windows AMIs can be slow as they require two reboots to get active, but in my case these are all customized machines, either public or snapshots I have created.


On a similar note, I was retrieving the log files in the EC2 console to know when my machine is started. However, some of the machines DO NOT seem to generate any logs?? So, realistically, I have a variable startup time and variable logging, in which case how can I even really tell that a Windows machine has become avialable?

like image 831
Johnny Smire Avatar asked Feb 02 '11 03:02

Johnny Smire


1 Answers

It does take a varying amount of time to launch a Windows AMI in EC2. You can minimize it, a bit, by setting a fixed machine name for the instance. Do this as you would on any Windows computer - in the properties of "My Computer", "Computer Name" tab. Then, run "EC2ConfigService Settings" from the Start Menu's "All Programs" list. That program is installed there by Amazon on most base AMIs. In that program, on the "General" tab, UnCheck "Set Computer Name". This eliminates the system from re-booting itself once while starting up the image, as it would have to, in order to set the name.

Still, you would like to be notified when your instance is ready! This is a perfect job for Amazon's Simple Notification Service. The service (also known as SNS) is simple to use programmatically (from a windows .NET project for example), free (for the first 100,000 messages, less than 1gb in total), and the notifications are immediate.

Code to send a notification (in VB.NET):

    Imports Amazon.EC2.AmazonEC2Client  
    Imports Amazon.SimpleNotificationService  
    DIM LabSNS As New AmazonSimpleNotificationServiceClient(Lab_AWSKey, Lab_AWSSecretKey)  
    Dim PubReq As New Amazon.SimpleNotificationService.Model.PublishRequest  
    Dim Msg As String 'Messege to be built up, then be sent.  It is body of eMail.  
    Msg = "The instance is running and ready!"  
    Msg = Msg + vbCrLf + "Previous State of machine was:" & PreviousState 'A made-up global  
    Msg = Msg + [Any other info. I want to send myself about the start of the instance.]  
    PubReq.WithTopicArn(Topic)'Topic is a global. It's value is a key from SNS topic setup.  
    PubReq.WithSubject("EC2 Instance is Ready!")  
    PubReq.WithMessage(Msg)  
    LabSNS.Publish(PubReq)  

The code requires Amazon's SDK for .NET which is free. Write a program including some code like the above. Set the program to run after the computer starts, and before login, using the Windows Task Scheduler - create a task triggered "at system startup" that calls the program.

The setup for SNS is documented here:SNS Documentation

It looks like a lot of trouble to send eMail, however, Amazon's EC2 environment is highly restrictive when it comes to sending eMail. Many have tried to use EC2 as a spam platform, so Amazon has been thorough in blocking SMTP (eMail) traffic, except as prescribed by Amazon. You can't just open up a port on the Amazon security group to bypass Amazon's blocks.

Amazon does have a general eMail facility one can use from within EC2. It is called, Amazon Simple Email Service (SES). That will not work well for you, as it is designed for bulk eMail. So, SES's pricing, exception handling and messaging won't fit well with what you need, I don't think.

SNS, on the other hand works great for this. It includes an initial eMail to the recipients (you, and perhaps others you may want to notify of your server coming on-line) asking if they want to receive future messages of the topic; they are given an option to opt out, and must reply to receive further.

The setup process (shown in blocks above) is all easily doable from Amazon's AWS Management Console. (Your question implies you that you already have an AWS EC2 account needed for this.) Once setup, any instance launched from the AMI would send out an eMail containing any information (available to your program) of your choosing as soon as the machine is ready.

It'll be gotcha-free in setting up, and solid as a rock in operation.

like image 186
John Langstaff Avatar answered Oct 15 '22 20:10

John Langstaff