Django POST listener in Elastic Beanstalk to receive AWS level working requests

I am trying to set up a work environment to run a background task. I have the same version of the application running in two environments, one of which is a web server and the other is a working one.

I need to delete files periodically according to the expiration date. I mapped the view as a URL on the local host where messages will be redirected as HTTP POST requests . The job is scheduled and looks like starting SQS, but all messages are in WorkerDeadLetterQueue .

In the log file I received the requests made, but error 403:

/ var / Log / HTTPD / access_log:

"POST / networks_app / delete_expired_files HTTP / 1.1" 403 2629 "-" "aws-sqsd / 2.0"

and this is in /var/log/aws-sqsd/default.log :

message: sent to% [ http: // localhost: 80 / networks_app / delete_expired_files] 2016-01-23T14: 58: 05Z http-err: d5f645cf-ce15-40bc-8ee3-34acb79e797b (4) 403 - 0.007

Here is my views.py code :

def delete_expired_files(request):
    if request.method == 'POST':
        users = DemoUser.objects.all()
        for user in users:
            documents = Document.objects.filter(owner=user.id)
            if documents:
                for doc in documents:
                    now = timezone.now()
                    if now >= doc.date_published + timedelta(days = doc.owner.group.valid_time):
                        doc.delete()

Cron.yaml file :

version: 1
cron:
 - name: "delete_expired_files"
   url: "/networks_app/delete_expired_files"   
   schedule: "* * * * *" 

If I access the URL through the browser, it works, it shows the GET request in the log file on my web application server.

, ?
, , 403?
?
Django?
?

+4
1

SQS, POST, CSRF, "403 Forbidden".

csrf_exempt:

from django.http import HttpResponse
from django.views.decorators.csrf import csrf_exempt

@csrf_exempt
def index(request):
    return HttpResponse("hello, world")
0

Source: https://habr.com/ru/post/1625654/


All Articles