简体   繁体   中英

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

I have a requirement to read output from txt file and this is result from a python script execution. This.txt file output/content needs to be published via sns topic. Can someone help me on this please?

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)

Read the.txt like this

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM