Run an automation on Azure or Google Cloud resources (command line)
The following procedure describes how to use the AWS CLI (on Linux or Windows) or
AWS Tools for PowerShell to run an automation on Microsoft Azure or Google
Cloud resources that a Cloud Connector can reach. The automation uses a single
target whose Key is CloudConnector and whose value is a JSON
object. To avoid nested quoting on the command line, keep the JSON in a file.
To run an automation on Azure or Google Cloud resources
Install and configure the AWS CLI or the AWS Tools for PowerShell, if you haven't already.
For information, see Installing or updating the latest version of the AWS CLI and Installing the AWS Tools for PowerShell.
-
Example 1: Azure resources
Create a file named
azure-target.jsonthat describes the connector and the filters. This example finds running and stopped virtual machines (VMs) in one subscription and resource group that have the tagEnv=prod. Replace the connector ID, subscription ID, and resource group name with your own.{ "CloudConnectorId": "a1b2c3d4-5678-90ab-cdef-EXAMPLE11111", "AzureSubscriptions": ["11111111-2222-3333-4444-555555555555"], "AzureResourceGroups": ["my-resource-group"], "AzureTag": { "Key": "Env", "Value": "prod" }, "AzureVmPowerStates": ["RUNNING", "STOPPED", "DEALLOCATED"] }For the AWS CLI on Linux, macOS, or Windows, create a file named
start-azure.jsonwith the full request. The target value is theazure-target.jsonobject as a JSON string.{ "DocumentName": "AWS-InstallDistributorPackageOnAzure", "Targets": [ { "Key": "CloudConnector", "Values": ["{\"CloudConnectorId\":\"a1b2c3d4-5678-90ab-cdef-EXAMPLE11111\",\"AzureSubscriptions\":[\"11111111-2222-3333-4444-555555555555\"],\"AzureResourceGroups\":[\"my-resource-group\"],\"AzureTag\":{\"Key\":\"Env\",\"Value\":\"prod\"},\"AzureVmPowerStates\":[\"RUNNING\",\"STOPPED\",\"DEALLOCATED\"]}"] } ], "TargetParameterName": "AzureVmResourceId", "MaxConcurrency": "10", "MaxErrors": "1", "Parameters": { "AutomationAssumeRole": ["arn:aws:iam::111122223333:role/service-role/SSM-AzureAssumeRole-MyConnector-a1b2c3d4"], "CloudConnector": ["a1b2c3d4-5678-90ab-cdef-EXAMPLE11111"], "PackageName": ["MyPackage"] } }Run the following command.
-
Example 2: Google Cloud resources
For Google Cloud, replace
MyGcpRunbookwith your own runbook andInstanceIdwith the runbook input that receives each VM ID. Create a file namedgcp-target.jsonthat describes the connector, the projects, the zones, and the labels to include. Replace the connector ID, project ID, and zone with your own.{ "CloudConnectorId": "a1b2c3d4-5678-90ab-cdef-EXAMPLE11111", "GcpProjects": ["my-project"], "Zones": ["us-central1-a"], "IncludesLabels": { "env": "prod" } }For the AWS CLI on Linux, macOS, or Windows, create a file named
start-gcp.jsonwith the full request.{ "DocumentName": "MyGcpRunbook", "Targets": [ { "Key": "CloudConnector", "Values": ["{\"CloudConnectorId\":\"a1b2c3d4-5678-90ab-cdef-EXAMPLE11111\",\"GcpProjects\":[\"my-project\"],\"Zones\":[\"us-central1-a\"],\"IncludesLabels\":{\"env\":\"prod\"}}"] } ], "TargetParameterName": "InstanceId", "MaxConcurrency": "10", "MaxErrors": "1", "Parameters": { "AutomationAssumeRole": ["arn:aws:iam::111122223333:role/service-role/SSM-GCPAssumeRole-MyConnector-a1b2c3d4"], "CloudConnector": ["a1b2c3d4-5678-90ab-cdef-EXAMPLE11111"] } }Run the following command.
The command returns the execution ID of the parent automation.
View the results
To list the child automations that the parent automation started, run the following
command. Replace parent execution ID with the execution ID
that the start-automation-execution command returned.
aws ssm describe-automation-executions \ --filters Key=ParentExecutionId,Values=parent execution ID
To view the resources that the Cloud Connector target resolved, run the following
command. Replace parent execution ID with your own
information.
aws ssm get-automation-execution \ --automation-execution-idparent execution ID
In the response, ResolvedTargets.ParameterValues holds at most the first
500 resource IDs, and Truncated is true when the target found
more.