Appendix I: Ops Automator scenarios - Ops Automator

Appendix I: Ops Automator scenarios

Ops Automator includes templates in the TaskConfiguration/ScenarioTemplates folder that implement end-to-end scenarios.

Vertical Scaling

The vertical scaling template sets up two tasks for vertical scaling. The Ops Automator’s handler AWS Lambda function retrieves the configuration for the CPU metrics task from Amazon DynamoDB and runs that task at a defined interval. The CPU metrics task checks the CPU utilization metrics of your Amazon Elastic Compute Cloud (Amazon EC2) instances against thresholds you define during deployment. When CPU utilization is below the low threshold, the instance is tagged to be scaled down. When utilization is above the high threshold, the instance is tagged to be scaled up. If utilization is within both thresholds, the instance is not changed.

Once an instance is tagged, the solution triggers the vertical scaling task to resize an existing instance, or replace the instance with a new instance with a different size, depending on which configuration you choose. You can specify a range of instance types for resizing.


        Ops Automator solution architectural overview

Figure 4: Ops Automator vertical scaling process

Scaling Method

This solution includes two methods for scaling: resizing your existing instance or replacing your instance with a new instance of a different size. When you specify a vertical scaling method, the solution creates the applicable task (resize or replace).

Resizing an Existing Instance

When you choose to resize your existing instances, the solution automatically stops your existing instance, resizes the instance to the next defined size up or the next defined size down, then starts the instance again.

During the resizing, Amazon Elastic Block Store (Amazon EBS) volumes on the instance will remain attached and the data will persist. However, any data on the ephemeral storage of your instance will be lost. To keep your data, it must be stored on an attached Amazon EBS volume.

This approach may be best for applications that can experience downtime, and use cases where the data on volumes must be preserved.

You can choose to resize your instances by type or by step using the Resizing mode AWS CloudFormation template parameter. When you choose to resize by type, the solution resizes your instance with a type you specify in the New instance type(s) parameter. We recommend you specify more than one type in this parameter to provide an alternative if the specified type is not available. When you choose to resize by step, the solution resizes your instance with the next defined size up or down in a range you specify in the Scaling Range parameter.

Replacing with a New Instance of a Different Size

When you choose to replace your existing instance with a new instance of a different size, the solution automatically launches a new instance with the same Amazon Machine Image and settings that is the next defined size up or the next defined size down. The solution is integrated with Elastic Load Balancing to automatically register (classic load balancers and application load balancers) the new instance with the same load balancer or target group.

Amazon EBS volumes on the original instance will be deleted, so any data on those volumes will be lost.

This approach may be best for applications that cannot experience downtime, and use cases where the data on volumes does not need to be preserved.

You can choose to replace your instances by type or by step using the Replacement mode AWS CloudFormation template parameter. When you choose to replace by type, the solution replaces your instance with a new instance with a type you specify in the New instance type(s) parameter. We recommend you specify more than one type in this parameter to provide an alternative if the specified type is not available. When you choose to replace by step, the solution replaces your instance with a new instance that is the next defined size up or down in a range you specify in the Scaling Range parameter.

Scaling Range

You must specify at least two valid Amazon EC2 instance types, and the instances types for the Scaling Range must be compatible. For more information, refer to Compatibility for Resizing Instances in the Amazon EC2 User Guide for Linux Instances.

The solution will not scale to instances that are not within the defined range. If an instance that exceeds the high threshold is at the top of the instance type range, the solution will not scale the instance and a message will be logged in Amazon CloudWatch. If an instance that falls below the low threshold is at the bottom of the range, the solution will not scale the instance and a message will be logged in CloudWatch.

Assumed Instance Type

You can use the Assumed Type AWS CloudFormation parameter to specify an instance type to use for instances that are not within the range you define. This instance type is used as the basis for scaling.

For example, a customer might specify a range of t2.micro, t2.small, and t2.medium, and an assumed type of t2.small. If that customer has a t3.small instance that exceeds the high threshold, the solution will use t2.small as the original instance type and scale the instance to t2.medium.

If you do not specify an assumed type, the solution logs an error in Amazon CloudWatch when it has to scale an instance that is not within the range you defined.

Launch the Vertical Scaling Template

Note

If you used the ActionsConfiguration.html file to launch the template, continue to step 7. For more information on the file, refer to Role and Task Templates.

  1. In the primary account’s Amazon S3 console, navigate to the bucket for the Ops Automator solution stack.

    Note

    You can find the name of the S3 bucket in the AWS CloudFormation stack Outputs tab. The bucket name is value of the ConfigurationBucketName key.

  2. In the TaskConfiguration/ScenarioTemplates folder, select the Ec2VerticalScaling AWS CloudFormation template.

  3. Copy the Link value.

  4. In the AWS CloudFormation console, select Create Stack.

  5. Select Specify an Amazon S3 template URL.

  6. Paste the template link into the text box and select Next.

  7. Enter a Stack name.

    Note

    This name will also be the name of the scaling plan that is used to tag Amazon EC2 instances for scaling.

  8. Under Parameters, review the parameters for the template and modify them as necessary.

    Parameter Default Description
    Ops Automator Stack <stackname> The name of the Ops Automator AWS CloudFormation stack. This parameter is auto-populated with the name you chose for your Ops Automator stack.
    Scaling Interval 5 Specify how often, in minutes, to check CPU utilization metrics.
    Scaling Method replace Choose whether to restart your instances with a new size, or replace your instance with a new, resized instance. Select resize or replace.
    Instance Types t2.micro, t2.small, t2.medium, t2.large

    A comma-delimited list of valid, compatible instance types.

    Note

    The list must be sorted from smallest to largest and must contain at least two instance types.

    Assume Type t2.small

    The default instance type that will be used if the instance type of an existing instance is not within the range defined in the Instance Types parameter.

    Note

    You must specify an instance type that is specified in the Instance Types parameter.

    CPU High Utilization Threshold 90 The high threshold for average CPU utilization that will determine whether an instance is scaled up.
    CPU Low Utilization Threshold 10 The low threshold for average CPU utilization that will determine whether an instance is scaled down.
    Instance Tags LastScalingAction=Instance scaled from type {org-instance-type} to type {new-instance-type} at {iso-datetime} by task {task} in Ops Automator stack {stack} Tags to set on the resized Amazon EC2 instance.
    Account List <Optional input>

    A comma-delimited list of account IDs for instance resizing.

    Note

    You must enable the Ec2TagCpuInstance, Ec2ReplaceInstance, and Ec2ResizeInstance actions in the cross-account role in each account. For more information, refer to Task Execution Across Accounts.

    Region List <Optional input>

    A comma-delimited list of AWS Regions for instance resizing.

    Note

    You must launch the event forwarder stack in each applicable Region. For more information, refer to Task Execution Across Accounts.

    Detailed Logging No Choose whether to generate detailed Amazon CloudWatch logs.
  9. Select Next.

  10. Select Next. Then, on the Review page, review and confirm the settings. Be sure to check the box acknowledging that the template will create AWS Identity and Access Management (IAM) resources.

  11. Choose Create to deploy the stack.

  12. After the stack is created, add the Scaling=<vertical-scaling-stackname> tag to applicable instances.