我有以下Lambda函數,我通過遵循一個PluralSight教程編寫[我對js知之甚少。這樣做是爲了學習API網關< - > LAMBDA教程]爲什麼我的Lambda函數在完成請求之前退出?
我已經寫了完全相同的功能,只有{}
作爲測試JSON:
var faker = require('faker');
exports.handler = function(event, context){
var inventory = [];
for(var i = 0; i < 10; i++){
var shoe = {};
var shoeType = getShoeType();
shoe.name = getShoeName(shoeType);
shoe.color = getShoeColor();
shoe.description = getShoeDescription(showType);
shoe.size = getShoeSize();
shoe.price = getShoePrice();
inventory.push(shoe);
}
context.succeed(inventory);
}
function getShoeName(showType){
return faker.company.catchPhraseNoun() + " " + faker.company.catchPhraseDescriptor() +
" " + showType;
}
function getShoeColor(){
return faker.commerce.color();
}
function getShoeDescription(shoeType){
return "A(n)" + faker.commerce.productAdjective() + ", " + faker.commerce.productAdjective() +
" " + shoeType + "made from the finest " + faker.commerce.productMaterial() + "designed for the " +
faker.commerce.bsBuzz() + " individual!";
}
function getShoeSize(){
return getNum(1, 13);
}
function getShoePrice(){
return faker.commerce.price();
}
function getShoeType(){
var shoeType = [
"running shoes",
"training shoes",
"tennis shoe",
"cricket shoe",
"other shoe"
]
return shoeType[getNum(0, 5)];
}
function getNum(min, max){
return Math.floor(Math.random() * (max - min +1)) + min;
}
然而,LAMBDA是給這個錯誤:
{
"errorMessage": "RequestId: e5566a3c-1df8-11e7-8b71-d961323b4fcf Process exited before completing request"
}
我也檢查了我的context.succeed()
的位置,它完全沒問題。
那麼,我哪裏出錯了?
那些faker調用可能需要一點時間才能返回。不熟悉亞馬遜lambda,但如果他們像天藍色的功能,你是有時間限制的。你只是花了太長時間?您可以嘗試用硬編碼值替換faker代碼,並測試該理論。 – Will