Role Management Interfaces
Updated at:2025-10-27
Create role
Create a role with reference to the following codes:
Python
1def create_role():
2 iam_client = IamClient(iam_sample_conf.config)
3
4# Role creation request as dict
5# Set the role name
6# Set the role description
7# Specify the entity allowed to assume the role (assumeRolePolicyDocument)
8 create_role_request = {"name": "test_role", "description": "create role: test_role",
9 "assumeRolePolicyDocument": "{\"version\":\"v1\",\"accessControlList\":[{"
10 "\"service\":\"bce:iam\",\"permission\":[\"AssumeRole\"],"
11 "\"region\":\"*\",\"grantee\":[{"
12 "\"id\":\"test_account_id\"}],"
13 "\"effect\":\"Allow\"}]}"}
14 response = iam_client.create_role(create_role_request)
15 print(response)
Query role
Query a role with reference to the following codes:
Python
1def get_role():
2 iam_client = IamClient(iam_sample_conf.config)
3
4# Set role name
5 role_name = b"test_role"
6 response = iam_client.get_role(role_name)
7 print(response)
Update role
Update a role with reference to the following codes:
Python
1def update_role():
2 iam_client = IamClient(iam_sample_conf.config)
3# Old role name
4 role_name = b"test_role"
5
6# Request to update role is dict
7# Set the updated role name
8# Set updated role description
9# Set updated carriers allowed to assume the role (assumeRolePolicyDocument)
10 update_role_request = {"name": "test_role_new", "description": "update role: test_role",
11 "assumeRolePolicyDocument": "{\"version\":\"v1\",\"accessControlList\":[{"
12 "\"service\":\"bce:iam\",\"permission\":[\"AssumeRole\"],"
13 "\"region\":\"*\",\"grantee\":[{"
14 "\"id\":\"test_account_id\"}],"
15 "\"effect\":\"Allow\"}]}"}
16 response = iam_client.update_role(role_name, update_role_request)
17 print(response)
Delete role
Delete a role with reference to the following codes:
Python
1def delete_role():
2 iam_client = IamClient(iam_sample_conf.config)
3# Role name to be deleted
4 role_name = b"test_role"
5 response = iam_client.delete_role(role_name=role_name)
6 print(response)
List roles
List a role with reference to the following codes:
Python
1def list_role():
2 iam_client = IamClient(iam_sample_conf.config)
3 response = iam_client.list_role()
4 print(response)
