我正在使用boto3的s3.transfer從s3下載幾個4GB +文件。所有,但一個能下載,但失敗的人給了以下錯誤:在http://boto3.readthedocs.org/en/latest/_modules/boto3/s3/transfer.html如何增加boto3.s3.transfer下載的令牌過期時間?
s3_client = session.client('s3')
transfer = S3Transfer(s3_client)
# Download s3://bucket/key to /tmp/myfile
transfer.download_file('bucket', 'key', '/tmp/myfile')
ERROR: An error occurred (ExpiredToken) when calling the GetObject operation: The provided token has expired.
我現在用同樣的方式是文件是否有增加的方式boto3中使用的簽名url的過期時間?
如果它是相關的,我使用Cognito拿到證書,並與他們,會話
client = boto3.client('cognito-identity', AWS_REGION)
# credentials[] contains the IdentityId and Token I get from my server
# which I get using client.get_open_id_token_for_developer_identity
# with TokenDuration=86400
resp = client.get_credentials_for_identity(IdentityId=credentials['IdentityId'],
Logins={'cognito-identity.amazonaws.com': credentials['Token']})
# The resp contains the actual temporary AWS secret/access codes and a session token, to be
# used with the rest of the AWS APIs
secretKey = resp['Credentials']['SecretKey']
accessKey = resp['Credentials']['AccessKeyId']
sessionToken = resp['Credentials']['SessionToken']
session = Session(aws_access_key_id=accessKey,
aws_secret_access_key=secretKey,
aws_session_token=sessionToken,
region_name=AWS_REGION)
s3_client = session.client('s3')
您的代碼如何接收訪問密鑰/密鑰?我的猜測是你的問題是代碼在一個附加了IAM角色的EC2實例上運行。它是否正確 ?或者你是否通過配置文件傳遞AK/SK? ENV變量? –
忘記提及我使用cognito獲取密鑰,訪問密鑰和會話令牌。 – dkarchmer
更新了OP,代碼顯示了我是如何獲得會話和s3客戶端的 – dkarchmer