0
我有一個腳本從我們自己的內部報告中抽取了很多來自Cloudwatch的指標。請求中包含的安全令牌已過期
該腳本迭代特定區域中的所有EC2實例,並在過去2周內(每次5分鐘之內返回5分鐘間隔,這正是1440配額)要求5個cloudwatch指標(所有可用統計數據) 。我使用的是假設會話:
session = Session(aws_access_key_id=AWS_ACCESS_KEY_ID, aws_secret_access_key=AWS_SECRET_ACCESS_KEY, region_name=regionName)
sts = session.client('sts')
response = sts.assume_role(
RoleArn=arn, # External role arn
RoleSessionName='role-name',
ExternalId='<some-id-here>',
)
tempAccessKeyId = response['Credentials']['AccessKeyId']
tempSecretAccessKey = response['Credentials']['SecretAccessKey']
tempSessionToken = response['Credentials']['SessionToken']
assumedSession = Session(
aws_access_key_id=tempAccessKeyId,
aws_secret_access_key=tempSecretAccessKey,
aws_session_token=tempSessionToken,
region_name=regionName)
在運行該腳本,我得到這個異常:
botocore.exceptions.ClientError: An error occurred (ExpiredToken) when calling the GetMetricStatistics operation: The security token included in the request is expired
有沒有一種方法,以確保令牌不會過期運行腳本時?我正在使用boto3。