Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions dj_elastictranscoder/views.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import json
import requests

from django.http import HttpResponse, HttpResponseBadRequest
from django.views.decorators.http import require_http_methods
from django.views.decorators.csrf import csrf_exempt
from django.core.mail import mail_admins

Expand All @@ -12,29 +14,28 @@
)

@csrf_exempt
@require_http_methods(["GET", "POST"])
def endpoint(request):
"""
Receive SNS notification
"""

try:
data = json.loads(request.read().decode('utf-8'))
except ValueError:
return HttpResponseBadRequest('Invalid JSON')


# handle SNS subscription
if data['Type'] == 'SubscriptionConfirmation':
subscribe_url = data['SubscribeURL']
requests.get(subscribe_url)
subscribe_body = """
Please visit this URL below to confirm your subscription with SNS
This URL will confirm your subscription with SNS. I've already visited it, but you can too!

%s """ % subscribe_url

mail_admins('Please confirm SNS subscription', subscribe_body)
return HttpResponse('OK')
return HttpResponse('Subscription confirmed')


#
try:
message = json.loads(data['Message'])
Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
install_requires=[
"django >= 1.8",
"boto3 >= 1.1",
"requests",
],
classifiers=[
"Intended Audience :: Developers",
Expand Down