This topic provides samples of using basic commands of Alibaba Cloud Command Line Interface (CLI). You can run commands based on these samples.

Initialize Alibaba Cloud CLI

Run the following command to configure Alibaba Cloud CLI by using your AccessKey ID and AccessKey secret so that Alibaba Cloud CLI can access your Alibaba Cloud resources:

aliyun configure
aliyun Access Key ID [None]: xxxxx
aliyun Access Key Secret [None]: xxxxx
Default Region Id [None]: cn-hangzhou # The ID of the region.
Default Output Format [json]: json (Only supports JSON) # Only the JSON format is supported.
Default Language [zh|en]: en # Select en to use English as the default language.

For more information about Alibaba Cloud regions, see Regions and zones.

Create an ECS instance

aliyun ecs CreateInstance \
    --InstanceName myvm1 \
    --ImageId centos_7_03_64_40G_alibase_20170625.vhd \
    --InstanceType ecs.n4.small \
    --SecurityGroupId sg-xxxxxx123 \ # The ID of the security group.
    --VSwitchId vsw-xxxxxx456 \ # The ID of the VSwitch.
    --InternetChargeType PayByTraffic
    --Password xxx # The password for logging on to the instance. You can also specify a Secure Shell (SSH) key pair for logging on to the instance.

Allocate an IP address to an ECS instance

aliyun ecs AllocatePublicIpAddress --InstanceId i-xxxxxx789 --InternetMaxBandwidthOut 1

Check the status of an ECS instance and modify its attributes

aliyun ecs DescribeInstances --InstanceName myvm1
aliyun ecs DescribeInstanceAttribute --InstanceId i-xxxxxx789
aliyun ecs ModifyInstanceAttribute   --InstanceId i-xxxxxx789 --Password xxx

Start, stop, and delete an ECS instance

aliyun ecs StartInstance --InstanceId i-xxxxxx789
aliyun ecs StopInstance --InstanceId i-xxxxxx789
aliyun ecs DeleteInstance --InstanceId i-xxxxxx789