> For the complete documentation index, see [llms.txt](https://docs.console.zenlayer.com/zenlayer-cli/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.console.zenlayer.com/zenlayer-cli/usage/examples.md).

# Example Commands

This guide provides common operation example commands for Zenlayer Cloud CLI to help you quickly get started with managing Zenlayer Cloud resources.

## Configuration Examples

### 1. Configure the CLI

```bash
# Interactive configuration
zeno configure

# View current configuration
zeno configure list

# Get a specific configuration value
zeno configure get output

# Set a specific configuration value
zeno configure set output table
```

### 2. Using Different Profiles

```bash
# Use the prod profile
zeno --profile prod zec describe-instances

# Specify profile using environment variable
export ZENLAYER_PROFILE=dev
zeno zec describe-instances
```

## Cloud Server (ZEC) Examples

### 1. Create Cloud Server Instances

```bash
# Create a cloud server instance
zeno zec create-zec-instances \
  --instance-type zec.s1.small \
  --count 1 \
  --region-id asia-east-1 \
  --image-id img-123456 \
  --name my-instance \
  --password MyPassword123!

# Create multiple cloud server instances
zeno zec create-zec-instances \
  --instance-type zec.s2.medium \
  --count 3 \
  --region-id asia-east-1 \
  --image-id img-123456 \
  --name batch-instance
```

### 2. Manage Cloud Server Instances

```bash
# List cloud server instances
zeno zec describe-instances

# View a specific cloud server instance
zeno zec describe-instances --instance-ids 123456

# Start a cloud server instance
zeno zec start-instances --instance-ids 123456

# Stop a cloud server instance
zeno zec stop-instances --instance-ids 123456

# Restart a cloud server instance
zeno zec reboot-instances --instance-ids i-123456

# Release a cloud server instance
zeno zec release-instances --instance-ids i-123456
```

### 3. Manage Cloud Server Instance Attributes

```bash
# Modify cloud server instance name
zeno zec modify-instance-attribute \
  --instance-id 123456 \
  --name new-instance-name

# Modify cloud server instance password
zeno zec modify-instance-attribute \
  --instance-id 123456 \
  --password NewPassword123!
```

## Advanced Usage Examples

### 1. Using Output Formats and Queries

```bash
# Use table format output
zeno zec describe-instances --output table

# Use JSON format output
zeno zec describe-instances --output json

# Extract specific fields
zeno zec describe-instances --query "dataSet[*].instanceId"

# Filter data
zeno zec describe-instances --query "dataSet[?status=='running']"

# Complex query
zeno zec describe-instances --query "dataSet[?zoneId=='ap-hongkong-1' && status=='running'].{ID: instanceId, Name: name}"
```

### 2. Combining with Shell Commands

```bash
# Extract all instance IDs and store in a variable
instance_ids=$(zeno zec describe-instances --query "dataSet[*].instanceId" --output json | jq -r ".[]")

# Iterate through instance IDs and view details
for instance_id in $instance_ids; do
  echo "Checking instance: $instance_id"
  zeno zec describe-instances --instance-ids $instance_id --output table
done

# Save output to a file
zeno zec describe-instances --output json > instances.json
zeno traffic describe-bandwidth-clusters --output table > bandwidth-clusters.txt
```

### 3. Using Environment Variables

```bash
# Set environment variables
export ZENLAYER_PROFILE=prod
export ZENLAYER_OUTPUT=table

# Execute commands
zeno zec describe-instances

# Temporarily override environment variables
ZENLAYER_OUTPUT=json zeno traffic describe-bandwidth-clusters
```

## Common Use Cases

### Scenario 1: Automated Cloud Server Instance Deployment

```bash
#!/bin/bash

# Set environment variables
export ZENLAYER_PROFILE=prod

# Create a cloud server instance
instance_id=$(zeno zec create-zec-instances \
  --instance-type zec.s1.small \
  --count 1 \
  --region-id asia-east-1 \
  --image-id img-123456 \
  --name auto-deploy-instance \
  --password MyPassword123! \
  --output json \
  --query "instanceIds[0]")

# Wait for instance to start
echo "Waiting for instance to start..."
sleep 60

# Check instance status
zeno zec describe-instances --instance-ids $instance_id --output table

echo "Instance deployed successfully: $instance_id"
```

### Scenario 2: Monitor Bandwidth Usage

```bash
#!/bin/bash

# Set environment variables
export ZENLAYER_PROFILE=prod

# Get all bandwidth clusters
clusters=$(zeno traffic describe-bandwidth-clusters --query "dataSet[*].clusterId" --output json | jq -r ".[]")

# Iterate through clusters and get usage
for cluster in $clusters; do
  echo "Checking bandwidth cluster: $cluster"
  zeno traffic describe-bandwidth-cluster-usage \
    --cluster-id $cluster \
    --start-time $(date -u -v-7d +"%Y-%m-%dT%H:%M:%SZ") \
    --end-time $(date -u +"%Y-%m-%dT%H:%M:%SZ") \
    --output table
done
```

### Scenario 3: Batch Resource Management

```bash
#!/bin/bash

# Set environment variables
export ZENLAYER_PROFILE=prod

# Get all stopped cloud server instances
stopped_instances=$(zeno zec describe-instances --query "dataSet[?status=='stopped'].instanceId" --output json | jq -r ".[]")

# Iterate and release stopped cloud server instances
for instance in $stopped_instances; do
  echo "Releasing stopped instance: $instance"
  zeno zec release-instances --instance-ids $instance
done
```

## Best Practices

* **Use Profiles**: Create profiles for different environments for easy switching
* **Use Output Formats**: Choose the appropriate output format based on your needs
* **Use Query Filtering**: Use the `--query` option to filter output and get only the information you need
* **Combine with Shell Commands**: Combine CLI commands with shell commands for more complex automation
* **Write Scripts**: Write commonly used operations as scripts to improve efficiency
* **Use Environment Variables**: Use environment variables to set credentials in CI/CD environments

## Related Documentation

* [Command Structure](/zenlayer-cli/usage/command-structure.md) - Learn about the basic structure of CLI commands
* [Parameter Types](/zenlayer-cli/usage/parameter-types.md) - Learn about different parameter type usage
* [Output Formats](/zenlayer-cli/usage/output.md) - Learn about different output format usage


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.console.zenlayer.com/zenlayer-cli/usage/examples.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
