close

how to put an Item in aws DynamoDb using aws Lambda with python

Hello Guys, How are you all? Hope You all Are Fine. Today We Are Going To learn about how to put an Item in aws DynamoDb using aws Lambda with python in Python. So Here I am Explain to you all the possible Methods here.

Without wasting your time, Let’s start This Article.

Table of Contents

how to put an Item in aws DynamoDb using aws Lambda with python?

  1. how to put an Item in aws DynamoDb using aws Lambda with python?

    Using Boto3 (Latest AWS SDK for python)
    You import it with
    import boto3

  2. put an Item in aws DynamoDb using aws Lambda with python

    Using Boto3 (Latest AWS SDK for python)
    You import it with
    import boto3

Method 1

Using Boto3 (Latest AWS SDK for python)

You import it with

import boto3

Then call the client via

dynamodb = boto3.client('dynamodb')

Get item example

dynamodb.get_item(TableName='fruitSalad', Key={'fruitName':{'S':'Banana'}})

Put item example

dynamodb.put_item(TableName='fruitSalad', Item={'fruitName':{'S':'Banana'},'key2':{'N':'value2'}})

‘S’ indicates a String value, ‘N’ is a numeric value

Method 2

Using latest AWS SDK

import boto3

def lambda_handler(event, context):
    # this will create dynamodb resource object and
    # here dynamodb is resource name
    client = boto3.resource('dynamodb')

    # this will search for dynamoDB table 
    # your table name may be different
    table = client.Table("dynamoDB")
    print(table.table_status)

    table.put_item(Item= {'id': '34','company':  'microsoft'})

If your are using AWS you can use this code sample, only you have to give permissions to this lambda function

Conclusion

It’s all About this issue. Hope all Methods helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which Method worked for you? Thank You.

Also, Read