在 Python 中使用 SNS 发布主题时如何指定不同的用户?

How to specify a different user when publishing to a topic with SNS in Python?

当我尝试在终端中发布主题时:

import boto3

client = boto3.client('sns', region_name="us-east-2")
response = client.publish(
    TopicArn="my_topic_arn",
    Message="message",
)

我明白了 user/xxxxx is not authorized to perform: SNS:Publish on resource:

如何更改它以使用 user/yyyyy

user/xxxxx 是您使用默认配置文件配置 AWS 凭证的凭证。如果您想使用 user/yyyyy 凭证,您需要使用 aws configure 或在环境变量 AWS_ACCESS_KEY_IDAWS_SECRET_ACCESS_KEY

中设置它们来更新 AWS 凭证