Exemple #1
0
        async IAsyncEnumerable <DescribeAutoScalingGroupsResponse> IPaginator <DescribeAutoScalingGroupsResponse> .PaginateAsync(CancellationToken cancellationToken = default)
        {
            if (Interlocked.Exchange(ref _isPaginatorInUse, 1) != 0)
            {
                throw new System.InvalidOperationException("Paginator has already been consumed and cannot be reused. Please create a new instance.");
            }
            var nextToken = _request.NextToken;
            DescribeAutoScalingGroupsResponse response;

            do
            {
                _request.NextToken = nextToken;
                response           = await _client.DescribeAutoScalingGroupsAsync(_request, cancellationToken).ConfigureAwait(false);

                nextToken = response.NextToken;
                cancellationToken.ThrowIfCancellationRequested();
                yield return(response);
            }while (nextToken != null);
        }
        protected override async Task<IEnumerable<AutoScalingGroup>> FetchResources()
        {
            var results = new List<IEnumerable<AutoScalingGroup>>();
            string marker = null;

            do
            {
                var response = await _client.DescribeAutoScalingGroupsAsync(
                    new DescribeAutoScalingGroupsRequest
                    {
                        NextToken = marker
                    });

                results.Add(response.AutoScalingGroups);
                marker = response.NextToken;
            }
            while (!string.IsNullOrEmpty(marker));

            return results.SelectMany(x => x).ToList();
        }
Exemple #3
0
 private Amazon.AutoScaling.Model.DescribeAutoScalingGroupsResponse CallAWSServiceOperation(IAmazonAutoScaling client, Amazon.AutoScaling.Model.DescribeAutoScalingGroupsRequest request)
 {
     Utils.Common.WriteVerboseEndpointMessage(this, client.Config, "AWS Auto Scaling", "DescribeAutoScalingGroups");
     try
     {
         #if DESKTOP
         return(client.DescribeAutoScalingGroups(request));
         #elif CORECLR
         return(client.DescribeAutoScalingGroupsAsync(request).GetAwaiter().GetResult());
         #else
                 #error "Unknown build edition"
         #endif
     }
     catch (AmazonServiceException exc)
     {
         var webException = exc.InnerException as System.Net.WebException;
         if (webException != null)
         {
             throw new Exception(Utils.Common.FormatNameResolutionFailureMessage(client.Config, webException.Message), webException);
         }
         throw;
     }
 }
        public virtual async Task Failover()
        {
            try
            {
                Console.WriteLine($"Simulating AZ failure for {azName}");

                // Find all subnets in the availability zone passed in the input
                DescribeSubnetsResponse subnetsInSpecifiedAZandVpc
                    = await ec2Client.DescribeSubnetsAsync(new DescribeSubnetsRequest()
                {
                    Filters = new List <Amazon.EC2.Model.Filter> {
                        new Amazon.EC2.Model.Filter {
                            Name   = "vpc-id",
                            Values = { vpcId }
                        },
                        new Amazon.EC2.Model.Filter {
                            Name   = "availability-zone",
                            Values = { azName }
                        }
                    }
                });

                List <string> subnetIdsInSpecifiedAZ = subnetsInSpecifiedAZandVpc.Subnets.Select(x => x.SubnetId).ToList();

                // Modify the autoscaling group to remove the AZ affected which is the AZ passed in the input
                // Find the autoscaling group that this is deployed into
                DescribeAutoScalingGroupsResponse autoScalingGroupsResponse = await asClient.DescribeAutoScalingGroupsAsync();

                if (autoScalingGroupsResponse != null && autoScalingGroupsResponse.AutoScalingGroups.Count > 0)
                {
                    // Note: This assumes an Auto Scaling group exists; no error checking for readability
                    AutoScalingGroup autoScalingGroup = autoScalingGroupsResponse.AutoScalingGroups[0];

                    Console.WriteLine($"Updating the auto scaling group {autoScalingGroup.AutoScalingGroupName} to remove the subnet in {azName}");

                    UpdateAutoScalingGroupResponse updateAutoScalingGroupResponse
                        = await asClient.UpdateAutoScalingGroupAsync(new UpdateAutoScalingGroupRequest
                    {
                        AutoScalingGroupName = autoScalingGroup.AutoScalingGroupName,
                        VPCZoneIdentifier    = String.Join(",", autoScalingGroup.VPCZoneIdentifier.Split(',').Where(x => !subnetIdsInSpecifiedAZ.Contains(x)))
                    });
                }

                Console.WriteLine("Creating new network ACL associations");
                await BlockSubnetsInAZ(vpcId, subnetIdsInSpecifiedAZ);

                Console.WriteLine("Failing over database");

                //fail over rds which is in the same AZ
                DescribeDBInstancesResponse describeDBInstancesResult = await rdsClient.DescribeDBInstancesAsync();

                string dbInstancedId = describeDBInstancesResult.DBInstances.Where(x => String.Equals(x.DBSubnetGroup.VpcId, vpcId, StringComparison.OrdinalIgnoreCase) &&
                                                                                   String.Equals(x.AvailabilityZone, azName, StringComparison.OrdinalIgnoreCase) &&
                                                                                   x.MultiAZ &&
                                                                                   !x.StatusInfos.Any())?.Select(x => x.DBInstanceIdentifier).FirstOrDefault();

                // we want to fail over rds if rds is present in the same az where it is affected
                if (!String.IsNullOrEmpty(dbInstancedId))
                {
                    Console.WriteLine("Rebooting dbInstanceId to secondary AZ " + dbInstancedId);

                    var response = await rdsClient.RebootDBInstanceAsync(new RebootDBInstanceRequest()
                    {
                        DBInstanceIdentifier = dbInstancedId,
                        ForceFailover        = true
                    });
                }
                else
                {
                    Console.WriteLine($"Didn't find DB in the same AZ as {azName}");
                }

                Console.Write("Done");
            }
            catch (Exception exception)
            {
                Console.WriteLine("Unknown exception occurred " + exception.Message);
            }
        }
 public LogAutoscalingEvent(IElasticLowLevelClient es, IAmazonAutoScaling asg, LogToElasticsearch logToEs) : base(request =>
                                                                                                                  (from asgEvent in Observable.Return(request)
                                                                                                                   let asgName = asgEvent.SelectToken("detail.AutoScalingGroupName")?.Value <string>()
                                                                                                                                 where !string.IsNullOrEmpty(asgName)
                                                                                                                                 let describeRequest = new DescribeAutoScalingGroupsRequest
 {
     AutoScalingGroupNames = new List <string> {
         asgName
     }
 }
                                                                                                                   from describeResponse in asg.DescribeAutoScalingGroupsAsync(describeRequest)
                                                                                                                   from description in describeResponse.AutoScalingGroups
                                                                                                                   let tags = description.Tags
                                                                                                                              let app = tags.GetValue("repo") ?? tags.GetValue("Application") ?? tags.GetValue("app")
                                                                                                                                        let env = tags.GetValue("env") ?? tags.GetValue("Environment")
                                                                                                                                                  let sha = tags.GetValue("sha")
                                                                                                                                                            let log = new
 {
     Name = asgEvent["detail-type"]?.Value <string>(),
     RequestId = asgName,
     Message = asgEvent
 }
                                                                                                                   let time = asgEvent["time"].Value <DateTime>()
                                                                                                                              let alteredLog = new AlteredLog
 {
     Time = time,
     Repo = app,
     Env = env,
     Sha = sha,
     Log = JObject.FromObject(log, AlteredJson.DefaultJsonSerializer)
 }
                                                                                                                   from response in logToEs.Execute(alteredLog)
                                                                                                                   select response).ToTask())
 {
 }