forked from Explore-AI/cloud-computing-predict
-
Notifications
You must be signed in to change notification settings - Fork 0
/
basic_lambda_data_decoding.py
48 lines (39 loc) · 1.75 KB
/
basic_lambda_data_decoding.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
45
46
47
48
"""
Initial AWS Lambda function is used to decode POST-request data received from the
student portfolio website.
Author: Explore Data Science Academy.
Note:
---------------------------------------------------------------------
The contents of this file should be added to a AWS Lambda function
created as part of the EDSA Cloud-Computing Predict.
For further guidance around this process, see the README instruction
file which sits at the root of this repo.
---------------------------------------------------------------------
"""
# Lambda dependencies
import boto3 # Python AWS SDK
import json # Used for handling API-based data.
import base64 # Needed to decode the incoming POST data
def lambda_handler(event, context):
# Perform JSON data decoding
body_enc = event['body']
dec_dict = json.loads(base64.b64decode(body_enc))
# Note that all of the POST data from our website form can now
# be accessed via the `dec_dict` dictionary object.
# For example, if we entered the name field as 'Student_name on the website' :
# >>> dec_dict['name']
# 'Student_name'
# Create a response object to tell the website that the form data
# was successfully received. We use the contents of the decoded JSON dictionary
# to create this response. As the predict progresses, we'll include
# more information about the AWS services we will invoke.
lambda_response = {
'statusCode': 200, # <-- Tells the website that everything executed successfully.
'body': json.dumps({
'Name': dec_dict['name'],
'Email': dec_dict['email'],
'Cell': dec_dict['phone'],
'Message': dec_dict['message']
})
}
return lambda_response