Amazon Lambda Java功能不会将数据插入DynamoDB [英] Amazon Lambda Java Function not insert data to DynamoDB

查看:658
本文介绍了Amazon Lambda Java功能不会将数据插入DynamoDB的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前,我正在使用 Amazon Webservices。


我使用 Eclipse IDE 。



在eclipse中创建函数后,我使用 JUnit测试测试函数eclipse。


Lambda函数成功执行,并将数据成功插入到 DynamoDB



但是问题是:



我使用AWS上的运行功能从Eclipse运行函数。 / p>

数据没有插入和抛出异常。



我也使用 API网关,但获得相同的异常。



异常: java.lang.IllegalArgumentException:在给定路径中找不到AWS凭证配置文件:/home/sbx_user1051/.aws/credentials



请朋友帮我解决这个问题


注意:我已经为Lambda功能和
DynamoDB添加了完整的权限。


我正在使用下面的代码将数据插入到 DynamoDB



DynamoDB dynamoDB = new DynamoDB(新的Amazon DynamoDBClient(新的ProfileCredentialsProvider(my_default_profile)));

表表= dynamoDB.getTable(TABLE_NAME);

String login_id =(String)inputHashMap.get(login_id);
String password =(String)inputHashMap.get(password);
String type =(String)inputHashMap.get(type);
String device_id =(String)inputHashMap.get(device_id);

尝试{
异常eItem item = new Item()。withPrimaryKey(login_id,login_id)
.withString(device_id,device_id)
.withBoolean (isUserVerified,false)
.withString(password,password)
.withString(type,type);

table.putItem(item);
}
catch(异常e){

}


解决方案

请尝试创建没有配置文件的DynamoDB对象。



DynamoDB dynamoDB = new DynamoDB新的AmazonDynamoDBClient());


Currently I am working with Amazon Webservices.
I create one Java lambda function using Eclipse IDE.

After created function in eclipse I test function eclipse using JUnit Test.
Lambda function execute successfully and also inserted data successfully to DynamoDB.

But problem is :

I run function on lambda from Eclipse using Run Function on AWS Lambda functionality.

Data is not inserting and its throwing exception.

I also test this method using API Gateway but get same exception.

Exception : java.lang.IllegalArgumentException: AWS credential profiles file not found in the given path: /home/sbx_user1051/.aws/credentials

Please Friends Help me to solve this problem.

NOTE : I already added full permission for both Lambda Function and DynamoDB.

I am using below code to insert Data to DynamoDB.

DynamoDB dynamoDB = new DynamoDB(new AmazonDynamoDBClient(new ProfileCredentialsProvider("my_default_profile")));

Table table = dynamoDB.getTable(TABLE_NAME);

String login_id = (String) inputHashMap.get("login_id");
String password = (String) inputHashMap.get("password");
String type = (String) inputHashMap.get("type");
String device_id = (String) inputHashMap.get("device_id");

try {
    Exception eItem item = new Item().withPrimaryKey("login_id", login_id)
        .withString("device_id", device_id)
        .withBoolean("isUserVerified", false)
        .withString("password", password)
        .withString("type", type);

    table.putItem(item);
}
catch(Exception e){

}

解决方案

Please try creating the DynamoDB object without a profile.

DynamoDB dynamoDB = new DynamoDB(new AmazonDynamoDBClient());

这篇关于Amazon Lambda Java功能不会将数据插入DynamoDB的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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