+
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions sqs/producer/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
FROM python:3.9

ENV PIP_NO_CACHE_DIR=1

WORKDIR /app

RUN groupadd -r pyapp && useradd -r -s /bin/false -g pyapp pyapp \
&& chown -R pyapp:pyapp /app

USER pyapp

COPY requirements.txt .

RUN pip install -r requirements.txt -t .

COPY . .

CMD [ "python", "app.py"]
15 changes: 15 additions & 0 deletions sqs/producer/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# SQS producer

Send messages to an AWS SQS Queue.

## Configuration

Set the `SQS_QUEUE_URL` environment variable to the value of the SQS Queue
that will be used as the target.

## Usage

```console
docker run -e SQS_QUEUE_URL="https://sqs.<aws_region>.amazonaws.com/111111111111/my-queue" \
-it ghcr.io/tbobm/apps:sqs-producer-latest
```
45 changes: 45 additions & 0 deletions sqs/producer/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import os
from time import sleep

import boto3

# https://sqs.<aws_region>.amazonaws.com/111111111111/my-queue
QUEUE_URL = os.environ.get('SQS_QUEUE_URL')

def main():
# Create SQS client
sqs = boto3.client('sqs')

while True:
send_message(sqs)
sleep(5)

def send_message(sqs_client):
# Send message to SQS queue
response = sqs_client.send_message(
QueueUrl=QUEUE_URL,
DelaySeconds=1,
MessageAttributes={
'Title': {
'DataType': 'String',
'StringValue': 'The Whistler'
},
'Author': {
'DataType': 'String',
'StringValue': 'John Grisham'
},
'WeeksOn': {
'DataType': 'Number',
'StringValue': '6'
}
},
MessageBody=(
'Information about current NY Times fiction bestseller for '
'week of 12/11/2016.'
)
)
print(response['MessageId'])


if __name__ == "__main__":
main()
1 change: 1 addition & 0 deletions sqs/producer/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
boto3
点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载