如何将AWS Lambda与python一起放入aws DynamoDb中 [英] how to put an Item in aws DynamoDb using aws Lambda with python

查看:203
本文介绍了如何将AWS Lambda与python一起放入aws DynamoDb中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在AWS Lambda中使用python,如何从DynamoDB表中放置/获取项目?

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

在Node.js中,这类似于:

In Node.js this would be something like:

dynamodb.getItem({
    "Key": {"fruitName" : 'banana'},
    "TableName": "fruitSalad"
}, function(err, data) {
    if (err) {
        context.fail('Incorrect username or password');
    } else {
        context.succeed('yay it works');
    }
});

我需要的只是python等效项。

All I need is the python equivalent.

推荐答案

使用Boto3 (最新的适用于python的AWS开发工具包)

Using Boto3 (Latest AWS SDK for python)

您可以使用

import boto3

然后通过以下方式致电客户

Then call the client via

dynamodb = boto3.client('dynamodb')

获取商品示例

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

放置项目示例

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

'S'表示字符串值,'N'是数字值

'S' indicates a String value, 'N' is a numeric value

有关其他数据类型,请参考 http://boto3.readthedocs.org/en/latest/ref erence / services / dynamodb.html#DynamoDB.Client.put_item

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

这篇关于如何将AWS Lambda与python一起放入aws DynamoDb中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆