0

Could anyone help me with this example of REST api “describe eucalyptus instances” in c# without using AWS sdk for .net? I give you my sample code. This code is running in aws successfully, but in eucalyptus they give a “404 not found” error.

    protected void Page_Load(object sender, EventArgs e)
    {
        EucaListInstance("xyx/services/Eucalyptus"); 
    }

    private void ListEucaInstance(string inboundQueueUrl)
    {

        // Create a request for the URL.        
        string date = System.DateTime.UtcNow.ToString("s");
        string stringToSign = string.Format("DescribeInstances" + date);
        string signature = CalculateEucaSignature(stringToSign, true);

        StringBuilder sb = new StringBuilder();
        sb.Append(inboundQueueUrl);
        sb.Append("?Action=DescribeInstances");
        sb.Append("&Version=2013-10-15");
        sb.AppendFormat("&AWSAccessKeyId={0}", m_EucaAccessKeyID);
        sb.AppendFormat("&Expires={0}", date);
        sb.AppendFormat("&Signature={0}", signature);

        HttpWebRequest request = (HttpWebRequest)WebRequest.Create(sb.ToString());
        HttpWebResponse response = null;
        Stream dataStream = null;
        StreamReader reader = null;

        try
        {
            request.Credentials = CredentialCache.DefaultCredentials;

            response = (HttpWebResponse)request.GetResponse();

            // Get the stream containing content returned by the server.
            dataStream = response.GetResponseStream();

            // Open the stream using a StreamReader for easy access.
            reader = new StreamReader(dataStream);

        }
        catch (Exception ex)
        {
            Console.WriteLine(ex.Message);
        }
        finally
        {
            // Cleanup the streams and the response.
            if (reader != null)
                reader.Close();

            if (dataStream != null)
                dataStream.Close();

            if (response != null)
                response.Close();
        }

    }

    private string CalculateEucaSignature(string data, bool urlEncode)
    {
        ASCIIEncoding ae = new ASCIIEncoding();
        HMACSHA1 signature = new HMACSHA1(ae.GetBytes(m_EucaSecretKey));
        string retSignature = Convert.ToBase64String(signature.ComputeHash(ae.GetBytes(data.ToCharArray())));
        return urlEncode ? HttpUtility.UrlEncode(retSignature) : retSignature;
    }
John Saunders
  • 160,644
  • 26
  • 247
  • 397

1 Answers1

1

You would get a 404 error if you are sending the request to the wrong URL. I would verify that you are sending to the correct URL, which would typically be along the lines of:

http://eucalyptus.your.domain.here.example.com:8773/services/Eucalyptus

You can find the URL to use in your deployment by looking in your eucarc file for the EC2_URL value, or by running the "euca-describe-services -T eucalyptus" admin command (in versions up to 4.0, for 4.0 onward you would use "-T compute")

sjones4
  • 146
  • 1
  • you need to form the URL first.. form a URL, try it in web browser.. if web browser gives correct response using that URL then create a web request in your code for that URL. then you can consume that API. – Naveen Katakam May 01 '14 at 07:38