-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlambda_function.txt
More file actions
37 lines (28 loc) · 921 Bytes
/
lambda_function.txt
File metadata and controls
37 lines (28 loc) · 921 Bytes
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
import json
import boto3
from time import gmtime, strftime
dynamodb = boto3.resource('dynamodb')
table = dynamodb.Table('BinaryCalculator')
now = strftime("%a, %d %b %Y %H:%M:%S +0000", gmtime())
def lambda_handler(event, context):
userInputNum = str(event['userInputNum'])
userInputBase = int(event['userInputBase'])
result = ''
decimalConversion = 0
userInputNum = userInputNum[::-1]
for i, digit in enumerate(userInputNum):
decimalConversion += int(digit) * (2 ** i)
result = ''
while decimalConversion > 0:
remainder = decimalConversion % userInputBase
result = str(remainder) + result
decimalConversion //= userInputBase
response = table.put_item(
Item={
'ID': result,
'LatestGreetingTime':now
})
return {
'statusCode': 200,
'body': json.dumps('Your result is ' + result)
}