April 7

ASP.Net and the Elastic Compute Cloud example

Posted by Dave
Filed under ASP.Net, EC2, Render Manager | No Comments

For a project that I am currently working on I have a requirement to use the Amazon Elastic Compute Cloud. I have had some difficulty finding resources explaining how to interact with the cloud via ASP.Net. I have tried two methods to get something basic up and running with success coming after a long night with the Red Bull. The methods I have tried are:

  1. Web Resource
  2. Third Party Libary

Web Resource

This option was the one that I thought I would get going in a few minutes and be creating servers in the cloud before you could say “describe instances”. However I was mistaken, I set up the web reference as I have done 100’s of times than started to use the proxy in order to start a security group in the cloud. First problem!!!! I could not find how to identify myself to EC2 I am sure you have to use the access keys somewhere or the security certificate. After several hours of head scratching I moved on.

Third Party Library

I found the C# wrapper for ASP.Net which proved to be much easier to set up and use. Included the Amazon.EC2 project in my solution and wrote the code that created a security group and opened external ports. Soo much easyer than trying to get to grips with the SOAP interface.

Code

Whoops nearly forgot to include the code!!

AmazonEC2 ec2 = new AmazonEC2Client(awsKey, seceret);

//create a security group
CreateSecurityGroupRequest request = new CreateSecurityGroupRequest();
request.GroupName = groupName;
request.GroupDescription = "Group Created for user 1";

CreateSecurityGroupResponse secg = ec2.CreateSecurityGroup(request);
string reqid = secg.ResponseMetadata.RequestId;

AuthorizeSecurityGroupIngressRequest ingressrequest = new AuthorizeSecurityGroupIngressRequest();
ingressrequest.FromPort = Convert.ToDecimal(80);
ingressrequest.ToPort = Convert.ToDecimal(80);
ingressrequest.IpProtocol = "tcp";
ingressrequest.CidrIp = "0.0.0.0/0";
ingressrequest.GroupName = groupName;

AuthorizeSecurityGroupIngressResponse inreag = c2.AuthorizeSecurityGroupIngress(ingressrequest);

string inreqid = inreag.ResponseMetadata.RequestId;

ingressrequest = new AuthorizeSecurityGroupIngressRequest();
ingressrequest.FromPort = Convert.ToDecimal(3389);
ingressrequest.ToPort = Convert.ToDecimal(3389);
ingressrequest.IpProtocol = "tcp";
ingressrequest.CidrIp = "0.0.0.0/0";
ingressrequest.GroupName = groupName;
inreag = ec2.AuthorizeSecurityGroupIngress(ingressrequest);

inreqid = inreag.ResponseMetadata.RequestId;

Conclusion

It has taken me hours of head scratching to get this far, due to the lack of decent examples for .Net developers, I feel that I am on the right track now I will keep you Informed of any more issues that I have in this interesting and frustrating journey.

I hope this post helps someone to get started with EC2 quicker than I did and feel free to share this post via the social bookmark sights below. Any constructive comments welcomed on this article content and structure.

Popularity: unranked [?]

Share this post
  • Twitter
  • Digg
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • Diigo
  • LinkedIn
  • Reddit
  • Technorati

Other Stuff You Might Like

This entry was posted on Tuesday, April 7th, 2009 at 22:35 and is filed under ASP.Net, EC2, Render Manager. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

Leave a Reply