Reputation: 1674
I inherited the following AWS .NET SDK code from 2012 and I can't find a number of types in the SDK. I added the nuget packages Amazon, AWSSDK.Core, Amazon.EC2, Amazon.SimpleDB and Amazon.S3.
using Amazon.EC2;
using Amazon.EC2.Model;
using Amazon.SimpleDB;
using Amazon.SimpleDB.Model;
using Amazon.S3;
using Amazon.S3.Model;
public static string GetServiceOutput()
{
StringBuilder sb = new StringBuilder(1024);
using (StringWriter sr = new StringWriter(sb))
{
sr.WriteLine("===========================================");
sr.WriteLine("Welcome to the AWS .NET SDK!");
sr.WriteLine("===========================================");
// Print the number of Amazon EC2 instances.
AmazonEC2 ec2 = AWSClientFactory.CreateAmazonEC2Client();
DescribeInstancesRequest ec2Request = new DescribeInstancesRequest();
try
{
DescribeInstancesResponse ec2Response = ec2.DescribeInstances(ec2Request);
int numInstances = 0;
numInstances = ec2Response.DescribeInstancesResult.Reservation.Count;
sr.WriteLine("You have " + numInstances + " Amazon EC2 instance(s) running in the US-East (Northern Virginia) region.");
}
catch (AmazonEC2Exception ex)
{
if (ex.ErrorCode != null && ex.ErrorCode.Equals("AuthFailure"))
{
sr.WriteLine("The account you are using is not signed up for Amazon EC2.");
sr.WriteLine("You can sign up for Amazon EC2 at http://aws.amazon.com/ec2");
}
else
{
sr.WriteLine("Caught Exception: " + ex.Message);
sr.WriteLine("Response Status Code: " + ex.StatusCode);
sr.WriteLine("Error Code: " + ex.ErrorCode);
sr.WriteLine("Error Type: " + ex.ErrorType);
sr.WriteLine("Request ID: " + ex.RequestId);
sr.WriteLine("XML: " + ex.XML);
}
}
sr.WriteLine();
// Print the number of Amazon SimpleDB domains.
AmazonSimpleDB sdb = AWSClientFactory.CreateAmazonSimpleDBClient();
ListDomainsRequest sdbRequest = new ListDomainsRequest();
try
{
ListDomainsResponse sdbResponse = sdb.ListDomains(sdbRequest);
if (sdbResponse.IsSetListDomainsResult())
{
int numDomains = 0;
numDomains = sdbResponse.ListDomainsResult.DomainName.Count;
sr.WriteLine("You have " + numDomains + " Amazon SimpleDB domain(s) in the US-East (Northern Virginia) region.");
}
}
catch (AmazonSimpleDBException ex)
{
if (ex.ErrorCode != null && ex.ErrorCode.Equals("AuthFailure"))
{
sr.WriteLine("The account you are using is not signed up for Amazon SimpleDB.");
sr.WriteLine("You can sign up for Amazon SimpleDB at http://aws.amazon.com/simpledb");
}
else
{
sr.WriteLine("Caught Exception: " + ex.Message);
sr.WriteLine("Response Status Code: " + ex.StatusCode);
sr.WriteLine("Error Code: " + ex.ErrorCode);
sr.WriteLine("Error Type: " + ex.ErrorType);
sr.WriteLine("Request ID: " + ex.RequestId);
sr.WriteLine("XML: " + ex.XML);
}
}
sr.WriteLine();
// Print the number of Amazon S3 Buckets.
AmazonS3 s3Client = AWSClientFactory.CreateAmazonS3Client();
try
{
ListBucketsResponse response = s3Client.ListBuckets();
int numBuckets = 0;
if (response.Buckets != null &&
response.Buckets.Count > 0)
{
numBuckets = response.Buckets.Count;
}
sr.WriteLine("You have " + numBuckets + " Amazon S3 bucket(s) in the US Standard region.");
}
catch (AmazonS3Exception ex)
{
if (ex.ErrorCode != null && (ex.ErrorCode.Equals("InvalidAccessKeyId") ||
ex.ErrorCode.Equals("InvalidSecurity")))
{
sr.WriteLine("Please check the provided AWS Credentials.");
sr.WriteLine("If you haven't signed up for Amazon S3, please visit http://aws.amazon.com/s3");
}
else
{
sr.WriteLine("Caught Exception: " + ex.Message);
sr.WriteLine("Response Status Code: " + ex.StatusCode);
sr.WriteLine("Error Code: " + ex.ErrorCode);
sr.WriteLine("Request ID: " + ex.RequestId);
sr.WriteLine("XML: " + ex.XML);
}
}
sr.WriteLine("Press any key to continue...");
}
return sb.ToString();
}
}
It says it that these types don't exist: AmazonEC2, AWSClientFactory, DescribeInstancesResult, ex.StatusCode, AmazonSimpleDB. ListDomainsResult, IsSetListDomainsResult, AmazonS3. I have done lots of google searches but the documentation is bad. I don't know if these types do not exist anymore or what further AWS nuget packages I can use? Please help
Upvotes: 0
Views: 807
Reputation: 3177
Code from 2012 would be using the old monolithic SDK where all of the services were on one assembly/nuget package and we only had a couple dozen services. Now a days with the 100+ services the SDK is a separate package for each service plus the core package AWSSDK.Core
.
For you you would need to add the NuGet package AWSSDK.EC2, AWSSDK.S3 and AWSSDK.SimpleDB.
Also the AWSClientFactory class no longer exist because it didn't work in the module version of the SDK. Just replace all calls to AWSClientFactory with the service client constructor i.e. new AmazonEC2()
Upvotes: 1