python-3.x - NoCredentialsError botocore.exceptions.NoCredentialsError:即使在传递凭据后也无法找到凭据
问题描述
我正在向 Flask 应用程序内的 SQS 队列发送消息。我正在使用https://github.com/vsouza/docker-SQS-local在本地模仿这个 SQS 功能。
我正在为boto3.client()
内部功能设置凭据。当我在 Pycharm 中直接运行发送消息的函数时,它正在向 SQS 队列发送消息。
但是当我 dockerize 这个 Flask 应用程序并调用触发这个函数的端点时,它会抛出错误。
引发 NoCredentialsError botocore.exceptions.NoCredentialsError:无法找到凭据
这是发送消息的代码。
def send_mes():
config = Config()
sqs = boto3.client('sqs', aws_access_key_id=None, aws_secret_access_key=None,
endpoint_url=config.QUEUE_ENDPOINT_URL, region_name='default')
feeder_queue = config.FEEDER_QUEUE
def inside_fun():
while True:
resp = sqs.send_message(
QueueUrl=feeder_queue,
MessageBody=(
f'Sample message for Queue at {datetime.now()}.'
)
)
print(resp)
time.sleep(3)
t1 = threading.Thread(target=inside_fun)
t2 = threading.Thread(target=inside_fun)
t1.start()
t2.start()
t1.join()
t2.join()
if __name__ == '__main__':
send_mes()
请指出我在哪里犯错?
解决方案
我没有在代码中直接将 AWS 凭证传递给客户端,而是设置了环境变量并且它起作用了。
推荐阅读
- reactjs - 不知道如何在这里实现条件渲染(react-native)
- mysql - GROUP BY 根据每列的不同条件
- floating-point - 数据类型浮点数的准确性(IEEE 754 单精度)
- python - 如何在 Python 中使用 Selenium 在 Google 上进行搜索?
- tarantool - 所有 Tarantool 节点 (vshard) 的可用空间
- routes - 如何从 osmnx 导出路由
- c++ - 通过 Freertos 中的队列发送字符串
- nestjs - 在没有 moduleRef.get 的情况下获得服务的可能性
- asp.net-core - 使用 OpenIdDict 时不允许使用“offline_access”范围
- powershell - 仅当某些变量不为空时,如何使用 Powershell 发送电子邮件?