Sarath
Sarath

Reputation: 376

How to fix AWS Device farm SDK error Unexpected key 'type' found in params

I am trying to get the list of uploads in the AWS Device Farm. I tried to use the method "devicefarm.listUploads" from Lambda.

I am facing an issue when I am trying to filter it by type.

var uploadList = devicefarm.listUploads({ arn: deviceFarmProject, type: 'IOS_APP' }).promise()
  .then(res => res)
  .catch(err => err);

The expectation is to get data about all the iOS apps, but getting the bellow error.

{
    "message": "Unexpected key 'type' found in params",
    "code": "UnexpectedParameter",
    "time": "2019-05-02T15:49:35.351Z"
}

Upvotes: 1

Views: 6256

Answers (1)

jmp
jmp

Reputation: 2375

~~I'm not sure why the type isn't recognized here~~

[Edit]

The reason for this error is due to the version of the aws-sdk in AWS Lambda. https://docs.aws.amazon.com/lambda/latest/dg/lambda-runtimes.html

Node.js Runtimes

Name Identifier AWS SDK for JavaScript Node.js 8.10

nodejs8.10

2.290.0

I created a Lambda layer with the following commands and applied it to my function through the web console.

npm init
npm install aws-sdk
mkdir nodejs
cp -r node-modules nodejs
zip -r aws-sdk-layer.zip nodejs

note the zip file structure needs to match the Lambda documentation example. https://docs.aws.amazon.com/lambda/latest/dg/configuration-layers.html#configuration-layers-path

Node.js – nodejs/node_modules, nodejs/node8/node_modules (NODE_PATH)

Example AWS X-Ray SDK for Node.js

xray-sdk.zip └ nodejs/node_modules/aws-xray-sdk

after I applied the layer I was able to execute the function successfully.


but I used the following and it seemed to work though I didn't have any iOS uploads.

// assume we already executed `npm install aws-sdk`
var AWS = require('aws-sdk');
// Device Farm is only available in the us-west-2 region
var devicefarm = new AWS.DeviceFarm({ region: 'us-west-2' });

var params = {};
devicefarm.listProjects(params, function (err, projects) {
    if (err) console.log(err, err.stack); // an error occurred
    else{
        project = projects.projects[0];
        console.log("project: ", project);
        uploadList = devicefarm.listUploads({ arn: project.arn, type: 'IOS_APP' }).promise()
            .then(function(uploadList){
                console.log("uploads: ",uploadList);
            })
            .catch(err => err);
    }
});

code I executed in Lambda

// assume we already executed `npm install aws-sdk`
var AWS = require('aws-sdk');
// Device Farm is only available in the us-west-2 region
var devicefarm = new AWS.DeviceFarm({ region: 'us-west-2' });

exports.handler = async (event) => {

    return new Promise(function (resolve, reject) {
        var params = {};
        devicefarm.listProjects(params, function (err, projects) {
            if (err) reject(err); // an error occurred
            else {
                var project = projects.projects[0];
                console.log("project: ", project);
                resolve(project);
            }
        });
    }).then(function(data){
        console.log("in then function","data: ",data);
        return new Promise(function(resolve,reject){
            devicefarm.listUploads({ arn: data.arn, type: 'IOS_APP' }, function(err,uploads){
                if (err) reject(err); // an error occurred
                else {
                    resolve(uploads);
                }
            })
        }).then(function(data){
            console.log("uploads: ", data);
            return data;
        }).catch(function(data){
            console.error("list uploads failed","data: ", data);
            return data;
        });
    }).catch(function(data){
        console.error("list projects failed","data: ",data);
        return data;
    });

};

It might be the case that the aws-sdk version in Lambda isn't up to date in which case you would need to apply a Lambda layer or include the aws-sdk in the code package.

Locally I executed this code and it provided the following output:

node sample.js
project:  { arn: 'arn:aws:devicefarm:us-west-2:111122223333:project:00ec5d2a-9170-4c52-b65e-0e12986e4fc3',
  name: 'web_app_test',
  created: 2019-02-10T22:47:35.052Z }
uploads:  { uploads: [] }

aws-sdk version: [email protected]

node --version v8.12.0

HTH

James

Upvotes: 1

Related Questions