private bool PopulateInstanceId()
{
// If we've already got this value, then
// just return true
if (!String.IsNullOrEmpty(_instanceId))
return true;
// Call to AWS to get the current EC2 instance ID
try
{
// Get the instance id
Uri uri = new Uri("http://169.254.169.254/latest/meta-data/instance-id");
var client = new System.Net.WebClient();
_instanceId = client.DownloadString(uri);
Info("Instance ID: {0}", _instanceId);
return true;
}
catch (Exception e)
{
Error("Error getting instance id: {0}", e.Message);
return false;
}
}