Completed
Pull Request — master (#9)
by George
02:20
created

Publisher.publish()   A

Complexity

Conditions 2

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %
Metric Value
cc 2
dl 0
loc 9
rs 9.6666
1
# -*- coding: utf-8 -*-
2
# vi:si:et:sw=4:sts=4:ts=4
3
4
import json
5
6
import boto3
1 ignored issue
show
Configuration introduced by
The import boto3 could not be resolved.

This can be caused by one of the following:

1. Missing Dependencies

This error could indicate a configuration issue of Pylint. Make sure that your libraries are available by adding the necessary commands.

# .scrutinizer.yml
before_commands:
    - sudo pip install abc # Python2
    - sudo pip3 install abc # Python3
Tip: We are currently not using virtualenv to run pylint, when installing your modules make sure to use the command for the correct version.

2. Missing __init__.py files

This error could also result from missing __init__.py files in your module folders. Make sure that you place one file in each sub-folder.

Loading history...
7
8
9
def sqs_publish(queue, message):
10
    _client = boto3.client('sqs')
11
12
    if queue.startswith('https://'):
13
        queue_url = queue
14
    else:
15
        response = _client.get_queue_url(QueueName=queue)
16
        queue_url = response['QueueUrl']
17
18
    return _client.send_message(QueueUrl=queue_url, MessageBody=message)
19
20
21
def sns_publish(topic, message):
22
    _client = boto3.client('sns')
23
    if topic.startswith('arn:'):
24
        arn = topic
25
    else:
26
        topics = _client.list_topics()
27
        for topic_data in topics['Topics']:
28
            if topic_data['TopicArn'].endswith(topic):
29
                arn = topic_data['TopicArn']
30
                break
31
32
    msg = json.dumps({'default': message})
33
    return _client.publish(TopicArn=arn, MessageStructure='json', Message=msg)
34