为什么我得到一个MissingAuthenticationToken错误时调用sns.从Python发布boto3?&l



我正在使用AWS SNS发送消息的Docker容器中的Python 3.10.3应用程序上工作。我写了下面的代码:

import boto3
from botocore.config import Config
config = Config(signature_version=botocore.UNSIGNED)
def send_sns_message(topic_arn: str, message: str, message_attributes: dict) -> None:
sns = boto3.client(
"sns",
region_name=os.environ["AWS_REGION"],
aws_access_key_id= os.environ["AWS_ACCESS_KEY_ID"],
aws_secret_access_key=os.environ["AWS_SECRET_ACCESS_KEY"],
config=config,
)
att_dict = {}
for key, value in message_attributes.items():
if isinstance(value, str):
att_dict[key] = {"DataType": "String", "StringValue": value}
response = sns.publish(
TopicArn=topic_arn,
Message=message,
MessageGroupId=str(uuid4()),
MessageAttributes=att_dict,
)

当我用有效的topic_arn, message和message_attributes调用这个函数时,它会产生这个错误:

botocore.exceptions.ClientError: An error occurred (MissingAuthenticationToken) when calling the Publish operation: Request is missing Authentication Token

AWS_ACCESS_KEY_ID和AWS_SECRET_ACCESS_KEY是有效的。谁有什么建议,我该如何解决这个问题?或者,在哪里查找/生成身份验证令牌?

唉,有时候我真讨厌我自己。我取出了config选项,现在一切都很好。这是一个巨大的"别介意"的标志!

最新更新