0

I am trying to run DAX sample getitem-test.js as a lambda.(doc link).I modified code to read from daxclient which I created. But daxClient.get returns error from lambda

START RequestId: bb657a02-05b1-11e8-804d-a1d27ac0e9f7 Version: $LATEST 2018-01-30T11:36:03.363Z bb657a02-05b1-11e8-804d-a1d27ac0e9f7 Unable to read item. Error JSON: { "time": 1517312163361, "code": "ValidationException", "retryable": true, "requestId": "AVI5QK8LN9S41B64JTTJVECLR3VV4KQNSO5AEMVJF66Q9ASUAAJG", "statusCode": "400", "_tubeInvalid": false, "waitForRecoveryBeforeRetrying": false }

I have setup dynamo db tables using dynamodbclient. setup VPC, subnets etc.. But I have no luck reading data from DAX. Any idea what could be the issue.

Following is the code I used:

var region = "eu-west-1";
AWS.config.update({
    region: region
});
var daxClient = null;
var dax = new AmazonDaxClient({ endpoints: ["mydax.e02jim.clustercfg.dax.euw1.cache.amazonaws.com:8111"], region: region })
daxClient = new AWS.DynamoDB.DocumentClient({ service: dax });
var tableName = "TryDaxTable";
var params = {
    TableName: tableName,
    Key: {
        "pk": 7,
        "sk": 1
    }
};
daxClient.get(params, function (err, data) {
    if (err) {
        console.error("Unable to read item. Error JSON:", 
JSON.stringify(err, null, 2));
    } else {
        console.log("success");
    }
});

I can get the result using var ddbClient = new AWS.DynamoDB.DocumentClient() instead of daxClient.

Also my lambda function is timed out

bharat
  • 1,762
  • 1
  • 24
  • 32
user2184972
  • 113
  • 1
  • 1
  • 6
  • Can you share the exact code you are using? ValidationException usually means that the request is incorrect in some way. – Jeff Hardy Jan 31 '18 at 16:26

1 Answers1

0

Found out that it was a permission issue. IAM role for my cluster did not have permission to DynamoDB table.

Regarding lambda timeout I added following code in the end after googling

context.callbackWaitsForEmptyEventLoop = false
callback(null, "success");
user2184972
  • 113
  • 1
  • 1
  • 6