

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
<a name="cli_auto-scaling-plans_code_examples"></a>

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 indiquent comment appeler des fonctions de service individuelles, vous pouvez les voir en contexte dans leurs scénarios associés.

Chaque exemple inclut un lien vers le code source complet, où vous trouverez des instructions sur la configuration et l’exécution du code en contexte.

**Topics**
+ [Actions](#actions)

## Actions
<a name="actions"></a>

### `create-scaling-plan`
<a name="auto-scaling-plans_CreateScalingPlan_cli_topic"></a>

L'exemple de code suivant montre comment utiliser`create-scaling-plan`.

**AWS CLI**  
**Pour créer un plan de mise à l’échelle**  
L’exemple `create-scaling-plan` suivant crée un plan de mise à l’échelle nommé `my-scaling-plan` à l’aide d’un fichier JSON déjà créé (nommé config.json). La structure du plan de mise à l’échelle inclut une instruction de mise à l’échelle 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 fichier `config.json` :  

```
{
    "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 AWS Auto Scaling](https://docs.aws.amazon.com/autoscaling/plans/userguide/what-is-aws-auto-scaling.html).  
+  Pour plus de détails sur l'API, reportez-vous [CreateScalingPlan](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/autoscaling-plans/create-scaling-plan.html)à la section *Référence des AWS CLI commandes*. 

### `delete-scaling-plan`
<a name="auto-scaling-plans_DeleteScalingPlan_cli_topic"></a>

L'exemple de code suivant montre comment utiliser`delete-scaling-plan`.

**AWS CLI**  
**Pour supprimer un plan de mise à l’échelle**  
L’exemple `delete-scaling-plan` suivant supprime le plan de mise à l’échelle spécifié.  

```
aws autoscaling-plans delete-scaling-plan \
    --scaling-plan-name my-scaling-plan \
    --scaling-plan-version 1
```
Cette commande ne produit aucune sortie.  
Pour plus d’informations, consultez le [Guide de l’utilisateur AWS Auto Scaling](https://docs.aws.amazon.com/autoscaling/plans/userguide/what-is-aws-auto-scaling.html).  
+  Pour plus de détails sur l'API, reportez-vous [DeleteScalingPlan](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/autoscaling-plans/delete-scaling-plan.html)à la section *Référence des AWS CLI commandes*. 

### `describe-scaling-plan-resources`
<a name="auto-scaling-plans_DescribeScalingPlanResources_cli_topic"></a>

L'exemple de code suivant montre comment utiliser`describe-scaling-plan-resources`.

**AWS CLI**  
**Pour décrire les ressources évolutives d’un plan de mise à l’échelle**  
L’`describe-scaling-plan-resources`exemple suivant affiche les informations 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 ?](https://docs.aws.amazon.com/autoscaling/plans/userguide/what-is-aws-auto-scaling.html) dans le *Guide de l'utilisateur d'AWS Auto Scaling*.  
+  Pour plus de détails sur l'API, reportez-vous [DescribeScalingPlanResources](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/autoscaling-plans/describe-scaling-plan-resources.html)à la section *Référence des AWS CLI commandes*. 

### `describe-scaling-plans`
<a name="auto-scaling-plans_DescribeScalingPlans_cli_topic"></a>

L'exemple de code suivant montre comment utiliser`describe-scaling-plans`.

**AWS CLI**  
**Pour décrire un plan de mise à l’échelle**  
L’exemple `describe-scaling-plans` suivant affiche les informations du plan de mise à l’échelle 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 ?](https://docs.aws.amazon.com/autoscaling/plans/userguide/what-is-aws-auto-scaling.html) dans le *Guide de l'utilisateur d'AWS Auto Scaling*.  
+  Pour plus de détails sur l'API, reportez-vous [DescribeScalingPlans](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/autoscaling-plans/describe-scaling-plans.html)à la section *Référence des AWS CLI commandes*. 

### `get-scaling-plan-resource-forecast-data`
<a name="auto-scaling-plans_GetScalingPlanResourceForecastData_cli_topic"></a>

L'exemple de code suivant montre comment utiliser`get-scaling-plan-resource-forecast-data`.

**AWS CLI**  
**Pour extraire 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 mise à l’échelle 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](https://docs.aws.amazon.com/autoscaling/plans/userguide/what-is-aws-auto-scaling.html) dans le *guide de l'utilisateur d'AWS Auto Scaling*.  
+  Pour plus de détails sur l'API, reportez-vous [GetScalingPlanResourceForecastData](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/autoscaling-plans/get-scaling-plan-resource-forecast-data.html)à la section *Référence des AWS CLI commandes*. 

### `update-scaling-plan`
<a name="auto-scaling-plans_UpdateScalingPlan_cli_topic"></a>

L'exemple de code suivant montre comment utiliser`update-scaling-plan`.

**AWS CLI**  
**Pour mettre à jour un plan de mise à l’échelle**  
L’exemple `update-scaling-plan` suivant modifie la métrique de mise à l’échelle d’un groupe Auto Scaling dans le plan de mise à l’échelle 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 aucune sortie.  
Pour plus d'informations, consultez [What Is AWS Auto Scaling ?](https://docs.aws.amazon.com/autoscaling/plans/userguide/what-is-aws-auto-scaling.html) dans le *Guide de l'utilisateur d'AWS Auto Scaling*.  
+  Pour plus de détails sur l'API, reportez-vous [UpdateScalingPlan](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/autoscaling-plans/update-scaling-plan.html)à la section *Référence des AWS CLI commandes*. 