-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathlambda_test.py
39 lines (33 loc) · 1.03 KB
/
lambda_test.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
import json
import jwt
def lambda_handler(event, context):
secret_key = 'secret-key'
# Data payload you want to encode
payload = {
'user_id': 123,
'email': '[email protected]'
}
try:
# Encoding the payload with the secret key
encoded_jwt = jwt.encode(payload, secret_key, algorithm='HS256')
print(f"Encoded JWT: {encoded_jwt}")
# Decoding the payload with the secret key
decoded_jwt = jwt.decode(encoded_jwt, secret_key, algorithms=['HS256'])
print(f"Decoded JWT: {decoded_jwt}")
return {
'statusCode': 200,
'body': json.dumps({
'message': 'JWT encoded and decoded successfully!',
'encoded': encoded_jwt,
'decoded': decoded_jwt
})
}
except Exception as e:
print(e)
return {
'statusCode': 500,
'body': json.dumps({
'message': 'An error occurred',
'error': str(e)
})
}