python - 从 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)
解决方案
像这样阅读.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
推荐阅读
- php - 在网格中显示带有子项和产品编号的 Woocommerce 产品类别
- google-apps-script - 范围选择器 Google Sheet Apps 脚本
- sql-server - 如何在 SQL Server 2012 中使用 GROUP BY
- r - R 记者到官员和移民
- .net-core - .NET Core GraphQL - GraphQL 架构不可用,而是显示自省查询
- java - 我想将不可变的 Java 对象作为引用传递,是否有 AtomicReferences 或 Array 或 List 的替代方法?
- datatables - ajax 加载后更新 Datatables 列搜索下拉框
- javascript - window.opener 为空...以前不是
- javascript - 在数组中插入元素
- typo3 - 从 url 参数设置表单值