0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Django+Celery+SQSをLocalStackで動かす

Posted at

これに関連して、LocalStackでローカルで試す方法です

Dockerの設定

docker/localstack/start.sh
# キューの作成
awslocal sqs create-queue --queue-name csv-upload.fifo --attributes "FifoQueue=true,ContentBasedDeduplication=true,VisibilityTimeout=3600"
awslocal sqs create-queue --queue-name send-message --attributes "VisibilityTimeout=300"
docker-compose.yml
version: "3.8"

services:
    localstack:
        image: localstack/localstack:0.14.5
        ports:
            - 34566:4566
        environment:
            DEFAULT_REGION: ap-northeast-1
            DATA_DIR: /tmp/localstack/data
            SERVICES: s3,sqs
        volumes:
            - ./docker/localstack/:/docker-entrypoint-initaws.d
            - ./docker/localstack/tmp:/tmp/localstack

細かい設定はそのプロジェクトに合わせていただければいいと思いますが
重要なのはdocker-entrypoint-initaws.dstart.shを置いて、コンテナ起動時にキューを作成させることです(docker-entrypoint-initaws.dにスクリプトを置くとコンテナ起動時にそれが実行される)

LocalStack設定

基本的には こちらと同じですが、以下だけ変更します

settings.py
# localstack:4566を追記する
CELERY_BROKER_URL = "sqs://{aws_access_key}:{aws_secret_key}@localstack:4566".format(
    aws_access_key=urllib.parse.quote(AWS_ACCESS_KEY_ID, safe=''), 
    aws_secret_key=urllib.parse.quote(AWS_SECRET_ACCESS_KEY, safe=''),
)

CELERY_BROKER_TRANSPORT_OPTIONS = {
    'region': 'ap-northeast-1',
    'predefined_queues': {
        'csv-upload.fifo': {
            # URLはhttp://localstack:4566/000000000000/
            'url': 'http://localstack:4566/000000000000/csv-upload.fifo',
        },
        'send-message': {
            'url': 'http://localstack:4566/000000000000/send-message',
        }
    }
}

以上です

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?