Skip to content

Amazon AWS - Simple Queue Service (SQS)

Nothing can be simpler to interact with AWS Simple Queue Service (SQS) than the BotCity plugin for AWS Lambda.

Create queues, send and receive messages and much more.

Installation

pip install botcity-aws-sqs-plugin

Importing the Plugin

After you installed this package, the next step is to import the package into your code and start using the functions.

from botcity.plugins.aws.sqs import BotAWSSQSPlugin

Setting up connection

Note

There are two different ways to authenticate.

1. Creating the .aws folder in the home directory, you need to create two files.

# ~/.aws/config
[default]
region=<region_code>
# ~/.aws/credentials
[default]
aws_access_key_id=<your_aws_access_key_id>
aws_secret_access_key=<your_aws_secret_access_key>

2. Passing credentials in the class constructor.

# Using the `.aws` folder
sqs = BotAWSSQSPlugin()

# Alternative using the credentials as constructor arguments
sqs = BotAWSSQSPlugin(
    use_credentials_file=False,
    access_key_id='<your_aws_access_key_id>',
    secret_access_key='<your_aws_secret_access_key>',
    region_name='<region_code>'  # default-region='us-east-1'
)

Info

You can set default queue_name and queue_url.

sqs = BotAWSSQSPlugin()
sqs.queue_name = '<queue_name>'
sqs.queue_url = '<queue_url>'

Queue operations

Create a queue

from botcity.plugins.aws.sqs import BotAWSSQSPlugin

sqs = BotAWSSQSPlugin()
response = sqs.create_queue(queue_name="test-123")
print(response)

List queues

from botcity.plugins.aws.sqs import BotAWSSQSPlugin

sqs = BotAWSSQSPlugin()
queues = sqs.list_queues()
print(queues)

Get queue url

from botcity.plugins.aws.sqs import BotAWSSQSPlugin

sqs = BotAWSSQSPlugin()
queue_url = sqs.get_queue_url(queue_name="test-123")
print(queue_url)

Delete queue

from botcity.plugins.aws.sqs import BotAWSSQSPlugin

sqs = BotAWSSQSPlugin()
sqs.delete_queue(queue_url="QUEUE_URL_HERE")

Message Queue operations

Send message

Info

message_body can be a string or a dict.

from botcity.plugins.aws.sqs import BotAWSSQSPlugin

sqs = BotAWSSQSPlugin()
response = sqs.send_message(queue_url="QUEUE_URL_HERE", message="Hello world!")
print(response)

Receive message

from botcity.plugins.aws.sqs import BotAWSSQSPlugin

sqs = BotAWSSQSPlugin()
response = sqs.receive_message(queue_url="QUEUE_URL_HERE")
print(response)

Delete message

from botcity.plugins.aws.sqs import BotAWSSQSPlugin

sqs = BotAWSSQSPlugin()
response = sqs.delete_message(queue_url="QUEUE_URL_HERE", receipt_handle="RECEIPT_HANDLE_HERE")
print(response)