从 python 中的文件中读取消息并通过 sns 主题发布

Read message from a file in python and publish it via sns topic

我需要从 txt 文件中读取输出,这是 python 脚本执行的结果。此 .txt 文件 output/content 需要通过 sns 主题发布。有人可以帮我解决这个问题吗?

import boto3
sns = boto3.client('sns')
# Publish a simple message to the specified SNS topic
response = sns.publish(
TopicArn='arn:aws:sns:us-west-2:xxxxxxxxx',   
Message='Message',

)
# Print out the response
 print(response)

像这样阅读 .txt

with open("/path/to/txt/file.txt", "r") as txt_file:
    output = txt_file.read() # might need .readlines() or .read().splitlines(). Whatever works for you
    Message = output