我从2012年继承了以下AWS .NET SDK代码,但在SDK中找不到许多类型。我添加了nuget包Amazon,AWSSDK.Core,Amazon.EC2,Amazon.SimpleDB和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();
}
}
它说这些类型不存在:AmazonEC2,AWSClientFactory,DescribeInstancesResult,例如状态代码,AmazonSimpleDB。 ListDomainsResult,IsSetListDomainsResult,AmazonS3。我已经做了很多Google搜索,但是文档很糟糕。我不知道这些类型是否不再存在,或者我可以使用哪些进一步的AWS nuget包?请帮助
答案 0 :(得分:1)
2012年的代码将使用旧的整体式SDK,其中所有服务都位于一个程序集/裸程序包中,而我们只有几十个服务。现在,使用100多种服务的SDK已经成为每个服务的单独软件包以及核心软件包for X = 1 to 100
cat logX.txt | grep -e string1 -e string2 | rm logX.txt
。
对于您来说,您需要添加NuGet包AWSSDK.EC2,AWSSDK.S3和AWSSDK.SimpleDB。
AWSClientFactory类也不再存在,因为它在SDK的模块版本中不起作用。只需将所有对AWSClientFactory的调用替换为服务客户端构造函数,即AWSSDK.Core