【发布时间】:2016-06-11 16:13:46
【问题描述】:
我有一个脚本,可以从 Cloudwatch 中提取大量指标用于我们自己的内部报告。
该脚本迭代特定区域中的所有 EC2 实例,并询问过去 2 周的 5 个 cloudwatch 指标(所有可用的统计数据)(每次 5 天,间隔 5 分钟,正好是 1440 配额)。我正在使用假定会话:
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。
【问题讨论】: