Automating your management tasks with Amazon OpsHub
You can use Amazon OpsHub to automate operational tasks that you perform frequently on your Snowball Edge. You can create a task for reoccurring actions that you might want to perform on resources, such as restarting virtual servers, stopping Amazon EC2-compatible instances, and so on. You provide an automation document that safely performs operational tasks and runs the operation on Amazon resources in bulk. You can also schedule common IT workflows.
Note
Automating tasks is not supported on clusters.
To use tasks, the Amazon EC2 Systems Manager service must be started first. For more information, see Activating Snow Device Management on a Snowball Edge.
Topics
Creating and starting a task with Amazon OpsHub
When you create a task, you specify the types of resources that the task should run on, and then provide a task document that contains the instructions that run the task. The task document is either in YAML or JSON format. You then provide the required parameters for the task and start the task.
To create a task
In the Launch tasks section of the dashboard, choose Get started to open the Tasks page. If you have created tasks, they appear under Tasks.
Choose Create task and provide details for the task.
For Name, enter a unique name for the task.
Tip
The name must be between 3 and 128 characters. Valid characters are
a-z
,A-Z
,0-9
,.
,_
, and-
.Optionally, you can choose a target type from the Target type-optional list. This is the type of resource that you want the task to run on.
For example, you can specify
/AWS::EC2::Instance
for the tasks to run on an Amazon EC2-compatible instance or/
to run on all resource types.In the Content section, choose YAML or JSON, and provide the script that performs the task. You have two options, YAML or JSON format. For examples, see Task examples in Amazon OpsHub.
-
Choose Create. The task that you created then appears on the Tasks page.
To start a task
In the Launch tasks section of the dashboard, choose Get started to open the Tasks page. Your tasks appear under Tasks.
Choose your task to open the Start task page.
-
Choose Simple execution to run on targets.
Choose Rate control to run safely on multiple targets and define concurrency and error thresholds. For this option, you provide the additional target and error threshold information in the Rate control section.
Provide the required input parameters, and choose Start task.
The status of the task is Pending, and changes to Success when the task has run successfully.
Task examples in Amazon OpsHub
The following example restarts an Amazon EC2-compatible instance. It requires two input
parameters: endpoint
and instance ID
.
YAML example
description: Restart EC2 instance schemaVersion: '0.3' parameters: Endpoint: type: String description: (Required) EC2 Service Endpoint URL Id: type: String description: (Required) Instance Id mainSteps: - name: restartInstance action: aws:executeScript description: Restart EC2 instance step inputs: Runtime: python3.7 Handler: restart_instance InputPayload: Endpoint: "{{ Endpoint }}" Id: "{{ Id }}" TimeoutSeconds: 30 Script: |- import boto3 import time def restart_instance(payload, context): ec2_endpoint = payload['Endpoint'] instance_id = payload['Id'] ec2 = boto3.resource('ec2', endpoint_url=ec2_endpoint) instance = ec2.Instance(instance_id) if instance.state['Name'] != 'stopped': instance.stop() instance.wait_until_stopped() instance.start() instance.wait_until_running() return {'InstanceState': instance.state}
JSON example
{ "description" : "Restart EC2 instance", "schemaVersion" : "0.3", "parameters" : { "Endpoint" : { "type" : "String", "description" : "(Required) EC2 Service Endpoint URL" }, "Id" : { "type" : "String", "description" : "(Required) Instance Id" } }, "mainSteps" : [ { "name" : "restartInstance", "action" : "aws:executeScript", "description" : "Restart EC2 instance step", "inputs" : { "Runtime" : "python3.7", "Handler" : "restart_instance", "InputPayload" : { "Endpoint" : "{{ Endpoint }}", "Id" : "{{ Id }}" }, "TimeoutSeconds" : 30, "Script" : "import boto3\nimport time\ndef restart_instance(payload, context):\n ec2_endpoint = payload['Endpoint']\n instance_id = payload['Id']\n ec2 = boto3.resource('ec2', endpoint_url=ec2_endpoint)\n instance = ec2.Instance(instance_id)\n if instance.state['Name'] != 'stopped':\n instance.stop()\n instance.wait_until_stopped()\n instance.start()\n instance.wait_until_running()\n return {'InstanceState': instance.state}" } } ] }
Viewing details of a task in Amazon OpsHub
You can view details of a management task, such as the description and the parameters that are required to run the task.
To view details of a task
In the Launch tasks section of the dashboard, choose Get started to open the Tasks page.
On the Tasks page, locate and choose the task that you want to see details of.
Choose View details, and choose one of the tabs to see the details. For example, the Parameters tab shows you the input parameters in the script.
Deleting a task in Amazon OpsHub
Follow these steps to delete a management task.
To delete a task
-
In the Launch tasks section of the dashboard, choose Get started to open the Tasks page.
-
Locate the task that you want to delete. Choose the task, and then choose Delete.