Use Alibaba Cloud CLI to manage ROS

Updated at:

Alibaba Cloud CLI is a command-line tool that allows you to call Alibaba Cloud API operations in a terminal to create, configure, and manage cloud resources. You can use Alibaba Cloud CLI to call ROS API operations to manage Resource Orchestration Service (ROS).

Note

For more information about Alibaba Cloud CLI, see What is Alibaba Cloud CLI?

Use Alibaba Cloud CLI

Install and configure Alibaba Cloud CLI

  1. Install Alibaba Cloud CLI.

    Alibaba Cloud CLI supports Windows, Linux, and macOS. For installation instructions, see the following topics:

  2. Configure Alibaba Cloud CLI.

    Configure the credential, region, and language required to access ROS resources. For more information, see Identity credential types.

    Important

    To ensure the security of your Alibaba Cloud account, we recommend that you create a Resource Access Management (RAM) user that is used only for API calls and create an AccessKey pair for the RAM user. For more information, see Identity management.

Use Alibaba Cloud CLI to call ROS API operations

After you install and configure Alibaba Cloud CLI, run commands in the following syntax to call ROS API operations:

For more information about the command syntax, see Syntax.

aliyun ros <API operation name> --<Parameter 1 Value 1> --<Parameter 2 Value 2> ...

Use OpenAPI Explorer to generate a CLI command for an API operation

  1. Log on to the ROS API portal in OpenAPI Explorer.

  2. Select the API operation for which you want to generate a CLI command and specify parameters.

  3. Click the CLI Example tab in the right of the page to view the CLI command that is generated together with the specified parameters.

    aliyun ros CreateStack --region cn-hangzhou --RegionId 'cn-hangzhou' --StackName stack_name

Usage examples

The following examples show how to call common ROS API operations by using Alibaba Cloud CLI.

Important
  • The sample requests are for reference only. Modify the CLI commands based on your business requirements.

  • Only some ROS API operations are demonstrated here. For the full list, see List of API operations by function.

Create a custom template

Call the CreateTemplate operation to create a custom template named MyTemplate. In this example, the template content is used to create a virtual private cloud (VPC).

Parameter

Description and sample value

TemplateName

The template name. Sample value: MyTemplate.

TemplateBody

The template content, which is used to create a VPC in this section. Sample value:

ROSTemplateFormatVersion: '2015-09-01'
Resources:
  VPC:
    Type: ALIYUN::ECS::VPC
    Properties:
      VpcName: myvpc
      CidrBlock: 192.168.0.0/16
  • Sample request:

    aliyun ros CreateTemplate --TemplateName MyTemplate --TemplateBody "ROSTemplateFormatVersion: '2015-09-01' Resources: VPC: Type: ALIYUN::ECS::VPC Properties: VpcName: myvpc CidrBlock: 192.168.0.0/16"
  • Sample response:

    {
            "RequestId": "24C1BF0F-F65A-45CA-9612-53D0C11BC539",
            "TemplateId": "4237d4b9-31cc-45aa-9c11-6836b2fd****"
    }

Query a resource type

Call the GetResourceType operation to query the information about a resource type. In this example, the ALIYUN::ECS::VPC resource type is queried.

Parameter

Description and sample value

ResourceType

The resource type. Sample value: ALIYUN::ECS::VPC.

  • Sample request:

    aliyun ros GetResourceType --ResourceType ALIYUN::ECS::VPC
  • Sample response:

    {
            "Attributes": {
                    "RouteTableId": {
                            "Description": "The router table id of created VPC."
                    },
                    "VRouterId": {
                            "Description": "Router id of created VPC."
                    },
                    "VpcId": {
                            "Description": "Id of created VPC."
                    }
            },
            "ResourceType": "ALIYUN::ECS::VPC",
            "RequestId": "8A897F64-6A61-446A-A913-30CA572EE181",
            "Properties": {
                    "CidrBlock": {
                            "Required": false,
                            "Description": "The IP address range of the VPC in the CIDR block form. You can use the following IP address ranges and their subnets:\n10.0.0.0/8\n172.16.0.0/12 (Default)\n192.168.0.0/16",
                            "Immutable": true,
                            "Type": "string",
                            "Constraints": [
                                    {
                                            "CustomConstraint": "vpc.cidr"
                                    }
                            ],
                            "UpdateAllowed": false
                    },
                    "VpcName": {
                            "Required": false,
                            "Description": "Display name of the vpc instance, [2, 128] English or Chinese characters, must start with a letter or Chinese in size, can contain numbers, '_' or '.', '-'",
                            "Immutable": false,
                            "Type": "string",
                            "Constraints": [
                                    {
                                            "CustomConstraint": "ecs.name"
                                    }
                            ],
                            "UpdateAllowed": false
                    },
                    "Description": {
                            "Required": false,
                            "Description": "Description of the vpc, [2, 256] characters. Do not fill or empty, the default is empty.",
                            "Immutable": false,
                            "Type": "string",
                            "Constraints": [
                                    {
                                            "CustomConstraint": "ecs.description"
                                    }
                            ],
                            "UpdateAllowed": false
                    },
                    "ResourceGroupId": {
                            "Description": "Resource group id.",
                            "Required": false,
                            "Immutable": false,
                            "Type": "string",
                            "UpdateAllowed": false
                    }
            }
    }

Create a stack

Call the CreateStack operation to create a stack. In this example, a stack named MyStack is created in the China (Hangzhou) region based on an existing template. The timeout period for creating the stack is 10 minutes.

Parameter

Description and sample value

RegionId

The region ID. Sample value: cn-hangzhou.

StackName

The stack name. Sample value: MyStack.

TimeoutInMinutes

The timeout period for creating the stack. Sample value: 10.

TemplateURL

The path of the existing template. Sample value: oss://ros-template/demo.

  • Sample request:

     aliyun ros CreateStack --RegionId cn-hangzhou --StackName MyStack --TimeoutInMinutes 10 --TemplateURL oss://ros-template/demo
  • Sample response:

    {
            "StackId": "c18d62d8-51ce-4e8e-b8f6-e00be431****",
            "RequestId": "53C2DB3A-8374-4464-9466-952614EEC159"
    }

Query the information about a change set

Call the GetChangeSet operation to query the information about a change set. In this example, the change set whose ID is 1f6521a4-05af-4975-afe9-bc4b45ad**** in the China (Hangzhou) region, and the template are queried.

Parameter

Description and sample value

RegionId

The region ID. Sample value: cn-hangzhou.

ChangeSetId

The ID of the change set. Sample value: 1f6521a4-05af-4975-afe9-bc4b45ad****.

ShowTemplate

Specifies whether to query the template. Sample value: true.

  • Sample request:

    aliyun ros GetChangeSet --RegionId cn-hangzhou --ChangeSetId 1f6521a4-05af-4975-afe9-bc4b45ad**** --ShowTemplate true
  • Sample response:

    {
        "ExecutionStatus": "AVAILABLE",
        "Parameters": [{
                "ParameterValue": "342546988786****",
                "ParameterKey": "ALIYUN::AccountId"
            },
            {
                "ParameterValue": "None",
                "ParameterKey": "ALIYUN::NoValue"
            },
            {
                "ParameterValue": "cn-beijing",
                "ParameterKey": "ALIYUN::Region"
            },
            {
                "ParameterValue": "c18d62d8-51ce-4e8e-b8f6-e00be431****",
                "ParameterKey": "ALIYUN::StackId"
            },
            {
                "ParameterValue": "MyStack",
                "ParameterKey": "ALIYUN::StackName"
            },
            {
                "ParameterValue": "sg-bfwb3h3eosga1tj5****",
                "ParameterKey": "SecurityGroupId"
            }
        ],
        "Changes": [{
            "Type": "Resource",
            "ResourceChange": {
                "LogicalResourceId": "WebServer",
                "ResourceType": "ALIYUN::ECS::Instance",
                "Action": "Add",
                "Details": [],
                "Scope": []
            }
        }],
        "Description": "It is a demo.",
        "TimeoutInMinutes": 12,
        "ChangeSetId": "1f6521a4-05af-4975-afe9-bc4b45ad****",
        "StackId": "c18d62d8-51ce-4e8e-b8f6-e00be431****",
        "DisableRollback": false,
        "ChangeSetName": "MyChangeSet",
        "ChangeSetType": "CREATE",
        "StackName": "MyStack",
        "Status": "CREATE_COMPLETE",
        "TemplateBody": "{\"ROSTemplateFormatVersion\":\"2015-09-01\",\"Parameters\":{\"SecurityGroupId\":{\"Type\":\"String\"}},\"Resources\":{\"WebServer\":{\"Type\":\"ALIYUN::ECS::Instance\",\"Properties\":{\"ImageId\":\"centos_7\",\"InstanceType\":\"ecs.c6.large\",\"SecurityGroupId\":{\"Ref\":\"SecurityGroupId\"}}}},\"Outputs\":{\"InstanceId\":{\"Value\":{\"Fn:GetAtt\":[\"WebServer\",\"InstanceId\"]}},\"PublicIp\":{\"Value\":{\"Fn:GetAtt\":[\"WebServer\",\"PublicIp\"]}}}}",
        "RequestId": "A46D85A6-9C8E-4603-9989-1FF3F91512F6",
        "RegionId": "cn-beijing",
        "CreateTime": "2019-09-05T14:39:31"
    }

Related documentation

You can use command-line options to modify the default behavior of commands or add functionality. For more information, see Command-line options.