Resources



Sample Code and Libraries

C# Library for Amazon EC2

Click for a printer friendly version of this document Printer Friendly Save to del.icio.us
Average Review:

C# Library for Amazon EC2

Submitted By: Elena@AWS  
AWS Products Used: Amazon EC2
Language(s): C#
License: Apache License 2.0

IMPORTANT: This library has been deprecated and will no longer be updated. We recommend developers switch to the new AWS SDK for .NET, which is almost identical to this library, where you’ll continue to get new feature updates and bug fixes. To learn more about the AWS SDK for .NET, and for support with migration, see http://aws.amazon.com/sdkfornet.

About this Library

  • Based on the 2009-08-15 API version.

What's New?

  • 2009-09-29:
    • Fix typo and response transformation on VpcAttachment
  • 2009-09-28:
  • 2009-09-23:
    • Support for Shared Snapshots API
  • 2009-09-10:
    • Fix for missing VPC fields on RunningInstance
  • 2009-08-25:
    • Support for VPC API
  • 2009-05-17:
    • Support for monitoring API
  • 2009-04-09:
    • Support for reserved instances API
  • 2008-12-26:
    • Support empty parameter values
  • 2008-12-23:
    • Fix for UTF8 url encoding for signature version 2
  • 2008-12-17:
    • Support for regions, signature version 2, https endpoint.
  • 2008-10-21:
    • Support for Windows Bundling, new API version - 2008-08-08
  • 2008-08-20:
    • Initial release, support for Amazon Elastic Block Store

Prerequisites

Package Content

Directory Overview
src Source distribution of the library. All sources including code samples that demonstrate the use of the library located under this directory.

Quick Start

Library comes with C# solution and two pre-configured C# projects.
  • Amazon.EC2.csproj - main library project
  • Amazon.EC2.Samples.csproj - library samples project
To get started with the library, follow these steps:
  1. Extract the amazon-ec2-2009-08-15-cs-library.zip file into a working directory.
  2. Open Amazon.EC2.sln solution file in Visual Studio 2005
  3. Hit F5 key and follow on screen instruction

Running Samples

Steps to run particular sample
  • Open AmazonEC2Samples.cs file under Amazon.EC2.Samples project
  • Set AWS Access Key ID and AWS Secret Access Key
  • String accessKeyId = "<Your Access Key ID>";
    String secretAccessKey = "<Your Secret Access Key>";
        


  • Set request parameters. For example, find following pre-generated snippet:
  • // DescribeImagesRequest request = new DescribeImagesRequest();
    // @TODO: set request parameters here
    // DescribeImagesSample.InvokeDescribeImages(service, request);
        


  • Uncomment first and third line and set ImageId of the image to describe
  • DescribeImagesRequest request = new DescribeImagesRequest();
    request.ImageId.Add("ami-be3adfd7");
    DescribeImagesSample.InvokeDescribeImages(service, request);
    
        

  • Hit F5 to run sample. You should see the output similar to the following:


  •     DescribeImagesResponse
            DescribeImagesResult
                Image
                    ImageId
                        ami-be3adfd7
                    ImageLocation
                        ec2-public-images/fedora-8-i386-base-v1.04.manifest.xml
                    ImageState
                        available
                    KernelId
                        aki-4438dd2d
                    RamdiskId
                        ari-4538dd2c
                    ...
        


    Note, to return all images, simply omit specifying ImageId parameter.

  • Experiment with other samples, examine samples sources. When ready, add library project to your solution, and use it.

Happy coding!

Comments, Questions or Feedback

If you have any comments, questions or feedback on the library, please start discussion here.

Discussion

The 5 most recent discussion messages. View full discussion.

tommihol
Posts: 3
Registered: 10/12/09
Re: C# Library for Amazon EC2
Posted: Oct 12, 2009 2:35 AM PDT   in response to: pawanbali
 
  Click to reply to this thread Reply

Hello,

  I`m trying to run the DescribeInstances example. I have one instance running but I can`t get any results by running the example. The requestId is there. If I request e.g. on of my AMI´s the result is correct. I`ve tried to search around but I`m stuck. Can anyone tell me what might be wrong?


byzero
Posts: 3
Registered: 8/12/09
Re: C# Library for Amazon EC2
Posted: Oct 12, 2009 6:42 AM PDT   in response to: tommihol
 
  Click to reply to this thread Reply

Hello - I'm not running the example as published, but this worked for me:

AmazonEC2 service = Service();
GetConsoleOutputRequest request = new GetConsoleOutputRequest ();

request.InstanceId = "youridinstanceid" ;

GetConsoleOutputResponse response = service.GetConsoleOutput(request);


anybody have code to decrypt the response string?



byzero
Posts: 3
Registered: 8/12/09
Re: C# Library for Amazon EC2
Posted: Oct 12, 2009 11:19 AM PDT   in response to: byzero
 
  Click to reply to this thread Reply

Regarding decoding the console output, there's a simple answer here: http://developer.amazonwebservices.com/connect/message.jspa?messageID=126285

public static string Decode(string str)
        {
            byte[] decbuff = Convert.FromBase64String(str);
            return System.Text.Encoding.UTF8.GetString(decbuff);
        }

Forgive me if this is already covered, or existing somewher in the sample code.

tommihol
Posts: 3
Registered: 10/12/09
Re: C# Library for Amazon EC2
Posted: Oct 13, 2009 2:50 AM PDT   in response to: byzero
 
  Click to reply to this thread Reply

In my use case I don`t know the instance id`s. I`m writing a web client for managing instances.



tommihol
Posts: 3
Registered: 10/12/09
Re: C# Library for Amazon EC2
Posted: Oct 13, 2009 3:58 AM PDT   in response to: tommihol
 
  Click to reply to this thread Reply

Got it working. I had to give service URL to spesific zone and start using the config when initiating the service.



Reviews
Create Review Write a Review

Perfect Code , yet One Problem so far.., Oct 27, 2008 3:38 PM
Reviewer: george gergues
Thank you for sharing this code, I have been working on a similar one myself, and there was no way I would have done it that detailed and complete. One Problem compiling the libary though , I waned to share with the community of users . C# is case sensitive , on the file , You will need to add those 2 lines at the beaning with the includes using Amazon.EC2.Util; using Amazon.EC2.Mock; Also there is a typo at the middle around if (!s3.isSetUploadPolicy()) You will need to change that with if (!s3.IsSetUploadPolicy()) now you can have real Happy Coding :) sure compiled fine. Thanks -George Gergues-
Welcome, Guest Help
Login Login