如何在我的AWS凭证文件中保存(添加)我的STS临时凭证?

时间:2017-12-09 03:34:30

标签: python file amazon-web-services text

我已经生成了临时凭证,但是我希望通过boto3 python将带有配置文件名称的~/.aws/credentials上的凭据上传到文件中。尝试使用文件操作没有成功。

import boto
import datetime
from datetime import date, timedelta
import subprocess
import os
import sys

from boto.s3.connection import S3Connection
from boto.sts import STSConnection

# Prompt for MFA time-based one-time password (TOTP)
mfa_TOTP = raw_input("Enter the MFA code: ")

sts_connection = STSConnection(profile_name="dev-yudw")

tempCredentials = sts_connection.get_session_token(
    duration=3600,
    mfa_serial_number="arn:aws:iam::xxxxxxxxx:mfa/yudi",
    mfa_token=mfa_TOTP
)

print tempCredentials.access_key
print tempCredentials.secret_key
print tempCredentials.session_token

lines_of_text = [
    "aws_access_key_id=" + str(tempCredentials.access_key) + "\n", 
    "aws_secret_access_key=" + str(tempCredentials.secret_key)" + "\n", 
    "security_token=" + str(tempCredentials.session_token) + "\n"
]
print str(tempCredentials.access_key)

这里有任何文件处理或boto 3函数来上传这个数组值 如果已退出,则需要替换~/.aws/credentials

中的配置文件

0 个答案:

没有答案