1

I am new to SQS and as a POC, I am only pushing "var/log/auth.log" to SQS. I now want to listen to the SQS que. I am able to do it, however, its displaying the entire json file. I want to display only "data" value of it.

here's what my script looks like.

import boto3
# Get the service resource
sqs = boto3.resource('sqs')
client = boto3.client('sqs')


response = client.receive_message(
    QueueUrl='https://sqs.us-east-1.amazonaws.com/XXXXX/my-queue-name',
    AttributeNames=[
        'Messages',
    ],
    MessageAttributeNames=[
        'data',
    ],
    MaxNumberOfMessages=1,
)

print(response)

And here's the sample output:

    vagrant@terraform:~/sqs$ python3 file.py 
{'Messages': [{'Body': '{"project": "XXX", "event_name": "system-events", "datetime": "2018-12-24 06:00:37.797510", "environment": "XXX", "client": "XXX", "data": "Dec 24 06:00:37 app--01 sshd[29393]: Received disconnect from 106.51.38.57: 11: disconnected by user\\n"}', 'MessageId': '95b5a167-958b-4536-a71e-2cd2bd0cf486', 'MD5OfBody': 'a1be00aa3b1f306d9f46c3201795f257', 'ReceiptHandle': 'AQEBIxEGSJerpfrPH6yO5qTwzlJ7cD88Eijdz8uPaUXemQF8PeNuYN/7np9ZfXDrgTaSdAt8zqodND2fI0sDjzgwIsrlnZC291dR4wmey3HvQ3ZQkSA8zl7/pOJzPcDI/byNXbx4P3YBloey3cdJrZ6dwCoICsSZdEVIbqbwLfEPuGwHCVY96FcvVwu/od6F2Xk9v2v5XlSan//veuDAVaXRZs9IX0ynSbDWK/6y+0D4HwJjeMbzXG2m31JakOghJRcvY6PJCTS5euXBWKCrVxgtWBNYIBvQOGuUxhtp2wweNiC62odC/AoGvPwxP60P9NHTJte7KrapOaNlbL61yQuGc1+3eoSBsJIeEiBYpZp7C58JI0jyG75VAtHiNLxckMI0qEbR9lG/8b/QvITYjYsj4J1K7cwSi8qobimghkIBXEY='}], 'ResponseMetadata': {'HTTPHeaders': {'x-amzn-requestid': '74ed6f55-914b-5a78-b88c-3bcf237f2355', 'date': 'Mon, 24 Dec 2018 10:07:48 GMT', 'content-type': 'text/xml', 'content-length': '1246'}, 'HTTPStatusCode': 200, 'RetryAttempts': 0, 'RequestId': '74ed6f55-914b-5a78-b88c-3bcf237f2355'}}
1
  • Could you add the log? Without it, it will be hard to answer the question. Please edit the Q&A and let us know when it can be reviewed. In the mean time the question will be closed. – 030 Dec 24 '19 at 15:03