Registry / gcp / alibabacloud-sts20150401

alibabacloud-sts20150401

JSON →
library1.2.0pypypi✓ verified 52d ago

The `alibabacloud-sts20150401` library is the official Alibaba Cloud SDK for interacting with the Security Token Service (STS) API version 2015-04-01. It allows you to issue temporary access credentials for Alibaba Cloud resources, commonly used for granting temporary permissions or cross-account access. The current version is 1.2.0. Like most Alibaba Cloud SDKs, it follows a stable release cadence, with updates primarily for bug fixes or minor enhancements rather than frequent new features.

gcp
pip install alibabacloud-sts20150401
Install & Compatibility
Where this runs
tested against v1.2.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.920 runs
installs and imports cleanly · install 0.0s · import 1.449s · 49MB
glibc
py 3.103.920 runs
installs and imports cleanly · install 8.2s · import 1.317s · 51MB
49MB installed
● package 49MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Client
from alibabacloud_sts20150401.client import Client as StsClient
Config
from alibabacloud_tea_openapi.models import Config
from alibabacloud_sts20150401.models import Config
The base `Config` class for client initialization comes from `alibabacloud-tea-openapi`, not the service-specific SDK.
AssumeRoleRequest
from alibabacloud_sts20150401.models import AssumeRoleRequest

This quickstart demonstrates how to initialize the STS client and call the `AssumeRole` API to obtain temporary credentials. It retrieves AccessKeyId and SecretKey from environment variables for security best practices and specifies a placeholder Role ARN. Remember to replace `YourRoleName` with your actual RAM Role ARN.

import os from alibabacloud_sts20150401.client import Client as StsClient from alibabacloud_tea_openapi.models import Config from alibabacloud_sts20150401.models import AssumeRoleRequest from alibabacloud_tea_util.models import RuntimeOptions # Ensure environment variables are set for security access_key_id = os.environ.get('ALIBABA_CLOUD_ACCESS_KEY_ID', '') access_key_secret = os.environ.get('ALIBABA_CLOUD_ACCESS_KEY_SECRET', '') role_arn = os.environ.get('ALIBABA_CLOUD_ROLE_ARN', 'acs:ram::xxxxxxxxxxxxxxx:role/YourRoleName') role_session_name = os.environ.get('ALIBABA_CLOUD_ROLE_SESSION_NAME', 'my-sts-session') if not access_key_id or not access_key_secret: print("Error: ALIBABA_CLOUD_ACCESS_KEY_ID and ALIBABA_CLOUD_ACCESS_KEY_SECRET must be set.") exit(1) # Configure the client config = Config( access_key_id=access_key_id, access_key_secret=access_key_secret, # STS is a global service, default endpoint is sts.aliyuncs.com endpoint='sts.aliyuncs.com' ) # Create a client instance try: client = StsClient(config) print("STS Client initialized successfully.") # Prepare the AssumeRole request assume_role_request = AssumeRoleRequest( role_arn=role_arn, role_session_name=role_session_name, duration_seconds=3600 # Optional: specify duration of token in seconds (default is 3600s) ) # Create a runtime option, useful for setting timeout or retry policy runtime = RuntimeOptions() # Call the AssumeRole API response = client.assume_role_with_options(assume_role_request, runtime) # Print the temporary credentials credentials = response.body.credentials print("\nAssumed Role Credentials:") print(f"AccessKeyId: {credentials.access_key_id}") print(f"AccessKeySecret: {credentials.access_key_secret}") print(f"SecurityToken: {credentials.security_token[:10]}...{credentials.security_token[-10:]}") # Truncate for display print(f"Expiration: {credentials.expiration}") except Exception as error: print(f"An error occurred: {error}") # In a real application, you'd log the full error or specific details # print(error.args[0].get('Code') if hasattr(error, 'args') and len(error.args) > 0 and isinstance(error.args[0], dict) else error)
Debug
Known issues
gotchaAlibaba Cloud SDKs often use `alibabacloud-SERVICEAPIVERSION` for their package names. This `sts20150401` package is specifically for the 2015-04-01 API version. Ensure you are using the correct package for the API version you intend to target, as there might be other STS packages for different versions or older SDK styles (e.g., `aliyun-python-sdk-sts`).
fix
Verify the required API version for your STS operations and install the corresponding `alibabacloud-SERVICEAPIVERSION` package.
affects: All versions of alibabacloud-sts20150401
gotchaThe base `Config` object for client initialization (e.g., `Config(access_key_id=..., endpoint=...)`) must be imported from `alibabacloud_tea_openapi.models`, not from `alibabacloud_sts20150401.models` or other service-specific packages. Misimporting `Config` is a common mistake that leads to `AttributeError` or unexpected behavior.
fix
Always import `Config` from `from alibabacloud_tea_openapi.models import Config`.
affects: All versions
gotchaAuthentication credentials (AccessKeyId and AccessKeySecret) should be managed securely. Hardcoding them directly in your code is strongly discouraged. It's recommended to use environment variables, instance RAM roles, or a secrets management service.
fix
Retrieve credentials from environment variables (`os.environ.get`), Alibaba Cloud credentials file, or integrate with an identity provider. The quickstart example uses environment variables.
affects: All versions
gotchaAlthough STS is a global service, explicitly setting the `endpoint` in the `Config` object (e.g., `endpoint='sts.aliyuncs.com'`) is a good practice to prevent potential issues if the default resolution changes or if you need to connect through a specific region's endpoint proxy for network reasons.
fix
Always set `config.endpoint` to the appropriate service endpoint. For global services like STS, `sts.aliyuncs.com` is common.
affects: All versions
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'alibabacloud_sts20150401'
The 'alibabacloud_sts20150401' package is not installed in the Python environment.
fix
Install the package using pip: 'pip install alibabacloud-sts20150401'.
ImportError: cannot import name 'Sts20150401Client' from 'alibabacloud_sts20150401'
Incorrect import statement; 'Sts20150401Client' should be imported from 'alibabacloud_sts20150401.client'.
fix
Use the correct import: 'from alibabacloud_sts20150401.client import Client as Sts20150401Client'.
AttributeError: module 'alibabacloud_sts20150401' has no attribute 'AssumeRoleRequest'
Attempting to access 'AssumeRoleRequest' directly from the 'alibabacloud_sts20150401' module instead of its 'models' submodule.
fix
Import 'AssumeRoleRequest' from the 'models' submodule: 'from alibabacloud_sts20150401 import models as sts_20150401_models'.
InvalidAccessKeyId.NotFound: Specified access key is not found.
The AccessKey ID provided for authentication is either incorrect, contains typographical errors, or does not exist in your Alibaba Cloud account.
fix
Verify that your `AccessKeyId` is correct and active in the Alibaba Cloud console. Ensure there are no leading or trailing spaces.
NoPermission: No permission perform sts:AssumeRole on this Role.
The RAM user or RAM role attempting to call the `AssumeRole` operation does not have the necessary permissions (e.g., `sts:AssumeRole`) or the target RAM role's trust policy does not allow the calling entity to assume it.
fix
Grant the `AliyunSTSAssumeRoleAccess` system authorization permission to the RAM user, or modify the trust policy of the target RAM role to allow the calling entity to assume it.
Upgrade
Version history
1.2.0latest on PyPI
Audit
Dependencies
alibabacloud-tea-utilrequiredCore utility functions for Alibaba Cloud SDKs.
alibabacloud-tea-openapirequiredProvides base classes and models for OpenAPI configurations.
alibabacloud-darabonba-envrequiredUtility for retrieving environment variables, often used for credential management.
Agent activity
81 hits · last 30 days
node
10
claudebot
4
Amazon
1
amazonbot
1
bytedance
1
googlebot
1
Resources