基本上我試圖從 API 網關調用 lambda 函數。該 API 是從我制作的 index.html 文件中調用的,該文件通過單擊按鈕調用 api 并返回值(最好是天氣)。我可以讓它返回一些文本值,但每當我嘗試使用節點獲取函數使用 lambda 函數實際調用 API 時,都會出現錯誤,提示“無法找到節點獲取模塊”。const fetch = require('node-fetch')module.exports.getTulsaCurrentWeather = (event, context, callback) => {//API endpointconst endpoint = `http://api.openweathermap.org/data/2.5/weather? APPID=${process.env.APPID}&q=Tulsa&units=imperial`;fetch(endpoint).then( res => res.json() ).then( body => {const response = { statusCode: 200, headers: { "Access-Control-Allow-Origin" : "*", }, body: JSON.stringify({ temperature: body.main.temp })};callback(null, response);});};
node-fetch 無法與 AWS lambda 函數一起使用(“找不到 node-fetch”)
隔江千里
2023-11-02 16:51:54