|
| 1 | +# Client |
| 2 | + |
| 3 | +## Using AccessKey call |
| 4 | + |
| 5 | +```python |
| 6 | +from aliyunsdkcore.client import AcsClient |
| 7 | +from aliyunsdkecs.request.v20140526.AcceptInquiredSystemEventRequest import AcceptInquiredSystemEventRequest |
| 8 | + |
| 9 | +# Create and initialize a AcsClient instance |
| 10 | +client = AcsClient( |
| 11 | + '<access_key_id>', # The AccessKey ID of the RAM account |
| 12 | + '<access_secret>', # The AccessKey Secret of the RAM account |
| 13 | + '<region_id>"' # The region ID |
| 14 | +) |
| 15 | + |
| 16 | +# Create an API request and set parameters |
| 17 | +request = AcceptInquiredSystemEventRequest() |
| 18 | +request.set_accept_format('json') |
| 19 | +# Initiate the request and handle the response or exceptions |
| 20 | +response = client.do_action_with_exception(request) |
| 21 | + |
| 22 | +print(str(response, encoding='utf-8')) |
| 23 | +``` |
| 24 | + |
| 25 | +## Use the default credential provider chain |
| 26 | + |
| 27 | +The default credential provider chain looks for available credentials, with following order: |
| 28 | + |
| 29 | +1.System Properties |
| 30 | + |
| 31 | +Look for environment credentials in system properties. If the `alibabacloud.accessKeyId` and `alibabacloud.accessKeyIdSecret` system properties are defined and not empty, the program will use them to create default credentials. |
| 32 | + |
| 33 | +2.Environment Credentials |
| 34 | + |
| 35 | +Look for environment credentials in environment variable. If the `ALIBABA_CLOUD_ACCESS_KEY_ID` and `ALIBABA_CLOUD_ACCESS_KEY_SECRET` environment variables are defined and are not empty, the program will use them to create default credentials. |
| 36 | + |
| 37 | +3.Credentials File |
| 38 | + |
| 39 | +If there is `~/.alibabacloud/credentials default file (Windows shows C:\Users\USER_NAME\.alibabacloud\credentials)`, the program automatically creates credentials with the specified type and name. The default file is not necessarily exist, but a parse error will throw an exception. The name of configuration item is lowercase.This configuration file can be shared between different projects and between different tools. Because it is outside of the project and will not be accidentally committed to the version control. The path to the default file can be modified by defining the `ALIBABA_CLOUD_CREDENTIALS_FILE` environment variable. If not configured, use the default configuration `default`. You can also set the environment variables `ALIBABA_CLOUD_PROFILE` to use the configuration. |
| 40 | + |
| 41 | +```ini |
| 42 | +[default] # default setting |
| 43 | +enable = true # Enable,Enabled by default if this option is not present |
| 44 | +type = access_key # Certification type: access_key |
| 45 | +access_key_id = foo # Key |
| 46 | +access_key_secret = bar # Secret |
| 47 | + |
| 48 | +[client1] # configuration that is named as `client1` |
| 49 | +type = ecs_ram_role # Certification type: ecs_ram_role |
| 50 | +role_name = EcsRamRoleTest # Role Name |
| 51 | + |
| 52 | +[client2] # configuration that is named as `client2` |
| 53 | +enable = false # Disable |
| 54 | +type = ram_role_arn # Certification type: ram_role_arn |
| 55 | +region_id = cn-test |
| 56 | +policy = test # optional Specify permissions |
| 57 | +access_key_id = foo |
| 58 | +access_key_secret = bar |
| 59 | +role_arn = role_arn |
| 60 | +role_session_name = session_name # optional |
| 61 | + |
| 62 | +[client3] # configuration that is named as `client3` |
| 63 | +type = rsa_key_pair # Certification type: rsa_key_pair |
| 64 | +public_key_id = publicKeyId # Public Key ID |
| 65 | +private_key_file = /your/pk.pem # Private Key file |
| 66 | +``` |
| 67 | + |
| 68 | +4.Instance RAM Role |
| 69 | + |
| 70 | +If the environment variable `ALIBABA_CLOUD_ECS_METADATA` is defined and not empty, the program will take the value of the environment variable as the role name and request http://100.100.100.200/latest/meta-data/ram/security-credentials/ to get the temporary Security credentials. |
| 71 | + |
| 72 | +```python |
| 73 | +from aliyunsdkcore.client import AcsClient |
| 74 | +from aliyunsdkecs.request.v20140526.AcceptInquiredSystemEventRequest import AcceptInquiredSystemEventRequest |
| 75 | + |
| 76 | +client = AcsClient( |
| 77 | + '<region_id>"' |
| 78 | +) |
| 79 | + |
| 80 | +request = AcceptInquiredSystemEventRequest() |
| 81 | +request.set_accept_format('json') |
| 82 | + |
| 83 | +response = client.do_action_with_exception(request) |
| 84 | + |
| 85 | +print(str(response, encoding='utf-8')) |
| 86 | +``` |
0 commit comments