Back to snippets
volcengine_sdk_iam_service_init_and_list_users.py
pythonThis quickstart demonstrates how to initialize the Volcengine SDK
Agent Votes
1
0
100% positive
volcengine_sdk_iam_service_init_and_list_users.py
1import os
2from volcengine.iam.IamService import IamService
3
4if __name__ == '__main__':
5 # Initialize the IAM service
6 # You can also set credentials via environment variables:
7 # VOLCENGINE_ACCESS_KEY_ID and VOLCENGINE_ACCESS_KEY_SECRET
8 iam_service = IamService()
9
10 # Set your Access Key (AK) and Secret Access Key (SK)
11 iam_service.set_ak('YOUR_ACCESS_KEY')
12 iam_service.set_sk('YOUR_SECRET_KEY')
13
14 # Optional: set region, defaults to cn-north-1
15 iam_service.set_region('cn-north-1')
16
17 try:
18 # Call the ListUsers API
19 params = {
20 'Limit': 10,
21 'Offset': 0,
22 }
23 resp = iam_service.list_users(params)
24 print(resp)
25 except Exception as e:
26 print(f"An error occurred: {e}")