应用程序需要在后台运行定期任务以删除过期文件 . 该应用程序已启动并在Web服务器和工作器层环境中运行 .
cron.yaml 文件位于应用的根目录:
version: 1
cron:
- name: "delete_expired_files"
url: "/networks_app/delete_expired_files"
schedule: "*/10 * * * *"
cron网址指向应用 view :
def delete_expired_files(request):
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()
Django ALLOWED_HOSTS 设置如下:
ALLOWED_HOSTS = ['127.0.0.1', 'localhost', 'networksapp.elasticbeanstalk.com']
正在安排任务,查询正在将请求发送到正确的URL,但是他们要去 WorkerDeadLetterQueue
工作器层环境日志文件显示 403 错误:
“POST / networks_app / delete_expired_files HTTP / 1.1”403 1374“ - ”“aws-sqsd / 2.0”
任务未执行(过期文件未被删除) . 但是当我访问url时,它会正确执行任务 .
我需要让它自动定期工作 .
我的 IAM 用户有此政策:
AmazonSQSFullAccess AmazonS3FullAccess AmazonDynamoDBFullAccess AdministratorAccess AWSElasticBeanstalkFullAccess
为什么不执行任务?这与任何IAM权限有关吗?有没有丢失的配置?如何使它工作?提前致谢 .