-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6068 from elysahall/awsdocs-04-06
New CLI examples for autoscaling
- Loading branch information
Showing
55 changed files
with
1,777 additions
and
1,126 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,9 @@ | ||
**To attach an instance to an Auto Scaling group** | ||
|
||
This example attaches the specified instance to the specified Auto Scaling group:: | ||
|
||
aws autoscaling attach-instances --instance-ids i-93633f9b --auto-scaling-group-name my-auto-scaling-group | ||
**To attach an instance to an Auto Scaling group** | ||
|
||
This example attaches the specified instance to the specified Auto Scaling group. :: | ||
|
||
aws autoscaling attach-instances \ | ||
--instance-ids i-061c63c5eb45f0416 \ | ||
--auto-scaling-group-name my-asg | ||
|
||
This command produces no output. |
16 changes: 11 additions & 5 deletions
16
awscli/examples/autoscaling/attach-load-balancer-target-groups.rst
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,11 @@ | ||
**To attach a target group to an Auto Scaling group** | ||
|
||
This example attaches the specified target group to the specified Auto Scaling group:: | ||
|
||
aws autoscaling attach-load-balancer-target-groups --auto-scaling-group-name my-auto-scaling-group --target-group-arns arn:aws:elasticloadbalancing:us-west-2:123456789012:targetgroup/my-targets/73e2d6bc24d8a067 | ||
**To attach a target group to an Auto Scaling group** | ||
|
||
This example attaches the specified target group to the specified Auto Scaling group. :: | ||
|
||
aws autoscaling attach-load-balancer-target-groups \ | ||
--auto-scaling-group-name my-asg \ | ||
--target-group-arns arn:aws:elasticloadbalancing:us-west-2:123456789012:targetgroup/my-targets/73e2d6bc24d8a067 | ||
|
||
This command produces no output. | ||
|
||
For more information, see `Elastic Load Balancing and Amazon EC2 Auto Scaling <https://docs.aws.amazon.com/autoscaling/ec2/userguide/autoscaling-load-balancer.html>`__ in the *Amazon EC2 Auto Scaling User Guide*. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,11 @@ | ||
**To attach a load balancer to an Auto Scaling group** | ||
|
||
This example attaches the specified load balancer to the specified Auto Scaling group:: | ||
|
||
aws autoscaling attach-load-balancers --load-balancer-names my-load-balancer --auto-scaling-group-name my-auto-scaling-group | ||
**To attach a Classic Load Balancer to an Auto Scaling group** | ||
|
||
This example attaches the specified Classic Load Balancer to the specified Auto Scaling group. :: | ||
|
||
aws autoscaling attach-load-balancers \ | ||
--load-balancer-names my-load-balancer \ | ||
--auto-scaling-group-name my-asg | ||
|
||
This command produces no output. | ||
|
||
For more information, see `Elastic Load Balancing and Amazon EC2 Auto Scaling <https://docs.aws.amazon.com/autoscaling/ec2/userguide/autoscaling-load-balancer.html>`__ in the *Amazon EC2 Auto Scaling User Guide*. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,13 @@ | ||
**To complete the lifecycle action** | ||
|
||
This example notifies Auto Scaling that the specified lifecycle action is complete so that it can finish launching or terminating the instance:: | ||
|
||
aws autoscaling complete-lifecycle-action --lifecycle-hook-name my-lifecycle-hook --auto-scaling-group-name my-auto-scaling-group --lifecycle-action-result CONTINUE --lifecycle-action-token bcd2f1b8-9a78-44d3-8a7a-4dd07d7cf635 | ||
**To complete the lifecycle action** | ||
|
||
This example notifies Amazon EC2 Auto Scaling that the specified lifecycle action is complete so that it can finish launching or terminating the instance. :: | ||
|
||
aws autoscaling complete-lifecycle-action \ | ||
--lifecycle-hook-name my-launch-hook \ | ||
--auto-scaling-group-name my-asg \ | ||
--lifecycle-action-result CONTINUE \ | ||
--lifecycle-action-token bcd2f1b8-9a78-44d3-8a7a-4dd07d7cf635 | ||
|
||
This command produces no output. | ||
|
||
For more information, see `Amazon EC2 Auto Scaling lifecycle hooks <https://docs.aws.amazon.com/autoscaling/ec2/userguide/lifecycle-hooks.html>`__ in the *Amazon EC2 Auto Scaling User Guide*. |
220 changes: 152 additions & 68 deletions
220
awscli/examples/autoscaling/create-auto-scaling-group.rst
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,68 +1,152 @@ | ||
**To create an Auto Scaling group using a launch configuration** | ||
|
||
This example creates an Auto Scaling group in a VPC using a launch configuration to specify the type of EC2 instance that Amazon EC2 Auto Scaling creates:: | ||
|
||
aws autoscaling create-auto-scaling-group --auto-scaling-group-name my-asg --launch-configuration-name my-launch-config --min-size 1 --max-size 3 --vpc-zone-identifier "subnet-5ea0c127,subnet-6194ea3b,subnet-c934b782" | ||
|
||
This example creates an Auto Scaling group and configures it to use an Elastic Load Balancing load balancer:: | ||
|
||
aws autoscaling create-auto-scaling-group --auto-scaling-group-name my-asg --launch-configuration-name my-launch-config --load-balancer-names my-load-balancer --health-check-type ELB --health-check-grace-period 120 --min-size 1 --max-size 3 --vpc-zone-identifier "subnet-5ea0c127,subnet-6194ea3b,subnet-c934b782" | ||
|
||
This example specifies a desired capacity as well as a minimum and maximum capacity. It also launches instances into a placement group and sets the termination policy to terminate the oldest instances first:: | ||
|
||
aws autoscaling create-auto-scaling-group --auto-scaling-group-name my-asg --launch-configuration-name my-launch-config --min-size 1 --max-size 3 --desired-capacity 1 --placement-group my-placement-group --termination-policies "OldestInstance" --availability-zones us-west-2c | ||
|
||
**To create an Auto Scaling group using an EC2 instance** | ||
|
||
This example creates an Auto Scaling group from the specified EC2 instance and assigns a tag to instances in the group:: | ||
|
||
aws autoscaling create-auto-scaling-group --auto-scaling-group-name my-asg --instance-id i-22c99e2a --min-size 1 --max-size 3 --vpc-zone-identifier "subnet-5ea0c127,subnet-6194ea3b,subnet-c934b782" --tags "ResourceId=my-asg,ResourceType=auto-scaling-group,Key=Role,Value=WebServer,PropagateAtLaunch=true" | ||
|
||
**To create an Auto Scaling group using a launch template** | ||
|
||
This example creates an Auto Scaling group in a VPC using a launch template to specify the type of EC2 instance that Amazon EC2 Auto Scaling creates:: | ||
|
||
aws autoscaling create-auto-scaling-group --auto-scaling-group-name my-asg --launch-template "LaunchTemplateName=my-template-for-auto-scaling,Version=1" --min-size 1 --max-size 3 --vpc-zone-identifier "subnet-5ea0c127,subnet-6194ea3b,subnet-c934b782" | ||
This example uses the default version of the specified launch template. It specifies Availability Zones and subnets and enables the instance protection setting:: | ||
|
||
aws autoscaling create-auto-scaling-group --auto-scaling-group-name my-asg --launch-template LaunchTemplateId=lt-0a4872e2c396d941c --min-size 1 --max-size 3 --desired-capacity 2 --availability-zones us-west-2a us-west-2b us-west-2c --vpc-zone-identifier "subnet-5ea0c127,subnet-6194ea3b,subnet-c934b782" --new-instances-protected-from-scale-in | ||
This example creates an Auto Scaling group that launches a single instance using a launch template to optionally specify the ID of an existing network interface (ENI ID) to use. It specifies an Availability Zone that matches the specified network interface:: | ||
|
||
aws autoscaling create-auto-scaling-group --auto-scaling-group-name my-asg-single-instance --launch-template "LaunchTemplateName=my-single-instance-asg-template,Version=2" --min-size 1 --max-size 1 --availability-zones us-west-2a | ||
|
||
This example creates an Auto Scaling group with a lifecycle hook that supports a custom action at instance termination:: | ||
|
||
aws autoscaling create-auto-scaling-group --cli-input-json file://~/config.json | ||
|
||
Contents of config.json file:: | ||
|
||
{ | ||
"AutoScalingGroupName": "my-asg", | ||
"LaunchTemplate": { | ||
"LaunchTemplateId": "lt-0a4872e2c396d941c" | ||
}, | ||
"LifecycleHookSpecificationList": [{ | ||
"LifecycleHookName": "my-hook", | ||
"LifecycleTransition": "autoscaling:EC2_INSTANCE_TERMINATING", | ||
"NotificationTargetARN": "arn:aws:sqs:us-west-2:123456789012:my-sqs-queue", | ||
"RoleARN": "arn:aws:iam::123456789012:role/my-notification-role", | ||
"HeartbeatTimeout": 300, | ||
"DefaultResult": "CONTINUE" | ||
}], | ||
"MinSize": 1, | ||
"MaxSize": 5, | ||
"VPCZoneIdentifier": "subnet-5ea0c127,subnet-6194ea3b,subnet-c934b782", | ||
"Tags": [{ | ||
"ResourceType": "auto-scaling-group", | ||
"ResourceId": "my-asg", | ||
"PropagateAtLaunch": true, | ||
"Value": "test", | ||
"Key": "environment" | ||
}] | ||
} | ||
|
||
For more information, see the `Amazon EC2 Auto Scaling User Guide`_. | ||
|
||
.. _`Amazon EC2 Auto Scaling User Guide`: https://docs.aws.amazon.com/autoscaling/ec2/userguide/what-is-amazon-ec2-auto-scaling.html | ||
**Example 1: To create an Auto Scaling group** | ||
|
||
The following ``create-auto-scaling-group`` example creates an Auto Scaling group in subnets in multiple Availability Zones within a Region. The instances launch with the default version of the specified launch template. Note that defaults are used for most other settings, such as the termination policies and health check configuration. :: | ||
|
||
aws autoscaling create-auto-scaling-group \ | ||
--auto-scaling-group-name my-asg \ | ||
--launch-template LaunchTemplateId=lt-1234567890abcde12 \ | ||
--min-size 1 \ | ||
--max-size 5 \ | ||
--vpc-zone-identifier "subnet-5ea0c127,subnet-6194ea3b,subnet-c934b782" | ||
|
||
This command produces no output. | ||
|
||
For more information, see `Auto Scaling groups <https://docs.aws.amazon.com/autoscaling/ec2/userguide/AutoScalingGroup.html>`__ in the *Amazon EC2 Auto Scaling User Guide*. | ||
|
||
**Example 2: To attach an Application Load Balancer, Network Load Balancer, or Gateway Load Balancer** | ||
|
||
This example specifies the ARN of a target group for a load balancer that supports the expected traffic. The health check type specifies ``ELB`` so that when Elastic Load Balancing reports an instance as unhealthy, the Auto Scaling group replaces it. The command also defines a health check grace period of ``600`` seconds. The grace period helps prevent premature termination of newly launched instances. :: | ||
|
||
aws autoscaling create-auto-scaling-group \ | ||
--auto-scaling-group-name my-asg \ | ||
--launch-template LaunchTemplateId=lt-1234567890abcde12 \ | ||
--target-group-arns arn:aws:elasticloadbalancing:us-west-2:123456789012:targetgroup/my-targets/943f017f100becff \ | ||
--health-check-type ELB \ | ||
--health-check-grace-period 600 \ | ||
--min-size 1 \ | ||
--max-size 5 \ | ||
--vpc-zone-identifier "subnet-5ea0c127,subnet-6194ea3b,subnet-c934b782" | ||
|
||
This command produces no output. | ||
|
||
For more information, see `Auto Scaling groups <https://docs.aws.amazon.com/autoscaling/ec2/userguide/AutoScalingGroup.html>`__ in the *Amazon EC2 Auto Scaling User Guide*. | ||
|
||
**Example 3: To specify a placement group and use the latest version of the launch template** | ||
|
||
This example launches instances into a placement group within a single Availability Zone. This can be useful for low-latency groups with HPC workloads. This example also specifies a desired capacity as well as a minimum and maximum capacity. :: | ||
|
||
aws autoscaling create-auto-scaling-group \ | ||
--auto-scaling-group-name my-asg \ | ||
--launch-template LaunchTemplateId=lt-1234567890abcde12,Version='$Latest' \ | ||
--min-size 1 \ | ||
--max-size 5 \ | ||
--desired-capacity 3 \ | ||
--placement-group my-placement-group \ | ||
--vpc-zone-identifier "subnet-6194ea3b" | ||
|
||
This command produces no output. | ||
|
||
For more information, see `Auto Scaling groups <https://docs.aws.amazon.com/autoscaling/ec2/userguide/AutoScalingGroup.html>`__ in the *Amazon EC2 Auto Scaling User Guide*. | ||
|
||
**Example 4: To specify a single instance Auto Scaling group and use a specific version of the launch template** | ||
|
||
This example creates an Auto Scaling group with minimum and maximum capacity set to ``1`` to enforce that one instance will be running. The command also specifies v1 of a launch template in which the ID of an existing ENI is specified. When you use a launch template that specifies an existing ENI for eth0, you must specify an Availability Zone for the Auto Scaling group that matches the network interface, without also specifying a subnet ID in the request. :: | ||
|
||
aws autoscaling create-auto-scaling-group \ | ||
--auto-scaling-group-name my-asg-single-instance \ | ||
--launch-template LaunchTemplateName=my-template-for-auto-scaling,Version='1' \ | ||
--min-size 1 \ | ||
--max-size 1 \ | ||
--availability-zones us-west-2a | ||
|
||
This command produces no output. | ||
|
||
For more information, see `Auto Scaling groups <https://docs.aws.amazon.com/autoscaling/ec2/userguide/AutoScalingGroup.html>`__ in the *Amazon EC2 Auto Scaling User Guide*. | ||
|
||
**Example 5: To use a launch configuration** | ||
|
||
This example creates an Auto Scaling group using a launch configuration and sets the termination policy to terminate the oldest instances first. The command also applies a tag to the group and its instances, with a key of ``Role`` and a value of ``WebServer``. :: | ||
|
||
aws autoscaling create-auto-scaling-group \ | ||
--auto-scaling-group-name my-asg \ | ||
--launch-configuration-name my-launch-config \ | ||
--min-size 1 \ | ||
--max-size 5 \ | ||
--termination-policies "OldestInstance" \ | ||
--tags "ResourceId=my-asg,ResourceType=auto-scaling-group,Key=Role,Value=WebServer,PropagateAtLaunch=true" \ | ||
--vpc-zone-identifier "subnet-5ea0c127,subnet-6194ea3b,subnet-c934b782" | ||
|
||
This command produces no output. | ||
|
||
For more information, see `Auto Scaling groups <https://docs.aws.amazon.com/autoscaling/ec2/userguide/AutoScalingGroup.html>`__ in the *Amazon EC2 Auto Scaling User Guide*. | ||
|
||
**Example 6: To specify a launch lifecycle hook** | ||
|
||
This example creates an Auto Scaling group with a lifecycle hook that supports a custom action at instance launch. :: | ||
|
||
aws autoscaling create-auto-scaling-group \ | ||
--cli-input-json file://~/config.json | ||
|
||
Contents of ``config.json`` file:: | ||
|
||
{ | ||
"AutoScalingGroupName": "my-asg", | ||
"LaunchTemplate": { | ||
"LaunchTemplateId": "lt-1234567890abcde12" | ||
}, | ||
"LifecycleHookSpecificationList": [{ | ||
"LifecycleHookName": "my-launch-hook", | ||
"LifecycleTransition": "autoscaling:EC2_INSTANCE_LAUNCHING", | ||
"NotificationTargetARN": "arn:aws:sqs:us-west-2:123456789012:my-sqs-queue", | ||
"RoleARN": "arn:aws:iam::123456789012:role/my-notification-role", | ||
"NotificationMetadata": "SQS message metadata", | ||
"HeartbeatTimeout": 4800, | ||
"DefaultResult": "ABANDON" | ||
}], | ||
"MinSize": 1, | ||
"MaxSize": 5, | ||
"VPCZoneIdentifier": "subnet-5ea0c127,subnet-6194ea3b,subnet-c934b782", | ||
"Tags": [{ | ||
"ResourceType": "auto-scaling-group", | ||
"ResourceId": "my-asg", | ||
"PropagateAtLaunch": true, | ||
"Value": "test", | ||
"Key": "environment" | ||
}] | ||
} | ||
|
||
This command produces no output. | ||
|
||
For more information, see `Auto Scaling groups <https://docs.aws.amazon.com/autoscaling/ec2/userguide/AutoScalingGroup.html>`__ in the *Amazon EC2 Auto Scaling User Guide*. | ||
|
||
**Example 7: To specify a termination lifecycle hook** | ||
|
||
This example creates an Auto Scaling group with a lifecycle hook that supports a custom action at instance termination. :: | ||
|
||
aws autoscaling create-auto-scaling-group \ | ||
--cli-input-json file://~/config.json | ||
|
||
Contents of ``config.json``:: | ||
|
||
{ | ||
"AutoScalingGroupName": "my-asg", | ||
"LaunchTemplate": { | ||
"LaunchTemplateId": "lt-1234567890abcde12" | ||
}, | ||
"LifecycleHookSpecificationList": [{ | ||
"LifecycleHookName": "my-termination-hook", | ||
"LifecycleTransition": "autoscaling:EC2_INSTANCE_TERMINATING", | ||
"HeartbeatTimeout": 120, | ||
"DefaultResult": "CONTINUE" | ||
}], | ||
"MinSize": 1, | ||
"MaxSize": 5, | ||
"TargetGroupARNs": [ | ||
"arn:aws:elasticloadbalancing:us-west-2:123456789012:targetgroup/my-targets/73e2d6bc24d8a067" | ||
], | ||
"VPCZoneIdentifier": "subnet-5ea0c127,subnet-6194ea3b,subnet-c934b782" | ||
} | ||
|
||
This command produces no output. | ||
|
||
For more information, see `Auto Scaling groups <https://docs.aws.amazon.com/autoscaling/ec2/userguide/AutoScalingGroup.html>`__ in the *Amazon EC2 Auto Scaling User Guide*. |
Oops, something went wrong.