我正在尝试获取AWS Device Farm中的上传列表。我尝试使用Lambda的“ devicefarm.listUploads” 方法。
尝试按类型过滤时遇到问题。
var uploadList = devicefarm.listUploads({ arn: deviceFarmProject, type: 'IOS_APP' }).promise()
.then(res => res)
.catch(err => err);
期望是获取有关所有iOS应用程序的数据,但会遇到以下错误。
{
"message": "Unexpected key 'type' found in params",
"code": "UnexpectedParameter",
"time": "2019-05-02T15:49:35.351Z"
}
答案 0 :(得分:1)
~~我不确定为什么在这里无法识别类型~~
[编辑]
此错误的原因是由于AWS Lambda中的aws-sdk版本。 https://docs.aws.amazon.com/lambda/latest/dg/lambda-runtimes.html
Node.js运行时
名称标识符适用于JavaScript的AWS开发工具包 Node.js 8.10
nodejs8.10
2.290.0
我使用以下命令创建了一个Lambda层,并通过Web控制台将其应用于我的函数。
npm init
npm install aws-sdk
mkdir nodejs
cp -r node-modules nodejs
zip -r aws-sdk-layer.zip nodejs
注意。zip文件结构需要与Lambda文档示例匹配。 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)
用于Node.js的示例AWS X-Ray SDK
xray-sdk.zip └ nodejs/node_modules/aws-xray-sdk
应用该层后,我能够成功执行该功能。
但是我使用了以下内容,尽管我没有任何iOS上传,但它似乎可以正常工作。
// 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);
}
});
我在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;
});
};
在Lambda中的aws-sdk版本可能不是最新的,在这种情况下,您需要应用Lambda layer或将aws-sdk包括在代码包中。
我在本地执行此代码,它提供了以下输出:
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版本:aws-sdk@2.448.0
node --version
v8.12.0
HTH
詹姆斯