当我从:膝上型电脑运行时,没有问题,但当我从我公司的服务器运行时,它挂在STSConnection()。获取\u会话\u令牌
这是tempCredentials=sts吗_connection.get\会话\令牌需要打开任何端口
import boto
import datetime
from datetime import date, timedelta
import subprocess
import os
import argparse
from boto.s3.connection import S3Connection
from boto.sts import STSConnection
import shutil
#command line arguments
parser = argparse.ArgumentParser(description='To create Temp credentials through STS function and upload to ~/.aws/credentials')
parser.add_argument('-d', '--device_id', help='acc xxxxxxxx neumerical value', required=True)
parser.add_argument('-u', '--user_id', help='user id like xxx ', required=True)
parser.add_argument('-p', '--parent_profile', help='parent profile ', required=True)
parser.add_argument('-m', '--mfa_profile', help='profile', required=True)
args = parser.parse_args()
deviceId = args.device_id
userID = args.user_id
parentProfile = args.parent_profile
mfaProfile = args.mfa_profile
# Prompt for MFA time-based one-time password (TOTP)
mfa_TOTP = raw_input("Enter the MFA code: ")
print "STS connection"
#sts connection
sts_connection = STSConnection(profile_name=parentProfile)
print "STS connection temp credentials"
tempCredentials = sts_connection.get_session_token(
duration=43200,
mfa_serial_number="arn:aws:iam::" + deviceId + ":mfa/" + userID,
mfa_token=mfa_TOTP
)
print "STS connection temp credentials closed"
print str(tempCredentials.access_key)
AWS实现了restapi。这意味着端口443需要对外开放。返回端口可以是1024到65534之间的任意值。你知道吗
尝试使用wget或curl对一个知名网站(https://www.amazon.com)发出一个普通的HTTPS请求,并确保这个请求没有被阻止。如果返回一个有效的网页,那么awsrestapi就可以了。你知道吗
再次检查您是否正在使用STS的全局enpoint。此链接将为您提供更多信息。尝试
wget https://sts.amazonaws.com
以确保STS端点响应。你知道吗Activating and Deactivating AWS STS in an AWS Region
最后不要使用你的根凭据。创建IAM用户以分配临时凭据。你知道吗
使用boto3的最终溶液:
相关问题 更多 >
编程相关推荐