-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.py
44 lines (33 loc) · 1.31 KB
/
index.py
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
"""
Roman Numerals converter - Amazon Lambda web service
Just push to master, and the code will get pulled through the CodeStar build pipeline.
To invoke the service, do an
HTTPS GET https://blahblahblah.execute-api.us-east-2.amazonaws.com/Prod?roman=XXX
where XXX is the Roman number to convert to Arabic.
Examples:
$ curl https://blahblahblah.execute-api.us-east-2.amazonaws.com/Prod?roman=I
1
$ curl https://blahblahblah.execute-api.us-east-2.amazonaws.com/Prod?roman=V
5
"""
import logging
from roman import convert
def handler(event, context):
"""AWS Lambda action handler"""
logger = logging.getLogger()
logger.setLevel(logging.INFO)
logger.info('event is: %s', str(event))
parameters = event['queryStringParameters']
if parameters is None:
logger.info('Received no arguments. Returning documentation.')
body = 'I convert Roman numerals to Arabic integers. ' \
'To invoke me, use the ?roman= parameter. For example: ?roman="V" '
else:
roman = parameters['roman']
logger.info('Received argument ?roman="%s', roman)
arabic = str(convert(roman))
logger.info('Returning arabic %s', arabic)
body = arabic
return {'statusCode': 200,
'body': body,
'headers': {'Content-Type': 'text/plain'}}