Navigate to the AWS Lambda Console
Configure the Function Settings:
book_create
Implement the Function Code:
import boto3
import json
client = boto3.resource('dynamodb')
def lambda_handler(event, context):
book_item = event["body"]
error = None
try:
table = client.Table('Books')
table.put_item(Item = book_item)
except Exception as e:
error = e
if error is None:
response = {
'statusCode': 200,
'body': 'writing to dynamoDB successfully!',
'headers': {
'Content-Type': 'application/json'
},
}
else:
response = {
'statusCode': 400,
'body': 'writing to dynamoDB fail!',
'headers': {
'Content-Type': 'application/json'
},
}
return response
Set up DynamoDB Access:
Add DynamoDB Policy:
Create a Test Event:
test_1
{
"body": {
"id": "1",
"name": "Java",
"author": "Alex",
"category": "IT",
"price": "10.89",
"description": "This book guide to create Java web basic",
"image": "https://book-image-resize-store.s3.us-east-1.amazonaws.com/Java.jpg"
}
}
Access Your DynamoDB Table:
View Table Items:
Review the Data: