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 }
/// <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); }
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); }
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 }
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 }
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); }
public AutoScalingHelper(string profile, string region, string color) : base(profile, region, color) { this.profile = profile; client = new AmazonAutoScalingClient( CredentiaslManager.GetCredential(profile), AwsCommon.GetRetionEndpoint(region)); }
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)); }
/// <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(); } }
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); }
/// <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); }
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 }
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 }
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 }
public void AutoScalingDeleteLaunchConfiguration() { #region autoscaling-delete-launch-configuration-1 var client = new AmazonAutoScalingClient(); var response = client.DeleteLaunchConfiguration(new DeleteLaunchConfigurationRequest { LaunchConfigurationName = "my-launch-config" }); #endregion }
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 }
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 }
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 }
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 }
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 }
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 }
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 }
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 }
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 }
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 }
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); }
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 }
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 }
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 }
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 }