首页 > 解决方案 > 从 python 文件中读取消息并通过 sns 主题发布

问题描述

我需要从 txt 文件读取输出,这是 python 脚本执行的结果。此 .txt 文件输出/内容需要通过 sns topic 发布。有人可以帮我吗?

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)

标签: pythonamazon-web-servicesboto3amazon-sns

解决方案


像这样阅读.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

推荐阅读