コード例 #1
0
        public void AutoScalingCreateOrUpdateTags()
        {
            #region autoscaling-create-or-update-tags-1

            var client   = new AmazonAutoScalingClient();
            var response = client.CreateOrUpdateTags(new CreateOrUpdateTagsRequest
            {
                Tags = new List <Tag> {
                    new Tag {
                        Key = "Role",
                        PropagateAtLaunch = true,
                        ResourceId        = "my-auto-scaling-group",
                        ResourceType      = "auto-scaling-group",
                        Value             = "WebServer"
                    },
                    new Tag {
                        Key = "Dept",
                        PropagateAtLaunch = true,
                        ResourceId        = "my-auto-scaling-group",
                        ResourceType      = "auto-scaling-group",
                        Value             = "Research"
                    }
                }
            });


            #endregion
        }
コード例 #2
0
        /// <summary>
        /// detact this instance from the ASG
        /// and decrement the ASG desired
        /// </summary>
        /// <returns></returns>
        private bool DetachFromAutoScalingGroup()
        {
            bool returnValue = false;

            using (AmazonAutoScalingClient scalingClient = new AmazonAutoScalingClient())
            {
                DetachInstancesRequest detachRequest = new DetachInstancesRequest
                {
                    AutoScalingGroupName           = _AutoScalingGroupName,
                    InstanceIds                    = new List <string>(new string[] { _InstanceId }),
                    ShouldDecrementDesiredCapacity = true
                };
                try
                {
                    DetachInstancesResponse detachResponse = scalingClient.DetachInstancesAsync(detachRequest).Result;
                    if (detachResponse.HttpStatusCode == System.Net.HttpStatusCode.OK)
                    {
                        returnValue = true;
                    }
                }
                catch (Exception)
                {
                    //Yes AWS throws Exceptions and System.AggregrateExceptions
                    //so for now this is the right way to handle it
                    returnValue = false;
                }
            }
            return(returnValue);
        }
コード例 #3
0
        public List <Image> GetAllOwnedPrivateAMIs(ILambdaContext context)
        {
            String accountId        = context.InvokedFunctionArn.Split(':')[4];
            var    ec2Client        = new AmazonEC2Client();
            var    asClient         = new AmazonAutoScalingClient();
            var    getImagesRequest = new DescribeImagesRequest();
            var    getLCRequest     = new DescribeLaunchConfigurationsRequest();

            getLCRequest.MaxRecords = 100;

            getImagesRequest.Filters.Add(new Amazon.EC2.Model.Filter
            {
                Name   = "is-public",
                Values = new List <string>()
                {
                    "false"
                }
            });
            getImagesRequest.Filters.Add(new Amazon.EC2.Model.Filter
            {
                Name   = "owner-id",
                Values = new List <string>()
                {
                    accountId
                }
            });

            var imagesResponse = ec2Client.DescribeImagesAsync(getImagesRequest);

            imagesResponse.Wait();

            return(imagesResponse.Result.Images);
        }
コード例 #4
0
        public void AutoScalingStartInstanceRefresh()
        {
            #region to-start-an-instance-refresh-1592957271522

            var client   = new AmazonAutoScalingClient();
            var response = client.StartInstanceRefresh(new StartInstanceRefreshRequest
            {
                AutoScalingGroupName = "my-auto-scaling-group",
                DesiredConfiguration = new DesiredConfiguration {
                    LaunchTemplate = new LaunchTemplateSpecification {
                        LaunchTemplateName = "my-template-for-auto-scaling",
                        Version            = "$Latest"
                    }
                },
                Preferences = new RefreshPreferences {
                    InstanceWarmup       = 400,
                    MinHealthyPercentage = 90,
                    SkipMatching         = true
                }
            });

            string instanceRefreshId = response.InstanceRefreshId;

            #endregion
        }
コード例 #5
0
        public void AutoScalingCreateAutoScalingGroup()
        {
            #region autoscaling-create-auto-scaling-group-2

            var client   = new AmazonAutoScalingClient();
            var response = client.CreateAutoScalingGroup(new CreateAutoScalingGroupRequest
            {
                AutoScalingGroupName   = "my-auto-scaling-group",
                HealthCheckGracePeriod = 300,
                HealthCheckType        = "ELB",
                LaunchTemplate         = new LaunchTemplateSpecification {
                    LaunchTemplateName = "my-template-for-auto-scaling",
                    Version            = "$Latest"
                },
                MaxSize         = 3,
                MinSize         = 1,
                TargetGroupARNs = new List <string> {
                    "arn:aws:elasticloadbalancing:us-west-2:123456789012:targetgroup/my-targets/73e2d6bc24d8a067"
                },
                VPCZoneIdentifier = "subnet-057fa0918fEXAMPLE, subnet-610acd08EXAMPLE"
            });


            #endregion
        }
コード例 #6
0
        public List <SA_AsgEc2Map> GetAsgEc2Maps(string region = null)
        {
            var rets = new List <SA_AsgEc2Map>();

            if (region != null)
            {
                client = new AmazonAutoScalingClient(
                    CredentiaslManager.GetCredential(profile),
                    AwsCommon.GetRetionEndpoint(region));
            }

            var lstSaGroups = new List <SA_AutoScalingGroup>();
            var response    = client.DescribeAutoScalingGroups();
            var lstGroups   = response.AutoScalingGroups.FindAll(o => o.Tags[0].Value.IndexOf(environment.ToString()) >= 0);

            foreach (var group in lstGroups)
            {
                if (group.Instances != null)
                {
                    foreach (var instance in group.Instances)
                    {
                        rets.Add(new SA_AsgEc2Map()
                        {
                            AsgName = group.Tags[0].Value,
                            AutoScalingGroupName = group.AutoScalingGroupName,
                            InstanceId           = instance.InstanceId
                        });
                    }
                }
            }
            return(rets);
        }
コード例 #7
0
 public AutoScalingHelper(string profile, string region, string color) : base(profile, region, color)
 {
     this.profile = profile;
     client       = new AmazonAutoScalingClient(
         CredentiaslManager.GetCredential(profile),
         AwsCommon.GetRetionEndpoint(region));
 }
コード例 #8
0
        public override void Invoke(AWSCredentials creds, RegionEndpoint region, int maxItems)
        {
            AmazonAutoScalingConfig config = new AmazonAutoScalingConfig();

            config.RegionEndpoint = region;
            ConfigureClient(config);
            AmazonAutoScalingClient client = new AmazonAutoScalingClient(creds, config);

            DescribeAutoScalingInstancesResponse resp = new DescribeAutoScalingInstancesResponse();

            do
            {
                DescribeAutoScalingInstancesRequest req = new DescribeAutoScalingInstancesRequest
                {
                    NextToken = resp.NextToken
                    ,
                    MaxRecords = maxItems
                };

                resp = client.DescribeAutoScalingInstances(req);
                CheckError(resp.HttpStatusCode, "200");

                foreach (var obj in resp.AutoScalingInstances)
                {
                    AddObject(obj);
                }
            }while (!string.IsNullOrEmpty(resp.NextToken));
        }
コード例 #9
0
        /// <summary>
        /// Notification configuration window load event
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void NcWindow_Loaded(object sender, RoutedEventArgs e)
        {
            try
            {
                AmazonAutoScalingConfig config = new AmazonAutoScalingConfig();
                config.ServiceURL = ((ViewModel)this.DataContext).Region.Url;
                AmazonAutoScalingClient client = new AmazonAutoScalingClient(config);
                DescribeAutoScalingNotificationTypesRequest  dasntreq  = new DescribeAutoScalingNotificationTypesRequest();
                DescribeAutoScalingNotificationTypesResponse dasntresp = client.DescribeAutoScalingNotificationTypes(dasntreq);
                foreach (string asnt in dasntresp.DescribeAutoScalingNotificationTypesResult.AutoScalingNotificationTypes)
                {
                    this.notificationTypes.Add(asnt);
                }

                AmazonSimpleNotificationServiceConfig snsconfig = new AmazonSimpleNotificationServiceConfig();
                config.ServiceURL = ((ViewModel)this.DataContext).Region.Url;
                AmazonSimpleNotificationServiceClient snsclient = new AmazonSimpleNotificationServiceClient(snsconfig);
                ListTopicsRequest  ltrequest = new ListTopicsRequest();
                ListTopicsResponse ltresp    = snsclient.ListTopics(ltrequest);
                foreach (Topic topic in ltresp.ListTopicsResult.Topics)
                {
                    this.snstopics.Add(topic.TopicArn);
                }

                rlbNcTypes.ItemsSource = this.notificationTypes;
                cboTopics.ItemsSource  = this.snstopics;
            }
            catch
            {
                MessageBox.Show(Window.GetWindow(this), "Error occured while loading the notification configuration options.", "Error", MessageBoxButton.OK);
                this.Close();
            }
        }
コード例 #10
0
ファイル: Bundle.cs プロジェクト: travcorp/aws-tools
        public CreateDeploymentResponse DeployToStack(
            AmazonCodeDeployClient codeDeployClient,
            AmazonIdentityManagementServiceClient iamClient,
            AmazonAutoScalingClient autoScalingClient,
            Role role)
        {
            var deploymentGroupName = _stackName + "_" + BundleName;

            EnsureDeploymentGroupExistsForBundle(codeDeployClient, iamClient, autoScalingClient, role, deploymentGroupName);

            var deploymentResponse = codeDeployClient.CreateDeployment(new CreateDeploymentRequest
            {
                ApplicationName     = CodeDeployApplicationName,
                DeploymentGroupName = deploymentGroupName,
                Revision            = new RevisionLocation
                {
                    RevisionType = RevisionLocationType.S3,
                    S3Location   = new S3Location
                    {
                        Bucket     = Bucket,
                        Key        = FileName,
                        BundleType = BundleType.Zip,
                        ETag       = ETag
                    }
                }
            });

            return(deploymentResponse);
        }
コード例 #11
0
        /// <summary>
        /// signals AWS to move on from terminate
        /// wait by completing the action
        /// </summary>
        public bool TryCompleteTerminateWait()
        {
            bool returnValue = false;

            //Ok now  its complicated, we need the LifecycleHookName and LifecycleActionToken
            //        to complete the request, there should be a message for us in the queue
            if (!(_TerminatingLifeCycleHookName.IsNullOrWhiteSpace()))
            {
                using (AmazonAutoScalingClient scalingClient = new AmazonAutoScalingClient())
                {
                    CompleteLifecycleActionRequest completeLifecycleActionRequest = new CompleteLifecycleActionRequest
                    {
                        InstanceId            = _InstanceId,
                        LifecycleActionResult = "CONTINUE",
                        AutoScalingGroupName  = _AutoScalingGroupName,
                        LifecycleHookName     = _TerminatingLifeCycleHookName
                    };
                    try
                    {
                        CompleteLifecycleActionResponse completeLifecycleActionResponse = scalingClient.CompleteLifecycleActionAsync(completeLifecycleActionRequest).Result;
                        if (completeLifecycleActionResponse.HttpStatusCode == System.Net.HttpStatusCode.OK)
                        {
                            returnValue = true;
                        }
                    }
                    catch (Exception)
                    {
                        //Yes AWS throws Exceptions and System.AggregrateExceptions
                        //so for now this is the right way to handle it
                        returnValue = false;
                    }
                }
            }
            return(returnValue);
        }
コード例 #12
0
        public void AutoScalingDescribeLifecycleHookTypes()
        {
            #region autoscaling-describe-lifecycle-hook-types-1

            var client   = new AmazonAutoScalingClient();
            var response = client.DescribeLifecycleHookTypes(new DescribeLifecycleHookTypesRequest
            {
            });

            List <string> lifecycleHookTypes = response.LifecycleHookTypes;

            #endregion
        }
コード例 #13
0
        public void AutoScalingDescribeAutoScalingNotificationTypes()
        {
            #region autoscaling-describe-auto-scaling-notification-types-1

            var client   = new AmazonAutoScalingClient();
            var response = client.DescribeAutoScalingNotificationTypes(new DescribeAutoScalingNotificationTypesRequest
            {
            });

            List <string> autoScalingNotificationTypes = response.AutoScalingNotificationTypes;

            #endregion
        }
コード例 #14
0
        public void AutoScalingDescribeAdjustmentTypes()
        {
            #region autoscaling-describe-adjustment-types-1

            var client   = new AmazonAutoScalingClient();
            var response = client.DescribeAdjustmentTypes(new DescribeAdjustmentTypesRequest
            {
            });

            List <AdjustmentType> adjustmentTypes = response.AdjustmentTypes;

            #endregion
        }
コード例 #15
0
        public void AutoScalingDeleteLaunchConfiguration()
        {
            #region autoscaling-delete-launch-configuration-1

            var client   = new AmazonAutoScalingClient();
            var response = client.DeleteLaunchConfiguration(new DeleteLaunchConfigurationRequest
            {
                LaunchConfigurationName = "my-launch-config"
            });


            #endregion
        }
コード例 #16
0
        public void AutoScalingDescribeScalingProcessTypes()
        {
            #region autoscaling-describe-scaling-process-types-1

            var client   = new AmazonAutoScalingClient();
            var response = client.DescribeScalingProcessTypes(new DescribeScalingProcessTypesRequest
            {
            });

            List <ProcessType> processes = response.Processes;

            #endregion
        }
コード例 #17
0
        public void AutoScalingDeleteAutoScalingGroup()
        {
            #region autoscaling-delete-auto-scaling-group-1

            var client   = new AmazonAutoScalingClient();
            var response = client.DeleteAutoScalingGroup(new DeleteAutoScalingGroupRequest
            {
                AutoScalingGroupName = "my-auto-scaling-group"
            });


            #endregion
        }
コード例 #18
0
        public void AutoScalingDescribeTerminationPolicyTypes()
        {
            #region autoscaling-describe-termination-policy-types-1

            var client   = new AmazonAutoScalingClient();
            var response = client.DescribeTerminationPolicyTypes(new DescribeTerminationPolicyTypesRequest
            {
            });

            List <string> terminationPolicyTypes = response.TerminationPolicyTypes;

            #endregion
        }
コード例 #19
0
        public void AutoScalingDescribeScheduledActions()
        {
            #region autoscaling-describe-scheduled-actions-1

            var client   = new AmazonAutoScalingClient();
            var response = client.DescribeScheduledActions(new DescribeScheduledActionsRequest
            {
                AutoScalingGroupName = "my-auto-scaling-group"
            });

            List <ScheduledUpdateGroupAction> scheduledUpdateGroupActions = response.ScheduledUpdateGroupActions;

            #endregion
        }
コード例 #20
0
        public void AutoScalingDeleteScheduledAction()
        {
            #region autoscaling-delete-scheduled-action-1

            var client   = new AmazonAutoScalingClient();
            var response = client.DeleteScheduledAction(new DeleteScheduledActionRequest
            {
                AutoScalingGroupName = "my-auto-scaling-group",
                ScheduledActionName  = "my-scheduled-action"
            });


            #endregion
        }
コード例 #21
0
        public void AutoScalingDescribeInstanceRefreshes()
        {
            #region to-list-instance-refreshes-1592959593746

            var client   = new AmazonAutoScalingClient();
            var response = client.DescribeInstanceRefreshes(new DescribeInstanceRefreshesRequest
            {
                AutoScalingGroupName = "my-auto-scaling-group"
            });

            List <InstanceRefresh> instanceRefreshes = response.InstanceRefreshes;

            #endregion
        }
コード例 #22
0
        public void AutoScalingDescribeLifecycleHooks()
        {
            #region autoscaling-describe-lifecycle-hooks-1

            var client   = new AmazonAutoScalingClient();
            var response = client.DescribeLifecycleHooks(new DescribeLifecycleHooksRequest
            {
                AutoScalingGroupName = "my-auto-scaling-group"
            });

            List <LifecycleHook> lifecycleHooks = response.LifecycleHooks;

            #endregion
        }
コード例 #23
0
        public void AutoScalingDescribeLoadBalancerTargetGroups()
        {
            #region autoscaling-describe-load-balancer-target-groups-1

            var client   = new AmazonAutoScalingClient();
            var response = client.DescribeLoadBalancerTargetGroups(new DescribeLoadBalancerTargetGroupsRequest
            {
                AutoScalingGroupName = "my-auto-scaling-group"
            });

            List <LoadBalancerTargetGroupState> loadBalancerTargetGroups = response.LoadBalancerTargetGroups;

            #endregion
        }
コード例 #24
0
        public void AutoScalingDescribeMetricCollectionTypes()
        {
            #region autoscaling-describe-metric-collection-types-1

            var client   = new AmazonAutoScalingClient();
            var response = client.DescribeMetricCollectionTypes(new DescribeMetricCollectionTypesRequest
            {
            });

            List <MetricGranularityType> granularities = response.Granularities;
            List <MetricCollectionType>  metrics       = response.Metrics;

            #endregion
        }
コード例 #25
0
        public void AutoScalingDescribePolicies()
        {
            #region autoscaling-describe-policies-1

            var client   = new AmazonAutoScalingClient();
            var response = client.DescribePolicies(new DescribePoliciesRequest
            {
                AutoScalingGroupName = "my-auto-scaling-group"
            });

            List <ScalingPolicy> scalingPolicies = response.ScalingPolicies;

            #endregion
        }
コード例 #26
0
        protected IAmazonAutoScaling CreateClient(AWSCredentials credentials, RegionEndpoint region)
        {
            var config = new AmazonAutoScalingConfig {
                RegionEndpoint = region
            };

            Amazon.PowerShell.Utils.Common.PopulateConfig(this, config);
            this.CustomizeClientConfig(config);
            var client = new AmazonAutoScalingClient(credentials, config);

            client.BeforeRequestEvent += RequestEventHandler;
            client.AfterResponseEvent += ResponseEventHandler;
            return(client);
        }
コード例 #27
0
        public void AutoScalingDescribeScalingActivities()
        {
            #region autoscaling-describe-scaling-activities-1

            var client   = new AmazonAutoScalingClient();
            var response = client.DescribeScalingActivities(new DescribeScalingActivitiesRequest
            {
                AutoScalingGroupName = "my-auto-scaling-group"
            });

            List <Activity> activities = response.Activities;

            #endregion
        }
コード例 #28
0
        public void AutoScalingSetInstanceHealth()
        {
            #region autoscaling-set-instance-health-1

            var client   = new AmazonAutoScalingClient();
            var response = client.SetInstanceHealth(new SetInstanceHealthRequest
            {
                HealthStatus = "Unhealthy",
                InstanceId   = "i-93633f9b"
            });


            #endregion
        }
コード例 #29
0
        public void AutoScalingEnableMetricsCollection()
        {
            #region autoscaling-enable-metrics-collection-1

            var client   = new AmazonAutoScalingClient();
            var response = client.EnableMetricsCollection(new EnableMetricsCollectionRequest
            {
                AutoScalingGroupName = "my-auto-scaling-group",
                Granularity          = "1Minute"
            });


            #endregion
        }
コード例 #30
0
        public void AutoScalingCancelInstanceRefresh()
        {
            #region to-cancel-an-instance-refresh-1592960979817

            var client   = new AmazonAutoScalingClient();
            var response = client.CancelInstanceRefresh(new CancelInstanceRefreshRequest
            {
                AutoScalingGroupName = "my-auto-scaling-group"
            });

            string instanceRefreshId = response.InstanceRefreshId;

            #endregion
        }