import boto3 import awscli import json import os import boto3 os envir

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import boto3
import awscli
import json
import os
import boto3
os.environ['AWS_PROFILE'] = 'AWSResearch'
sqs_client = boto3.client('sqs', 'us-east-1')
queue_url = 'https://sqs.us-east-1.amazonaws.com/641113671333/lesson1_oleg_cherednichenko'
def send_sqs_message(text: str):
sqs_client.send_message(
QueueUrl=queue_url, MessageBody=text)
def read_sqs_message() -> list:
response = sqs_client.receive_message(QueueUrl=queue_url, AttributeNames=['SentTimestamp'], MaxNumberOfMessages=10,
MessageAttributeNames=['All'], VisibilityTimeout=0, WaitTimeSeconds=0)
messages = list()
for k in response.keys():
for values in response[k]:
if k in 'Messages':
messages.append(values['Body'])
return messages
def read_full_sqs():
return sqs_client.receive_message(QueueUrl=queue_url, AttributeNames=['SentTimestamp'], MaxNumberOfMessages=10,
MessageAttributeNames=['All'], VisibilityTimeout=0, WaitTimeSeconds=0)
def delete_message():
response = sqs_client.delete_queue(QueueUrl=queue_url)
def save_to_file_sqs():
with open('sqs_messages.txt', 'w') as file:
messages = read_sqs_message()
file.write('\n'.join(x for x in messages))
def read_with_json():
return json.dumps(read_full_sqs())
if __name__ == '__main__':
mes = read_with_json()
print(mes)