Unlock the Power of AI

1 million free tokens

88% Price Reduction

NaNDayNaN:NaN:NaN
Activate Now

Use Alibaba Cloud CLI to manage ROS

Updated at: 2024-09-02 05:25

Alibaba Cloud CLI is a command-line tool that allows you to call Alibaba Cloud API operations in a terminal or on a command-line interface to create, configure, and manage Alibaba Cloud resources. This topic describes how to use Alibaba Cloud CLI to call ROS API operations to manage 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.

    You can install Alibaba Cloud CLI on Windows, Linux, and macOS. Download an installation package that is suitable for the OS that runs on your computer. For more information about how to install Alibaba Cloud CLI on different OSs, see the following topics:

  2. Configure Alibaba Cloud CLI.

    Configure information that is required to call ROS resources. The information includes the credential, region, and language. For more information about how to configure the 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, you can use the following syntax to run commands 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. Go to the ROS API debugging page 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

    image

Usage examples

The following section provides examples on how to use Alibaba Cloud CLI to call ROS API operations.

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

  • In the examples, only part of ROS API operations are called. For more information about ROS API operations, 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"
    }
  • On this page (1, T)
  • Use Alibaba Cloud CLI
  • Install and configure Alibaba Cloud CLI
  • Use Alibaba Cloud CLI to call ROS API operations
  • Usage examples
  • Create a custom template
  • Query a resource type
  • Create a stack
  • Query the information about a change set
Feedback
phone Contact Us

Chat now with Alibaba Cloud Customer Service to assist you in finding the right products and services to meet your needs.

alicare alicarealicarealicare