Alibaba Cloud CLI lets you save multiple credential configurations. You can use the configure command and its subcommands to manage these configurations. This topic describes the command syntax and provides usage examples.
Create a profile in interactive mode
Run the aliyun configure command to create a profile in interactive mode.
Syntax
aliyun configure [--mode <AUTHENTICATE_MODE>] [--profile <PROFILE_NAME>]AUTHENTICATE_MODE: Specifies the credential type to configure. If you do not specify this parameter, an AccessKey (AK) profile is created by default.PROFILE_NAME: Specifies the profile name. If you do not specify this parameter, the current profile is modified. If the specified profile does not exist, a new profile is created.
Example
Run the following command to configure the
AkProfileprofile of the AK credential type in interactive mode:aliyun configure --mode AK --profile AkProfileInteractive process:
Configuring profile 'AkProfile' in 'AK' authenticate mode... Access Key Id []: "0wNEpMMlzy7s****" Access Key Secret []: <YOUR_ACCESS_KEY_SECRET> Default Region Id []: cn-hangzhou Default Output Format [json]: json (Only support json) Default Language [zh|en] en: en Saving profile[profile] ...Done.
Create or modify a profile in non-interactive mode
Run the aliyun configure set command to create or modify a profile in non-interactive mode.
After a profile is modified, Alibaba Cloud CLI switches to the modified profile.
Syntax
aliyun configure set [--mode <AUTHENTICATE_MODE>] [--profile <PROFILE_NAME>] [--settingName <settingValue>...]AUTHENTICATE_MODE: Specifies the credential type. If you do not specify this parameter, an AK profile is created by default.PROFILE_NAME: Specifies the profile name. If you do not specify this parameter and theALIBABA_CLOUD_PROFILEenvironment variable is not configured, the current profile is modified. If the specified profile does not exist, a new profile is created.settingName: the profile options that you want to configure. Configure the required options for the profile. Otherwise, the profile fails to be created. For more information, see Configure credentials.
Example 1: Create a file in non-interactive mode
Run the following command to configure the
AkProfileprofile of the AK credential type in non-interactive mode:aliyun configure set \ --access-key-id <yourAccessKeyID> \ --access-key-secret <yourAccessKeySecret> \ --region cn-hangzhou \ --profile AkProfile \ --mode AK \ --language enRun the
aliyun configure listcommand. If you receive the following output, theAkProfileprofile is created:Profile | Credential | Valid | Region | Language --------- | ------------------ | ------- | ---------------- | -------- default | AK:****** | Valid | cn-beijing | zh AkProfile * | AK:****** | Valid | cn-hangzhou | en
Example 2: Modify a profile
Run the
aliyun configure get regioncommand. The region ID in the current profile is returned.
Run the following command to replace the region ID in the profile with
cn-shanghai:aliyun configure set --region cn-shanghaiRun the
aliyun configure get regionagain to check whether the region ID is updated.
Query a list of profiles
Run the aliyun configure list command to query a list of profiles. You can view the summary of all profiles on the list.
Example
Run the following command to query a list of profiles:
aliyun configure listThe following list of profiles is returned:
The profile list contains the summary of each profile, including the profile name, profile identifier, some credential information, credential validity period, default region ID, and language of the help information. Alibaba Cloud CLI uses an asterisk (
*) on the right side of the profile name to identify a profile.Profile | Credential | Valid | Region | Language --------- | ------------------ | ------- | ---------------- | -------- AkProfile * | AK:****** | Valid | cn-beijing | en StsTokenProfile | StsToken:****** | Valid | cn-hangzhou | en RamRoleArnProfile | RamRoleArn:****** | Valid | cn-shanghai | en EcsRamRoleProfile | EcsRamRole:ECSAdmin | Valid | cn-qingdao | zh
Query the details about a profile
Run the aliyun configure get command to query the details about a specified profile.
Syntax
aliyun configure get [--profile <PROFILE_NAME>] [<SETTING_NAME>...]PROFILE_NAME: Specifies the profile name. If you do not specify this parameter and theALIBABA_CLOUD_PROFILEenvironment variable is not configured, information about the current profile is displayed. If the specified profile does not exist, the messageprofile <PROFILE_NAME> not found!is returned.SETTING_NAME: Specifies the settings to view. You can specify multiple settings. If you do not specify this parameter, all settings are displayed. If a specified setting does not exist, the command returns no information.
Example 1: View all configuration options of a profile
Run the following command to query all configuration options of the
AkProfileprofile of the AK type:aliyun configure get --profile AkProfileSample response:
{ "name": "AkProfile", "mode": "AK", "access_key_id": "<yourAccessKeyID>", "access_key_secret": "<yourAccessKeySecret>", "region_id": "cn-hangzhou", "output_format": "json", "language": "en" }
Example 2: Query specified configuration options of a profile
Run the following command to query the profile name, credential type, and default language of the
ExternalProfilewhose credential type is External:aliyun configure get profile mode language --profile ExternalProfileThe details are returned in the
key=valueformat.profile=ExternalProfile mode=External language=en
Switch to a specific profile
Starting from v3.0.214, you can run the aliyun configure switch command to change the current active profile. After you switch profiles, Alibaba Cloud CLI automatically uses the new profile for all requests, unless you specify another credential.
Syntax
aliyun configure switch --profile <PROFILE_NAME>PROFILE_NAME: Specifies the profile name. This parameter is required. The command fails if this parameter is empty or the specified profile does not exist.
Example
Run the
aliyun configure listcommand to query a list of profiles. The list shows that the current profile isdefault. Alibaba Cloud CLI uses an asterisk (*) on the right side of the profile name to identify a profile.Profile | Credential | Valid | Region | Language --------- | ------------------ | ------- | ---------------- | -------- default * | AK:****** | Valid | cn-hangzhou | en ExampleProfile | AK:****** | Valid | cn-beijing | zhRun the following command to switch to the
ExampleProfileprofile. If you receive theThe default profile is `ExampleProfile` nowmessage, the command succeeds.aliyun configure switch --profile exampleProfileRun the
aliyun configure listcommand again to check whether you are switched to the specified profile.Profile | Credential | Valid | Region | Language --------- | ------------------ | ------- | ---------------- | -------- default | AK:****** | Valid | cn-hangzhou | en ExampleProfile * | AK:****** | Valid | cn-beijing | zh
Delete a profile
Run the aliyun configure delete command to delete a specific profile.
Syntax
aliyun configure delete --profile <PROFILE_NAME>PROFILE_NAME: Specifies the name of the profile to delete. This parameter is required. The command fails if this parameter is empty or the specified profile does not exist.If you delete the current profile, you are automatically switched to the profile on the top of the list. For more information, see the following example.
We recommend that you keep at least one profile. If you delete all profiles by mistake, Alibaba Cloud CLI does not work as expected. To resolve this issue, you must manually delete the
config.jsonfile. This file is located in the.aliyunfolder in your user home directory. The location of the user home directory varies based on the operating system.Windows:
C:\Users\<USER_NAME>\.aliyunLinux and macOS:
/home/<USER_NAME>/.aliyun
Example
Run the
aliyun configure listcommand to query a list of profiles.Profile | Credential | Valid | Region | Language --------- | ------------------ | ------- | ---------------- | -------- default | AK:****** | Valid | cn-hangzhou | en AkProfile | AK:****** | Valid | cn-hangzhou | en ExampleProfile * | AK:****** | Valid | cn-hangzhou | enRun the following command to delete the
ExampleProfilefile:aliyun configure delete --profile ExampleProfileRun the
aliyun configure listcommand again to check whether theExampleProfileprofile is deleted. If yes, you are switched to thedefaultprofile.Profile | Credential | Valid | Region | Language --------- | ------------------ | ------- | ---------------- | -------- default * | AK:****** | Valid | cn-hangzhou | en AkProfile | AK:****** | Valid | cn-hangzhou | en