Exemples d'Auto Scaling Plans utilisant AWS CLI - AWS Command Line Interface

Les traductions sont fournies par des outils de traduction automatique. En cas de conflit entre le contenu d'une traduction et celui de la version originale en anglais, la version anglaise prévaudra.

Exemples d'Auto Scaling Plans utilisant AWS CLI

Les exemples de code suivants vous montrent comment effectuer des actions et implémenter des scénarios courants à l'aide de AWS Command Line Interface with Auto Scaling Plans.

Les actions sont des extraits de code de programmes plus larges et doivent être exécutées dans leur contexte. Alors que les actions vous montrent comment appeler des fonctions de service individuelles, vous pouvez les visualiser dans leur contexte dans leurs scénarios associés.

Chaque exemple inclut un lien vers le code source complet, où vous trouverez des instructions sur la façon de configurer et d'exécuter le code en contexte.

Rubriques

Actions

L'exemple de code suivant montre comment utilisercreate-scaling-plan.

AWS CLI

Pour créer un plan de mise à l'échelle

L'create-scaling-planexemple suivant crée un plan de dimensionnement nommé à my-scaling-plan l'aide d'un JSON fichier déjà créé (nommé config.json). La structure du plan de dimensionnement inclut une instruction de dimensionnement pour un groupe Auto Scaling nommémy-asg. Elle spécifie la propriété TagFilters en tant que source de l'application et active le dimensionnement prédictif et dynamique.

aws autoscaling-plans create-scaling-plan \ --scaling-plan-name my-scaling-plan \ --cli-input-json file://~/config.json

Contenu du config.json fichier :

{ "ApplicationSource": { "TagFilters": [ { "Key": "purpose", "Values": [ "my-application" ] } ] }, "ScalingInstructions": [ { "ServiceNamespace": "autoscaling", "ResourceId": "autoScalingGroup/my-asg", "ScalableDimension": "autoscaling:autoScalingGroup:DesiredCapacity", "ScheduledActionBufferTime": 300, "PredictiveScalingMaxCapacityBehavior": "SetForecastCapacityToMaxCapacity", "PredictiveScalingMode": "ForecastAndScale", "PredefinedLoadMetricSpecification": { "PredefinedLoadMetricType": "ASGTotalCPUUtilization" }, "ScalingPolicyUpdateBehavior": "ReplaceExternalPolicies", "MinCapacity": 1, "MaxCapacity": 4, "TargetTrackingConfigurations": [ { "PredefinedScalingMetricSpecification": { "PredefinedScalingMetricType": "ASGAverageCPUUtilization" }, "TargetValue": 50 } ] } ] }

Sortie :

{ "ScalingPlanVersion": 1 }

Pour plus d'informations, consultez le guide de l'utilisateur d'AWS Auto Scaling.

  • Pour API plus de détails, voir CreateScalingPlanla section Référence des AWS CLI commandes.

L'exemple de code suivant montre comment utiliserdelete-scaling-plan.

AWS CLI

Pour supprimer un plan de dimensionnement

L'delete-scaling-planexemple suivant supprime le plan de dimensionnement spécifié.

aws autoscaling-plans delete-scaling-plan \ --scaling-plan-name my-scaling-plan \ --scaling-plan-version 1

Cette commande ne produit aucun résultat.

Pour plus d'informations, consultez le guide de l'utilisateur d'AWS Auto Scaling.

  • Pour API plus de détails, voir DeleteScalingPlanla section Référence des AWS CLI commandes.

L'exemple de code suivant montre comment utiliserdescribe-scaling-plan-resources.

AWS CLI

Pour décrire les ressources évolutives d'un plan de mise à l'échelle

L'describe-scaling-plan-resourcesexemple suivant affiche les détails de la ressource évolutive unique (un groupe Auto Scaling) associée au plan de dimensionnement spécifié.

aws autoscaling-plans describe-scaling-plan-resources \ --scaling-plan-name my-scaling-plan \ --scaling-plan-version 1

Sortie :

{ "ScalingPlanResources": [ { "ScalableDimension": "autoscaling:autoScalingGroup:DesiredCapacity", "ScalingPlanVersion": 1, "ResourceId": "autoScalingGroup/my-asg", "ScalingStatusCode": "Active", "ScalingStatusMessage": "Target tracking scaling policies have been applied to the resource.", "ScalingPolicies": [ { "PolicyName": "AutoScaling-my-asg-b1ab65ae-4be3-4634-bd64-c7471662b251", "PolicyType": "TargetTrackingScaling", "TargetTrackingConfiguration": { "PredefinedScalingMetricSpecification": { "PredefinedScalingMetricType": "ALBRequestCountPerTarget", "ResourceLabel": "app/my-alb/f37c06a68c1748aa/targetgroup/my-target-group/6d4ea56ca2d6a18d" }, "TargetValue": 40.0 } } ], "ServiceNamespace": "autoscaling", "ScalingPlanName": "my-scaling-plan" } ] }

Pour plus d'informations, consultez What Is AWS Auto Scaling ? dans le Guide de l'utilisateur d'AWS Auto Scaling.

L'exemple de code suivant montre comment utiliserdescribe-scaling-plans.

AWS CLI

Pour décrire un plan de mise à l'échelle

L'describe-scaling-plansexemple suivant affiche les détails du plan de dimensionnement spécifié.

aws autoscaling-plans describe-scaling-plans \ --scaling-plan-names scaling-plan-with-asg-and-ddb

Sortie :

{ "ScalingPlans": [ { "LastMutatingRequestTime": 1565388443.963, "ScalingPlanVersion": 1, "CreationTime": 1565388443.963, "ScalingInstructions": [ { "ScalingPolicyUpdateBehavior": "ReplaceExternalPolicies", "ScalableDimension": "autoscaling:autoScalingGroup:DesiredCapacity", "TargetTrackingConfigurations": [ { "PredefinedScalingMetricSpecification": { "PredefinedScalingMetricType": "ASGAverageCPUUtilization" }, "TargetValue": 50.0, "EstimatedInstanceWarmup": 300, "DisableScaleIn": false } ], "ResourceId": "autoScalingGroup/my-asg", "DisableDynamicScaling": false, "MinCapacity": 1, "ServiceNamespace": "autoscaling", "MaxCapacity": 10 }, { "ScalingPolicyUpdateBehavior": "ReplaceExternalPolicies", "ScalableDimension": "dynamodb:table:ReadCapacityUnits", "TargetTrackingConfigurations": [ { "PredefinedScalingMetricSpecification": { "PredefinedScalingMetricType": "DynamoDBReadCapacityUtilization" }, "TargetValue": 50.0, "ScaleInCooldown": 60, "DisableScaleIn": false, "ScaleOutCooldown": 60 } ], "ResourceId": "table/my-table", "DisableDynamicScaling": false, "MinCapacity": 5, "ServiceNamespace": "dynamodb", "MaxCapacity": 10000 }, { "ScalingPolicyUpdateBehavior": "ReplaceExternalPolicies", "ScalableDimension": "dynamodb:table:WriteCapacityUnits", "TargetTrackingConfigurations": [ { "PredefinedScalingMetricSpecification": { "PredefinedScalingMetricType": "DynamoDBWriteCapacityUtilization" }, "TargetValue": 50.0, "ScaleInCooldown": 60, "DisableScaleIn": false, "ScaleOutCooldown": 60 } ], "ResourceId": "table/my-table", "DisableDynamicScaling": false, "MinCapacity": 5, "ServiceNamespace": "dynamodb", "MaxCapacity": 10000 } ], "ApplicationSource": { "TagFilters": [ { "Values": [ "my-application-id" ], "Key": "application" } ] }, "StatusStartTime": 1565388455.836, "ScalingPlanName": "scaling-plan-with-asg-and-ddb", "StatusMessage": "Scaling plan has been created and applied to all resources.", "StatusCode": "Active" } ] }

Pour plus d'informations, consultez What Is AWS Auto Scaling ? dans le Guide de l'utilisateur d'AWS Auto Scaling.

L'exemple de code suivant montre comment utiliserget-scaling-plan-resource-forecast-data.

AWS CLI

Pour récupérer les données de prévision de charge

Cet exemple extrait les données de prévision de charge pour une ressource évolutive (un groupe Auto Scaling) associée au plan de dimensionnement spécifié.

aws autoscaling-plans get-scaling-plan-resource-forecast-data \ --scaling-plan-name my-scaling-plan \ --scaling-plan-version 1 \ --service-namespace "autoscaling" \ --resource-id autoScalingGroup/my-asg \ --scalable-dimension "autoscaling:autoScalingGroup:DesiredCapacity" \ --forecast-data-type "LoadForecast" \ --start-time "2019-08-30T00:00:00Z" \ --end-time "2019-09-06T00:00:00Z"

Sortie :

{ "Datapoints": [...] }

Pour plus d'informations, consultez la section What Is AWS Auto Scaling dans le guide de l'utilisateur d'AWS Auto Scaling.

L'exemple de code suivant montre comment utiliserupdate-scaling-plan.

AWS CLI

Pour mettre à jour un plan de mise à l'échelle

L'update-scaling-planexemple suivant modifie la métrique de dimensionnement d'un groupe Auto Scaling dans le plan de dimensionnement spécifié.

aws autoscaling-plans update-scaling-plan \ --scaling-plan-name my-scaling-plan \ --scaling-plan-version 1 \ --scaling-instructions '{"ScalableDimension":"autoscaling:autoScalingGroup:DesiredCapacity","ResourceId":"autoScalingGroup/my-asg","ServiceNamespace":"autoscaling","TargetTrackingConfigurations":[{"PredefinedScalingMetricSpecification": {"PredefinedScalingMetricType":"ALBRequestCountPerTarget","ResourceLabel":"app/my-alb/f37c06a68c1748aa/targetgroup/my-target-group/6d4ea56ca2d6a18d"},"TargetValue":40.0}],"MinCapacity": 1,"MaxCapacity": 10}'

Cette commande ne produit aucun résultat.

Pour plus d'informations, consultez What Is AWS Auto Scaling ? dans le Guide de l'utilisateur d'AWS Auto Scaling.

  • Pour API plus de détails, voir UpdateScalingPlanla section Référence des AWS CLI commandes.