-
Notifications
You must be signed in to change notification settings - Fork 0
/
insertStudentData.py
31 lines (27 loc) · 972 Bytes
/
insertStudentData.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
import json
import boto3
# Create a DynamoDB object using the AWS SDK
dynamodb = boto3.resource('dynamodb')
# Use the DynamoDB object to select our table
table = dynamodb.Table('Your DynamoDB table name')
# Define the handler function that the Lambda service will use as an entry point
def lambda_handler(event, context):
# Extract values from the event object we got from the Lambda service and store in variables
student_id = event['studentid']
name = event['name']
student_class = event['class']
age = event['age']
# Write student data to the DynamoDB table and save the response in a variable
response = table.put_item(
Item={
'studentid': student_id,
'name': name,
'class': student_class,
'age': age
}
)
# Return a properly formatted JSON object
return {
'statusCode': 200,
'body': json.dumps('Student data saved successfully!')
}