public List <string> GetDomains() { ListDomainsRequest ListDomainsAction = new ListDomainsRequest(); ListDomainsResponse response = Service.ListDomains(ListDomainsAction); return(response.ListDomainsResult.DomainName); }
/// <summary> /// Unmarshaller the response from the service to the response class. /// </summary> /// <param name="context"></param> /// <returns></returns> public override AmazonWebServiceResponse Unmarshall(JsonUnmarshallerContext context) { ListDomainsResponse response = new ListDomainsResponse(); context.Read(); int targetDepth = context.CurrentDepth; while (context.ReadAtDepth(targetDepth)) { if (context.TestExpression("Domains", targetDepth)) { var unmarshaller = new ListUnmarshaller <DomainDetails, DomainDetailsUnmarshaller>(DomainDetailsUnmarshaller.Instance); response.Domains = unmarshaller.Unmarshall(context); continue; } if (context.TestExpression("NextToken", targetDepth)) { var unmarshaller = StringUnmarshaller.Instance; response.NextToken = unmarshaller.Unmarshall(context); continue; } } return(response); }
public static void InvokeListDomains() { NameValueCollection appConfig = ConfigurationManager.AppSettings; // Print the number of Amazon SimpleDB domains. IAmazonSimpleDB sdb = AWSClientFactory.CreateAmazonSimpleDBClient(RegionEndpoint.USWest2); try { ListDomainsResponse sdbResponse = sdb.ListDomains(new ListDomainsRequest()); int numDomains = 0; numDomains = sdbResponse.DomainNames.Count; Console.WriteLine("You have " + numDomains + " Amazon SimpleDB domain(s)."); } catch (AmazonSimpleDBException ex) { if (ex.ErrorCode.Equals("AuthFailure")) { Console.WriteLine("Please check the provided AWS access credentials."); Console.WriteLine("If you haven't signed up for Amazon SimpleDB yet, you can sign up at http://aws.amazon.com/simpledb."); } else { Console.WriteLine("Caught Exception: " + ex.Message); Console.WriteLine("Response Status Code: " + ex.StatusCode); Console.WriteLine("Error Code: " + ex.ErrorCode); Console.WriteLine("Error Type: " + ex.ErrorType); Console.WriteLine("Request ID: " + ex.RequestId); } } Console.WriteLine(); }
/// <summary> /// Fetches the domain names and populates them to the domain list box. /// </summary> private void PopulateDomainNames() { SimpleDBResponseEventHandler <object, ResponseEventArgs> handler = null; handler = delegate(object sender, ResponseEventArgs args) { SimpleDB.Client.OnSimpleDBResponse -= handler; ListDomainsResponse response = args.Response as ListDomainsResponse; if (null != response) { ListDomainsResult listResult = response.ListDomainsResult; if (null != listResult) { this.Dispatcher.BeginInvoke(() => { this.DomainNameList.Clear(); listResult.DomainName.ForEach(domain => this.DomainNameList.Add(domain)); }); } } }; //Show a wait message. this.Dispatcher.BeginInvoke(() => { this.DomainNameList.Clear(); this.DomainNameList.Add("Please wait..."); }); SimpleDB.Client.OnSimpleDBResponse += handler; ListDomainsRequest request = new ListDomainsRequest(); SimpleDB.Client.BeginListDomains(request); }
private static void UnmarshallResult(XmlUnmarshallerContext context, ListDomainsResponse response) { int originalDepth = context.CurrentDepth; int targetDepth = originalDepth + 1; if (context.IsStartOfDocument) { targetDepth += 2; } while (context.ReadAtDepth(originalDepth)) { if (context.IsStartElement || context.IsAttribute) { if (context.TestExpression("DomainName", targetDepth)) { var unmarshaller = StringUnmarshaller.Instance; var item = unmarshaller.Unmarshall(context); response.DomainNames.Add(item); continue; } if (context.TestExpression("NextToken", targetDepth)) { var unmarshaller = StringUnmarshaller.Instance; response.NextToken = unmarshaller.Unmarshall(context); continue; } } } return; }
private async Task CreateDomain() { //Get the list of domains ListDomainsRequest listDomainRequest = new ListDomainsRequest() { RegistrationStatus = RegistrationStatus.REGISTERED }; ListDomainsResponse listDomainsResponse = await this.SwfClient.ListDomainsAsync(listDomainRequest); //Check if our domain exists if (listDomainsResponse.DomainInfos.Infos.Any(x => x.Name == this.SwfConfiguration.DomainName)) { return; } //If doesn't exist -> create RegisterDomainRequest registerDomainRequest = new RegisterDomainRequest() { Name = this.SwfConfiguration.DomainName, Description = this.SwfConfiguration.DomainDescription, WorkflowExecutionRetentionPeriodInDays = this.SwfConfiguration.WorkflowExecutionRetentionPeriodInDays }; await this.SwfClient.RegisterDomainAsync(registerDomainRequest); }
public static ListDomainsResponse Unmarshall(UnmarshallerContext _ctx) { ListDomainsResponse listDomainsResponse = new ListDomainsResponse(); listDomainsResponse.HttpResponse = _ctx.HttpResponse; listDomainsResponse.RequestId = _ctx.StringValue("ListDomains.RequestId"); listDomainsResponse.TotalCount = _ctx.LongValue("ListDomains.TotalCount"); listDomainsResponse.PageNumber = _ctx.LongValue("ListDomains.PageNumber"); listDomainsResponse.PageSize = _ctx.LongValue("ListDomains.PageSize"); List <ListDomainsResponse.ListDomains_DomainInfo> listDomainsResponse_domainInfos = new List <ListDomainsResponse.ListDomains_DomainInfo>(); for (int i = 0; i < _ctx.Length("ListDomains.DomainInfos.Length"); i++) { ListDomainsResponse.ListDomains_DomainInfo domainInfo = new ListDomainsResponse.ListDomains_DomainInfo(); domainInfo.DomainName = _ctx.StringValue("ListDomains.DomainInfos[" + i + "].DomainName"); domainInfo.Resolved = _ctx.LongValue("ListDomains.DomainInfos[" + i + "].Resolved"); domainInfo.ResolvedHttps = _ctx.LongValue("ListDomains.DomainInfos[" + i + "].ResolvedHttps"); domainInfo.Resolved6 = _ctx.LongValue("ListDomains.DomainInfos[" + i + "].Resolved6"); domainInfo.ResolvedHttps6 = _ctx.LongValue("ListDomains.DomainInfos[" + i + "].ResolvedHttps6"); listDomainsResponse_domainInfos.Add(domainInfo); } listDomainsResponse.DomainInfos = listDomainsResponse_domainInfos; return(listDomainsResponse); }
public override AmazonWebServiceResponse Unmarshall(XmlUnmarshallerContext context) { ListDomainsResponse response = new ListDomainsResponse(); context.Read(); int targetDepth = context.CurrentDepth; while (context.ReadAtDepth(targetDepth)) { if (context.IsStartElement) { if (context.TestExpression("ListDomainsResult", 2)) { UnmarshallResult(context, response); continue; } if (context.TestExpression("ResponseMetadata", 2)) { response.ResponseMetadata = ResponseMetadataUnmarshaller.Instance.Unmarshall(context); } } } return(response); }
public override void Invoke(AWSCredentials creds, RegionEndpoint region, int maxItems) { AmazonSageMakerConfig config = new AmazonSageMakerConfig(); config.RegionEndpoint = region; ConfigureClient(config); AmazonSageMakerClient client = new AmazonSageMakerClient(creds, config); ListDomainsResponse resp = new ListDomainsResponse(); do { ListDomainsRequest req = new ListDomainsRequest { NextToken = resp.NextToken , MaxResults = maxItems }; resp = client.ListDomains(req); CheckError(resp.HttpStatusCode, "200"); foreach (var obj in resp.Domains) { AddObject(obj); } }while (!string.IsNullOrEmpty(resp.NextToken)); }
public override AmazonWebServiceResponse Unmarshall(JsonUnmarshallerContext context) { ListDomainsResponse response = new ListDomainsResponse(); UnmarshallResult(context, response); return(response); }
/// <summary> /// Unmarshaller the response from the service to the response class. /// </summary> /// <param name="context"></param> /// <returns></returns> public override AmazonWebServiceResponse Unmarshall(JsonUnmarshallerContext context) { ListDomainsResponse response = new ListDomainsResponse(); response.DomainInfos = DomainInfosUnmarshaller.Instance.Unmarshall(context); return(response); }
public override AmazonWebServiceResponse Unmarshall(JsonUnmarshallerContext context) { ListDomainsResponse response = new ListDomainsResponse(); context.Read(); response.ListDomainsResult = ListDomainsResultUnmarshaller.GetInstance().Unmarshall(context); return(response); }
private void SetupAmazonSwfToReturn(params DomainInfo[] domainInfo) { var listDomainsResponse = new ListDomainsResponse(); listDomainsResponse.DomainInfos = new DomainInfos() { Infos = domainInfo.ToList() }; _amazonWorkflowClient.Setup(a => a.ListDomainsAsync(It.IsAny <ListDomainsRequest>(), It.IsAny <CancellationToken>())) .Returns(Task.FromResult(listDomainsResponse)); }
private void WriteSimpleDBInfo() { StringBuilder output = new StringBuilder(); ListDomainsRequest sdbRequest = new ListDomainsRequest(); ListDomainsResponse sdbResponse = sdb.ListDomains(sdbRequest); foreach (string domain in sdbResponse.DomainNames) { output.AppendFormat("<li>{0}</li>", domain); } this.sdbPlaceholder.Text = output.ToString(); }
public static bool DoesDomainExist(string domainName, IAmazonSimpleDB sdbClient) { ListDomainsRequest listDomainsRequest = new ListDomainsRequest(); ListDomainsResponse response = sdbClient.ListDomains(listDomainsRequest); if (response != null) { return(response.DomainNames.Contains(domainName)); } return(false); }
private async Task <bool> checkDomainExists(string domainName) { _logger.LogDebug($"Checking for domain {domainName}"); var client = GetClient(); ListDomainsRequest request = new ListDomainsRequest(); ListDomainsResponse response = await client.ListDomainsAsync(request); _logger.LogDebug(response.ToString()); return(response.DomainNames.Any(n => n == domainName)); }
public static void CheckForDomain(string domainName, IAmazonSimpleDB sdbClient) { VerifyKeys(); ListDomainsRequest listDomainsRequest = new ListDomainsRequest(); ListDomainsResponse listDomainsResponse = sdbClient.ListDomains(listDomainsRequest); if (!listDomainsResponse.DomainNames.Contains(domainName)) { CreateDomainRequest createDomainRequest = new CreateDomainRequest() { DomainName = domainName }; sdbClient.CreateDomain(createDomainRequest); } }
public static string GetSimpleDBDomainsOutput(RegionEndpoint rEndpoint) { StringBuilder sb = new StringBuilder(1024); using (StringWriter sr = new StringWriter(sb)) { IAmazonSimpleDB simpleDBClient = new AmazonSimpleDBClient(); try { ListDomainsResponse response = simpleDBClient.ListDomains(); int numDomains = 0; if (response.DomainNames != null && response.DomainNames.Count > 0) { numDomains = response.DomainNames.Count; } sr.WriteLine(string.Format("You have {0} Amazon SimpleDB domain(s) in the {1} region.", numDomains, rEndpoint.ToString())); sr.WriteLine(); sr.WriteLine(); //S3Bucket[] domains = response.DomainNames.ToArray(); //foreach ( bucket in buckets) //{ // sr.WriteLine("--- " + bucket.BucketName.PadRight(63) + " --- " + bucket.CreationDate); //} } 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); } } } return(sb.ToString()); }
public async Task <IEnumerable <string> > ListDomainsAsync() { var result = new List <string>(); ListDomainsResponse domains = null; do { domains = await _client.ListDomainsAsync(new ListDomainsRequest { MaxNumberOfDomains = 100, NextToken = domains?.NextToken }, CancellationToken.None); result.AddRange(domains.DomainNames); } while (!string.IsNullOrEmpty(domains.NextToken)); return(result); }
private async Task EnsureDomainCreated() { if (_domainExists) { return; } try { await _sync.WaitAsync(); if (_domainExists) { return; } ListDomainsResponse domains = null; do { domains = await _client.ListDomainsAsync(new ListDomainsRequest { MaxNumberOfDomains = 100, NextToken = domains?.NextToken }); foreach (var domain in domains.DomainNames) { if (domain == _domainName) { return; } } } while (!string.IsNullOrEmpty(domains.NextToken)); if (!_shouldCreateDomain) { throw new Exception($"Domain {_domainName} does not exist, and the configuration provided instructs not to create one"); } await _client.CreateDomainAsync(new CreateDomainRequest { DomainName = _domainName }); } finally { _sync.Release(); } }
private void AmazonWorkflowReturnsEmptyDomainInfo() { Action <ListDomainsRequest, CancellationToken> requestParameters = (r, c) => { Assert.That(r.MaximumPageSize, Is.EqualTo(0)); Assert.That(r.NextPageToken, Is.Null); Assert.That(r.ReverseOrder, Is.False); }; var emptyDomainResponse = new ListDomainsResponse(); emptyDomainResponse.DomainInfos = new DomainInfos() { Infos = new List <DomainInfo>() }; _amazonWorkflowClient.Setup(a => a.ListDomainsAsync(It.IsAny <ListDomainsRequest>(), It.IsAny <CancellationToken>())) .Returns(Task.FromResult(emptyDomainResponse)).Callback(requestParameters); }
public static bool CheckForDomains(string[] expectedDomains, AmazonSimpleDBClient sdbClient) { VerifyKeys(); ListDomainsRequest listDomainsRequest = new ListDomainsRequest(); ListDomainsResponse listDomainsResponse = sdbClient.ListDomains(listDomainsRequest); foreach (string expectedDomain in expectedDomains) { if (!listDomainsResponse.DomainNames.Contains(expectedDomain)) { // No point checking any more domains because // at least 1 domain doesn't exist return(false); } } // We got this far, indicating that all expectedDomains // were found in the domain list return(true); }
private static void UnmarshallResult(XmlUnmarshallerContext context, ListDomainsResponse response) { int originalDepth = context.CurrentDepth; int targetDepth = originalDepth + 1; if (context.IsStartOfDocument) { targetDepth += 2; } while (context.Read()) { if (context.IsStartElement || context.IsAttribute) { if (context.TestExpression("DomainName", targetDepth)) { response.DomainNames.Add(StringUnmarshaller.GetInstance().Unmarshall(context)); continue; } if (context.TestExpression("NextToken", targetDepth)) { response.NextToken = StringUnmarshaller.GetInstance().Unmarshall(context); continue; } } else if (context.IsEndElement && context.CurrentDepth < originalDepth) { return; } } return; }
void ListDomainWebResponse(object sender, ResponseEventArgs args) { ISimpleDBResponse result = args.Response; SimpleDB.Client.OnSimpleDBResponse -= ListDomainWebResponse; if (result is AmazonSimpleDBException) { this.Dispatcher.BeginInvoke(() => { this.ListDomainMessage = "Error: " + ((AmazonSimpleDBException)result).Message; }); return; } ListDomainsResponse response = (ListDomainsResponse)result; this.Dispatcher.BeginInvoke(() => { DomainNameList.Clear(); response.ListDomainsResult.DomainName.ForEach(b => DomainNameList.Add(b)); this.ListDomainMessage = "No of Domains: " + response.ListDomainsResult.DomainName.Count; }); }
static string GetServiceOutput() { var awsOptions = Configuration.GetAWSOptions(); var awsRegion = awsOptions.Region.SystemName; StringBuilder sb = new StringBuilder(1024); using (StringWriter sr = new StringWriter(sb)) { sr.WriteLine("==========================================="); sr.WriteLine("AWS SDK with DotNet Core 2.x -- Al Dass ([email protected])"); sr.WriteLine("==========================================="); // Print the number of Amazon EC2 instances. IAmazonEC2 ec2 = awsOptions.CreateServiceClient <IAmazonEC2>(); DescribeInstancesRequest ec2Request = new DescribeInstancesRequest(); try { DescribeInstancesResponse ec2Response = ec2.DescribeInstancesAsync(ec2Request).Result; int numInstances = 0; numInstances = ec2Response.Reservations.Count; sr.WriteLine($"You have {numInstances} Amazon EC2 instance(s) in the [{awsRegion}] region."); foreach (var r in ec2Response.Reservations) { foreach (var i in r.Instances) { sr.WriteLine("==========================================="); sr.WriteLine($" InstanceId: {i.InstanceId}"); sr.WriteLine($" VpcId: {i.VpcId}"); sr.WriteLine($" Current State: {i.State?.Name?.Value}"); sr.WriteLine($" Public DNS / [IP]: {i.PrivateDnsName} / [{i.PrivateIpAddress}]"); sr.WriteLine($"Private DNS / [IP]: {i.PublicDnsName} / [{i.PublicIpAddress}]"); sr.WriteLine($" Tags:"); foreach (var t in i.Tags) { sr.WriteLine($" {t.Key} : {t.Value}"); sr.WriteLine($" ==========================================="); } //if (i.State?.Name == InstanceStateName.Stopped) //{ // ec2.StartInstancesAsync(new StartInstancesRequest(new List<string> { i.InstanceId })); // var currState = string.Empty; // SpinWait.SpinUntil(() => { // Thread.Sleep(5 * 1000); // var dscInstRslt = ec2.DescribeInstancesAsync().Result; // var instCk = dscInstRslt.Reservations.FirstOrDefault(o => o.Instances.Any(o2 => o2.InstanceId == i.InstanceId))?.Instances.FirstOrDefault(o => o.InstanceId == i.InstanceId); // currState = instCk?.State?.Name; // //sr.WriteLine($"...start {i.InstanceId} - {currState}"); // return currState != InstanceStateName.Stopped; // }, 60 * 1000); //} if (i.State?.Name == InstanceStateName.Running) { ec2.StopInstancesAsync(new StopInstancesRequest(new List <string> { i.InstanceId })); var currState = string.Empty; SpinWait.SpinUntil(() => { Thread.Sleep(5 * 1000); var dscInstRslt = ec2.DescribeInstancesAsync().Result; var instCk = dscInstRslt.Reservations.FirstOrDefault(o => o.Instances.Any(o2 => o2.InstanceId == i.InstanceId))?.Instances.FirstOrDefault(o => o.InstanceId == i.InstanceId); currState = instCk?.State?.Name; //sr.WriteLine($"...stop {i.InstanceId} - {currState}"); return(currState != InstanceStateName.Running); }, 60 * 1000); } } } } 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(); // Print the number of Amazon SimpleDB domains. IAmazonSimpleDB sdb = awsOptions.CreateServiceClient <IAmazonSimpleDB>(); ListDomainsRequest sdbRequest = new ListDomainsRequest(); try { ListDomainsResponse sdbResponse = sdb?.ListDomainsAsync(sdbRequest).Result; sr.WriteLine($"You have {sdbResponse?.DomainNames?.Count} Amazon SimpleDB domain(s) in the [{awsRegion}] 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(); // Print the number of Amazon S3 Buckets. IAmazonS3 s3Client = awsOptions.CreateServiceClient <IAmazonS3>(); try { ListBucketsResponse response = s3Client.ListBucketsAsync().Result; int numBuckets = 0; if (response.Buckets != null && response.Buckets.Count > 0) { numBuckets = response.Buckets.Count; } sr.WriteLine($"You have {numBuckets} Amazon S3 bucket(s)."); } 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("Press any key to continue..."); } return(sb.ToString()); }
/// <summary> /// Maps to information. /// </summary> /// <param name="resp">The resp.</param> /// <returns>ListDomainsInfo.</returns> public static ListDomainsInfo MapToInfo(ListDomainsResponse resp) { var h = new ListDomainsMapperHelper(); return(h.MapToInfo(resp)); }
public async Task <string> GetServiceOutputAsync() { region = RegionEndpoint.USWest2; StringBuilder sb = new StringBuilder(1024); using (StringWriter sr = new StringWriter(sb)) { sr.WriteLine("==========================================="); sr.WriteLine("Welcome to the MAGIC HEALTH CHECK!"); sr.WriteLine("==========================================="); // Print the number of Amazon EC2 instances. IAmazonEC2 ec2 = new AmazonEC2Client(accessKeyId, secretAccessKey, region); Debug.WriteLine(ec2.Config.RegionEndpoint.ToString()); DescribeInstancesRequest ec2Request = new DescribeInstancesRequest(); try { DescribeInstancesResponse ec2Response = await ec2.DescribeInstancesAsync(ec2Request); int numInstances = 0; numInstances = ec2Response.Reservations.Count; sr.WriteLine(string.Format("You have {0} Amazon EC2 instance(s) running in the {1} region.", numInstances, "AWSRegion")); } 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(); // Print the number of Amazon SimpleDB domains. IAmazonSimpleDB sdb = new AmazonSimpleDBClient(accessKeyId, secretAccessKey, region); ListDomainsRequest sdbRequest = new ListDomainsRequest(); try { ListDomainsResponse sdbResponse = await sdb.ListDomainsAsync(sdbRequest); int numDomains = 0; numDomains = sdbResponse.DomainNames.Count; sr.WriteLine(string.Format("You have {0} Amazon SimpleDB domain(s) in the {1} region.", numDomains, "AWSRegion")); } 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(); // Print the number of Amazon S3 Buckets. s3Client = new AmazonS3Client(accessKeyId, secretAccessKey, region); try { ListBucketsResponse response = await s3Client.ListBucketsAsync(); int numBuckets = 0; if (response.Buckets != null && response.Buckets.Count > 0) { numBuckets = response.Buckets.Count; } sr.WriteLine("You have " + numBuckets + " Amazon S3 bucket(s)."); } 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); } } } return(sb.ToString()); }
private static void UnmarshallResult(JsonUnmarshallerContext context, ListDomainsResponse response) { response.DomainInfos = DomainInfosUnmarshaller.GetInstance().Unmarshall(context); return; }
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()); }