Alibaba Cloud CLI is a command-line tool built on the OpenAPI Specification. Use it to automate Cloud Firewall resource management without leaving your terminal.
This topic uses the DescribeNatFirewallList operation as an example to show how to call Cloud Firewall API operations from the CLI. DescribeNatFirewallList queries the details of NAT firewalls.
Prerequisites
Before you begin, ensure that you have:
Reviewed What is Alibaba Cloud CLI?
A device running Windows, Linux, or macOS
Install Alibaba Cloud CLI
Install Alibaba Cloud CLI for your operating system:
Alternatively, use Cloud Shell to run and debug CLI commands directly in your browser without a local installation. For details, see What is Cloud Shell?
Configure Alibaba Cloud CLI
An Alibaba Cloud account has full access to all API operations, which poses security risks. Instead, create a Resource Access Management (RAM) identity, grant it the minimum required permissions, and use it to call API operations. For the policies supported by Cloud Firewall, see System policies and Custom policies.
Alibaba Cloud CLI requires identity credentials and a region ID. This example uses AccessKey pairs as credentials. For other supported credential types, see Credential types.
Create a RAM user and generate an AccessKey pair for it. See Create a RAM user and Create an AccessKey pair.
Attach the
AliyunYundunCloudFirewallReadOnlyAccesspolicy to the RAM user to grant read-only access to Cloud Firewall. See Grant permissions to a RAM user.Get the region ID for the region where you want to make API calls. For supported regions, see Endpoints.
NoteUse the
--regionoption to specify a region at the command level. When set, it overrides any region defined in your default credentials or environment variables. For details, see Command line options.Configure the AccessKey pair as identity credentials in the
_AkProfile_configuration file. See Configuration examples.
Generate a sample CLI command
Use OpenAPI Explorer to get a ready-to-run CLI command for any Cloud Firewall API operation.
Open DescribeNatFirewallList in OpenAPI Explorer.
On the Parameters tab, fill in the parameters. Then click the CLI Example tab to view the generated command.
Copy or run the command:
Click
to copy the command to your clipboard. Paste it into your local shell to run it.Click
to open Cloud Shell and debug the command in your browser.
NoteOpenAPI Explorer adds the
--regionoption to generated commands by default. When you run the command locally, this overrides your default credential region. Keep or remove the option based on your needs. For parameter format requirements, see Parameter formats.

Call Cloud Firewall API operations
Example 1: List available API operations
Use the --help option to see all API operations supported by Cloud Firewall.
aliyun cloudfw --helpThe output lists all available operations and their descriptions. For the complete list, see List of operations by function.

Example 2: Query NAT firewall details
Use the DescribeNatFirewallList operation to retrieve details of your NAT firewalls.
Run the following command:
aliyun cloudfw DescribeNatFirewallList \ --region cn-hangzhou \ --Lang zh \ --PageNo 1 \ --PageSize 10 \ --ProxyId 'proxy-nat97a******' \ --RegionNo 'cn-hangzhou'Verify the output. A successful response contains a
RequestIdand aNatFirewallListarray:{ "TotalCount": 10, "RequestId": "15FCCC52-1E23-57AE-B5EF-3E00A3******", "NatFirewallList": [ { "MemberUid": 0, "AliUid": 0, "ProxyId": "proxy-nat97a******", "ProxyName": "Test NAT firewall", "ProxyStatus": "normal", "RegionId": "cn-hangzhou", "NatGatewayId": "ngw-uf6tnblxip4qcxg******", "NatGatewayName": "Test NAT gateway", "VpcId": "vpc-2ze26ya******", "VpcName": "Test VPC", "ErrorDetail": "Failed to create the firewall", "StrictMode": 0, "NatRouteEntryList": [ { "RouteTableId": "vtb-bp18o0gb******", "NextHopId": "ngw-2ze0s284r9atg5******", "NextHopType": "NatGateway", "DestinationCidr": "0.0.0.0/0" } ] } ] }
Troubleshooting
If an API call returns an error, check your input parameters and values against the error code.
For self-service diagnostics, use Alibaba Cloud OpenAPI Diagnostic Platform with the RequestId from the error response.
What's next
Browse all available Cloud Firewall API operations: List of operations by function
Learn about supported parameter formats: Parameter formats