AWS EC2 Windows Instance – Get instance details

When provisioning an AWS EC2 fleet either manually or via a launch configuration it is very useful to be able to determine if the instance(s) are both operational and the Elastic load balancer is correctly redirecting HTTP requests and spreading the load evenly amongst the active EC2 instances.

The best way to achieve this is to have the instance “self provision” the functionality via userdata or via a launch configuration that can be injected when the instance is created. This code can be stored in an S3 bucket and copied to the instance on start-up.

PowerShell handles the automation process for you via UserData or by a launch configuration and does the following:

1) Install-WindowsFeature etc… – Installs IIS and all subcomponents. This can take some time – approx. 5 minutes per instance.

2) wget https://<bucketname>.s3.amazonaws.com/aspxless.zip -outfile c:\inetpub\wwwroot\aspxless.zip – Gets the zipped code from the S3 bucket and copies it locally to the /inetpub folder within the EC2 instance.

3) [System.Reflection.Assembly]::LoadWithPartialName(‘System.IO.Compression.FileSystem’)
[System.IO.Compression.ZipFile]::ExtractToDirectory(“c:\inetpub\wwwroot\aspxless.zip”, “c:\inetpub\wwwroot\aspxless”) – Unzips the code into a separate folder and makes it ready for use under the \wwwroot\aspxless folder.

Note: Make sure that the S3 bucket where the zip file is stored has the “Action s3:GetObject” set otherwise you will get a permission denied error. You can secure this via an IAM role (Highly recommended) for better security but for the purposes of the demo the “*” permission will suffice.

The code within the default.aspx page queries the instance metadata and returns the following:

  1. InstanceID
  2. Public Host Name
  3. Public IP
  4. Instance Type
  5. Availability Zone

You would then query the instance data by the following url: http://<ELB_End_Point_Or_PublicIP>/aspxless/default.aspx

The complete code for the walkthrough above can be found from here: https://github.com/AaronSaikovski/AWS_Less

Advertisements

About Aaron Saikovski

Aaron Saikovski is a Microsoft certified technology specialist, consultant, developer, trainer and cloud solution architect with over 20+ years commercial information technology experience. He has consulted and worked with an incredibly diverse number of both local and international clients across the banking and financial services, utilities, oil and mining, telecommunications, logistics, construction/property, pharmaceutical, transport/airline and FMCG sectors. He has also consulted on a variety of projects to both Federal and State governments in high-profile portfolios such as Prime Minister and Cabinet, Department of Defence, Taxation Office, Department of Education and Training, Department of Employment & Workplace Relations and the Department of Health. Aaron’s skills revolve around the Microsoft platform stack with a core skillset based on the SharePoint platform. He has been involved in some of the largest SharePoint deployments in the world and was a member of the Global SharePoint Ranger team within Microsoft Corporation and was actively involved with the SharePoint Customer Advisory Team (SPCAT) to provide guidance and best practices to the largest Microsoft enterprise global customers. He was also an active MSDN article reviewer and contributor during his time at Microsoft. He has very broad and deep experience with architecting, developing and deploying complex customer solutions leveraging the Microsoft Office365 and Azure cloud platforms. Some of the key cloud customers he has been involved with are Qantas, Caltex, and Fujitsu/Westpac to name a few. He assists customers with their journey to the cloud and provides guidance and best practices to assist in identifying workloads that are suitable candidates to be migrated or redeveloped. These include IaaS, SaaS and PaaS solutions that solve a particular business requirement while providing the best technical outcome for the customer. Aaron is a regular presenter at such events as SharePoint Saturday (http://www.spsevents.org), Microsoft TechEd and is a regular presenter at user groups and conferences. He presents on a wide and varied range of topics that encompass the complete end to end Microsoft solution stack such as Windows 8 App development through to deploying Azure IaaS solutions with PowerShell. Aaron has an active social media profile. He was the founding member of OzMoss (http://www.codify.com/lists/OzMOSS), a very active and prominent online SharePoint community and he can be followed on Twitter at @RuskyDuck72. He blogs regularly at https://aaronsaikovski.wordpress.com/ Aaron is also an active affiliate member of the Institute of Electrical and Electronics Engineers (www.ieee.org) Outside of work Aaron is a very active volunteer for DoggieRescue (www.doggierescue.com) where he volunteers his time to maintain and improve their IT systems to keep them running as optimally and efficiently as possible. ** OPINIONS EXPRESSED ARE MY OWN VIEWS AND NOT THOSE OF MY EMPLOYER **
This entry was posted in Amazon Web Services, AWS, EC2. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s