When I try to invoke the lambda
function using a public url I don't see any output.
# Lambda function
import json
import hmac, base64, struct, hashlib, time
sec = 'my_secret'
def get_hotp_token(secret, intervals_no):
key = base64.b32decode(secret, True)
msg = struct.pack(">Q", intervals_no)
h = hmac.new(key, msg, hashlib.sha1).digest()
o = h[19] & 15
h = (struct.unpack(">I", h[o:o 4])[0] & 0x7fffffff) % 1000000
return h
def get_totp_token(secret):
return get_hotp_token(secret, intervals_no=int(time.time())//30)
def lambda_handler(event, totp):
# totp = get_totp_token(sec)
# print(totp)
return {
'statusCode' : 200,
'totp' : get_totp_token(sec)
}
When I test the function using aws-console
I get the desired output.
I went to Configuration---->Function URL---->Create Function Url---->Auth type---->None----> Cors---->Yes
. Saved with default settings of CORS
.
Now when I use the URL I get a blank page.
CodePudding user response:
Lamba body response should be a string, Not an object/ dict. If you want to return a dict you'l need to stringify it.