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

前端 未结 3 986
闹比i
闹比i 2021-02-01 01:50

Using python in AWS Lambda, how do I put/get an item from a DynamoDB table?

In Node.js this would be something like:

dynamodb.getItem({
    \"Key\": {\"f         


        
3条回答
  •  孤城傲影
    2021-02-01 02:12

    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

    For other data types refer http://boto3.readthedocs.org/en/latest/reference/services/dynamodb.html#DynamoDB.Client.put_item

提交回复
热议问题