This file contains 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 python3 | |
import boto3 | |
import argparse | |
from time import sleep | |
def getInstanceIP(id): | |
resp = client.describe_instances(InstanceIds=[args.ec2]) | |
try: | |
return resp['Reservations'][0]['Instances'][0]['PublicIpAddress'] | |
except: |
This file contains 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
import tasks | |
from time import sleep | |
print("add 3+5") | |
ret = tasks.add.delay(3,5) | |
print("Task ID:") | |
print(ret) | |
sleep(10) #give SQS and your worker time enough to execute, so that you can check status on next line | |
print(ret.status) #this should say SUCCESS |
This file contains 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
#!/bin/bash | |
export AWS_ACCESS_KEY_ID="" | |
export AWS_SECRET_ACCESS_KEY="" | |
export AWS_REGION="" | |
export SQS_URL="" | |
apt-get update -qq | |
apt-get -qq -y install python3 git | |
curl -fsSL https://get.docker.com | bash - | |
curl -L "https://github.com/docker/compose/releases/download/1.25.5/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose | |
chmod +x /usr/local/bin/docker-compose |
This file contains 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
version: '2.0' | |
services: | |
worker: | |
image: python:3.8-alpine | |
command: ash -c "apk add --no-cache build-base libcurl curl-dev; pip3 install -r requirements.txt; celery -A tasks worker --loglevel=info" | |
volumes: | |
- "./app:/app" | |
working_dir: /app | |
restart: on-failure | |
environment: |
This file contains 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
from celery import Celery | |
app = Celery('tasks') | |
app.config_from_object('celeryconfig') | |
@app.task | |
def add(x, y): | |
#we're taking the example task you'd see first in celery docs. | |
return x + y |
This file contains 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
import os | |
#env vars used: | |
#AWS_REGION: specify which region you want to access SQS from. | |
#SQS_URL: The url of the sqs queue to listen for. The AWS keys are picked up | |
# from the environment vars that we'll add later while running the worker. | |
CELERY_BROKER_TRANSPORT_OPTIONS = { | |
'region': os.getenv('AWS_REGION','us-east-1'), | |
'predefined_queues': { | |
'default': { | |
'url': os.getenv('SQS_URL') |
This file contains 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
celery[sqs]==4.4 |