Last active
July 11, 2024 12:08
-
-
Save MahirMahbub/f9c226dbc0a01da22c8c539cf9c9bcc9 to your computer and use it in GitHub Desktop.
Config for AWS Beanstalk Linux 2 Django Celery Deployment with Amazon SQS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# Create the celery systemd service file | |
echo "[Unit] | |
Name=Celery | |
Description=Celery service for __ | |
After=network.target | |
StartLimitInterval=0 | |
[Service] | |
Type=simple | |
Restart=always | |
RestartSec=30 | |
User=root | |
WorkingDirectory=/var/app/current | |
ExecStart=$PYTHONPATH/celery -A config worker --loglevel=INFO | |
ExecReload=$PYTHONPATH/celery -A config worker --loglevel=INFO | |
EnvironmentFile=/opt/elasticbeanstalk/deployment/env | |
[Install] | |
WantedBy=multi-user.target | |
" | tee /etc/systemd/system/celery.service | |
# Start celery service | |
systemctl start celery.service | |
# Enable celery service to load on system start | |
systemctl enable celery.service |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
source ${PYTHONPATH}/activate && ${PYTHONPATH}/pip3 install pycurl --global-option="--with-openssl" --upgrade |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
packages: | |
yum: | |
libcurl-devel: [] | |
openssl-static.x86_64: [] | |
python3-devel: [] | |
gcc: [] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
container_commands: | |
01_install_requirements: | |
command: "source /var/app/venv/*/bin/activate && pip3 install -r requirements.txt" | |
leader_only: true | |
02_migrate: | |
command: "ls /var/app/venv/*/bin && source /var/app/venv/*/bin/activate && python3 manage.py migrate" | |
leader_only: true |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
option_settings: | |
aws:elasticbeanstalk:container:python: | |
WSGIPath: config.wsgi:application | |
aws:elasticbeanstalk:application:environment: | |
DJANGO_SETTINGS_MODULE: config.settings |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# AWS config | |
AWS_ACCESS_KEY_ID = config("AWS_ACCESS_KEY_ID", "") | |
AWS_SECRET_ACCESS_KEY = config("AWS_SECRET_ACCESS_KEY", "") | |
# CELERY SETTINGS | |
BROKER_URL = f"sqs://{AWS_ACCESS_KEY_ID}:{AWS_SECRET_ACCESS_KEY}@" | |
BROKER_TRANSPORT_OPTIONS = { | |
"region": "ap-southeast-2", | |
"polling_interval": 60, | |
'visibility_timeout': 3600, | |
'queue_name_prefix': <app-name>, | |
} | |
CELERY_DEFAULT_QUEUE = "sqs" | |
CELERY_ACCEPT_CONTENT = ["application/json"] | |
CELERY_TASK_SERIALIZER = "json" | |
CELERY_RESULT_SERIALIZER = "json" | |
# CELERY_CONTENT_ENCODING = "utf-8" | |
# CELERY_ENABLE_REMOTE_CONTROL = False | |
# CELERY_SEND_EVENTS = False | |
# Reason why we need the above is explained in Configuration Gotchas section. | |
# SQS_QUEUE_NAME = "<app-name>sqs" | |
# CELERY_BROKER_URL = BROKER_URL | |
CELERY_BROKER_TRANSPORT_OPTIONS = BROKER_TRANSPORT_OPTIONS | |
CELERY_TASK_DEFAULT_QUEUE = "sqs" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment