forked from dschep/lambda-decorators
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhandler.py
More file actions
56 lines (40 loc) · 1.25 KB
/
handler.py
File metadata and controls
56 lines (40 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import json
import aiohttp
import asyncio
import async_timeout
from lambda_decorators import (
async_handler, load_json_body, json_http_resp, no_retry_on_failure, cors_headers)
async def fetch(session, url):
async with async_timeout.timeout(10):
async with session.get(url) as response:
return await response.json()
@async_handler
async def async_example():
async with aiohttp.ClientSession() as session:
return await asyncio.gather(
fetch(session, 'http://httpbin.org/delay/3'),
fetch(session, 'http://httpbin.org/delay/3'),
fetch(session, 'http://httpbin.org/delay/3'),
fetch(session, 'http://httpbin.org/delay/3'),
)
@load_json_body
def get_foo(event, context):
return {'body': event['body'].get('foo')}
@json_http_resp
def hello(event, context):
return {'hello': 'world'}
@no_retry_on_failure
def schedule_test(event, context):
raise Exception
@cors_headers('https://example.com')
@json_http_resp
def cors_customized(event, context):
return {}
@cors_headers(origin='https://example.com', credentials=True)
@json_http_resp
def cors_customized2(event, context):
return {}
@cors_headers
@json_http_resp
def cors_default(event, context):
return {}