Alibaba Cloud CLI is a general-purpose command-line tool that is developed based on the OpenAPI Specification. You can use Alibaba Cloud CLI to implement automated management and maintenance of Cloud Firewall resources. In this topic, the DescribeNatFirewallList
operation is used as an example to describe how to call the API operations of Cloud Firewall by using Alibaba Cloud CLI. The DescribeNatFirewallList operation is used to query the details of NAT firewalls.
Before you begin
Get yourself familiar with Alibaba Cloud CLI. For more information, see What is Alibaba Cloud CLI?
Install Alibaba Cloud CLI
Before you can use Alibaba Cloud CLI, you must install Alibaba Cloud CLI. You can install Alibaba Cloud CLI on the Windows, Linux, and macOS operating systems. You must select an installation package for Alibaba Cloud CLI based on the operating system of your device. For more information, see the following topics:
You can also use Cloud Shell provided by Alibaba Cloud to debug the commands that you want to run in Alibaba Cloud CLI. For more information about Cloud Shell, see What is Cloud Shell?
Configure Alibaba Cloud CLI
An Alibaba Cloud account has the permissions to manage and access the APIs of all Alibaba Cloud services. If you use an Alibaba Cloud account to call API operations, security risks may arise. We recommend that you create a Resource Access Management (RAM) identity, grant the required permissions to the RAM identity based on the principle of least privilege, and then use the RAM identity to call API operations. For more information about the policies supported by Cloud Firewall, see System policies and Custom policies.
Before you use Alibaba Cloud CLI, you must configure information such as identity credentials and region IDs in Alibaba Cloud CLI. Alibaba Cloud CLI supports various types of identity credentials. For more information, see Credential types. In this example, AccessKey pairs are used as identity credentials.
Create a RAM user and create an AccessKey pair for the RAM user to configure identity credentials. For more information, see Create a RAM user and Create an AccessKey pair.
Grant the required permissions to the RAM user. In this example, the
AliyunYundunCloudFirewallReadOnlyAccess
policy is attached to the RAM user. The policy grants the read-only permissions on Cloud Firewall. For more information, see Grant permissions to a RAM user.Obtain the ID of the region that you want to use. Alibaba Cloud CLI uses the region ID that you specify to initiate API calls. For more information about the regions supported by Cloud Firewall, see Endpoints.
NoteWhen you use Alibaba Cloud CLI, you can use the
--region
option to specify the region from which you want to initiate a call. If you use the option to specify a region, Alibaba Cloud CLI ignores the region information in the default credential settings and environment variables. For more information, see Command line options for API calls.Use the AccessKey pair of the RAM user to configure identity credentials in the
AkProfile
configuration file. For more information, see Configuration examples.
Generate a sample CLI command
In OpenAPI Explorer, call the DescribeNatFirewallList operation.
On the Parameters tab, configure the parameters. Then, click the CLI Example tab to view the generated sample CLI command.
Copy the CLI command or debug the CLI command in Cloud Shell.
Click the icon to start Cloud Shell and debug the CLI command in Cloud Shell.
Click the icon to copy the CLI command to the clipboard. You can also paste the CLI command into your on-premises shell to run the command.
NoteWhen you paste the CLI command into your on-premises shell for debugging, take note of the parameter formats. For more information about the parameter formats required by Alibaba Cloud CLI, see Parameter formats.
By default, OpenAPI Explorer adds the
--region
option to the generated CLI command. When you copy the command to your on-premises shell, Alibaba Cloud CLI ignores the region information in the default identity credential settings and environment variables, and runs the command in the region specified by the option. You can delete or retain the option based on your business requirements.
Call the API operations of Cloud Firewall
Example 1: Query the supported API operations of Cloud Firewall by using Alibaba Cloud CLI
The following sample code provides an example on how to use the --help
option to query the supported API operations of Cloud Firewall. You can view the supported API operations. For more information, see List of operations by function.
Run the following command:
aliyun cloudfw --help
View the output.
Example 2: Query the details of NAT firewalls
The following sample code provides an example on how to use Alibaba Cloud CLI to call the DescribeNatFirewallList
operation of Cloud Firewall. The operation is used to query the details of NAT firewalls.
Run the following command:
aliyun cloudfw DescribeNatFirewallList \ --region cn-hangzhou \ --Lang zh \ --PageNo 1 \ --PageSize 10 \ --ProxyId 'proxy-nat97a******' \ --RegionNo 'cn-hangzhou'
View the output.
{ "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" } ] } ] }
NoteIf an error is returned after you call an API operation of Cloud Firewall, check whether the input parameters and values are valid based on the error code.
You can also use Alibaba Cloud OpenAPI Diagnostics to perform self-service diagnostics based on the returned request ID or SDK error information.