gpt4 book ai didi

Python AWS Boto3 SAML 身份验证错误

转载 作者:行者123 更新时间:2023-12-01 01:48:36 31 4
gpt4 key购买 nike

您好,我正在尝试查找端口 22 0.0.0.0/0 打开的所有 AWS EC2 实例。我有下面的代码,但仍然遇到下面的身份验证处理错误。看来 boto 无法识别我已通过身份验证。我一直在四处寻找,但找不到如何处理此错误。关于如何处理以下错误有什么想法吗?

import sys
import boto
from boto import ec2
from boto import sns
import os
import boto3


# Call the saml API Key Retreiver - Must be stored in C:\Temp
os.system('"C:/Temp/apikeyretriever_windows_386.exe"')

# Set Profile to SAML
session = boto3.session.Session(profile_name='saml')



connection = ec2.connect_to_region("us-east-1")
connSNS = boto.sns.connect_to_region("us-east-1")
sg = connection.get_all_security_groups('us-east-1')

listOfInstances = ""
messages = "Following Instances have port 22 open"


def getTag(instanceId):
reservations = connection.get_all_instances(filters={'instance_id': instanceId})
for r in reservations:
for i in r.instances:
return i.tags['Name']


try:

for securityGroup in sg:
for rule in securityGroup.rules:

global instanceId;

if (rule.from_port == '22' and rule.to_port == '22') and '0.0.0.0/0' in str(rule.grants):
for instanceid in securityGroup.instances():
listOfInstances += "Instance Name : " + getTag(instanceId.split(':')[
1]) + "\t State:" + instanceid.state + "\t SecurityGroup:" + securityGroup.name + "\n"

connSNS.publish(topic='sns-arn-endpoint', message=messages + "\n" + listOfInstances,
subject='ProjectName : Server List with Port 22 Open')

except:
print('Some Error occurred : ')
print
sys.exc_info()
connSNS.publish(topic='sns-arn-endpoint', message=sys.exc_info(), subject='script ended with error')

错误信息:

 Traceback (most recent call last):
File "port.py", line 17, in <module>
connection = ec2.connect_to_region("us-east-1")
File "C:\ProgramData\Anaconda3\lib\site-packages\boto\ec2\__init__.py", line 6
6, in connect_to_region
connection_cls=EC2Connection, **kw_params)
File "C:\ProgramData\Anaconda3\lib\site-packages\boto\regioninfo.py", line 218
, in connect
return region.connect(**kw_params)
File "C:\ProgramData\Anaconda3\lib\site-packages\boto\regioninfo.py", line 288
, in connect
return self.connection_cls(region=self, **kw_params)
File "C:\ProgramData\Anaconda3\lib\site-packages\boto\ec2\connection.py", line
103, in __init__
profile_name=profile_name)
File "C:\ProgramData\Anaconda3\lib\site-packages\boto\connection.py", line 110
0, in __init__
provider=provider)
File "C:\ProgramData\Anaconda3\lib\site-packages\boto\connection.py", line 569
, in __init__
host, config, self.provider, self._required_auth_capability())
File "C:\ProgramData\Anaconda3\lib\site-packages\boto\auth.py", line 1021, in
get_auth_handler
'Check your credentials' % (len(names), str(names)))
boto.exception.NoAuthHandlerFound: No handler was ready to authenticate. 1 handl
ers were checked. ['HmacAuthV4Handler'] Check your credentials

最佳答案

您从堆栈跟踪中收到的错误消息看起来像是您的脚本找不到 STS token ,我假设 apikeyretriever_windows_386.exe 应该为您创建和存储该 token ,以登录 API在您的 AWS 凭证/配置文件中名为“saml”的配置文件下。

关于Python AWS Boto3 SAML 身份验证错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50970308/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com