private bool PopulateRegion()
{
if (!String.IsNullOrEmpty(_regionName))
return true;
// Call to AWS to get the current availability zone
string availabilityZone;
try
{
// Get the instance id
Uri uri = new Uri("http://169.254.169.254/latest/meta-data/placement/availability-zone");
var client = new System.Net.WebClient();
availabilityZone = client.DownloadString(uri);
Info("Availability Zone: {0}", availabilityZone);
}
catch (Exception e)
{
Error("Error getting availability zone: {0}", e.Message);
return false;
}
// Assume that the region can be determined by stripping off the trailing a,b,c, etc.
// This is ok now, but perhaps not in the future.
_regionName = availabilityZone.Substring(0, availabilityZone.Length - 1);
Info("Region: {0}", _regionName);
return true;
}