AWS STS GetFederationToken用于为AWS中的临时用户生成临时凭证。此API适用于那些需要在不向他们提供长期AWS安全凭证的情况下运行代码的应用程序。临时凭证的最大寿命为12小时,如果需要更长时间,可以在到期之前调用GetFederationToken API以获得新的临时凭证。
以下是一个GetFederationToken的代码示例:
import boto3
sts_client = boto3.client('sts')
response = sts_client.get_federation_token( Name='test-user', Policy='{"Version": "2012-10-17","Statement": [{"Effect": "Allow","Action": "s3:","Resource": ""}]}', DurationSeconds=3600 )
access_key_id = response['Credentials']['AccessKeyId'] secret_access_key = response['Credentials']['SecretAccessKey'] session_token = response['Credentials']['SessionToken']
print("Access Key Id: {}".format(access_key_id)) print("Secret Access Key: {}".format(secret_access_key)) print("Session Token: {}".format(session_token))