AWS Lambda 오류 :“ '/ var / task / index'모듈을 찾을 수 없습니다.”
Node.js Alexa 작업 문제
저는 현재 AWS Lambda를 통해 Node.js Alexa 작업을 코딩하고 있으며 OpenWeather API에서 정보를 수신하고이를라는 변수로 구문 분석하는 함수를 코딩하려고했습니다 weather. 관련 코드는 다음과 같습니다.
var request = require('request');
var weather = "";
function isBadWeather(location) {
var endpoint = "http://api.openweathermap.org/data/2.5/weather?q=" + location + "&APPID=205283d9c9211b776d3580d5de5d6338";
var body = "";
request(endpoint, function (error, response, body) {
if (!error && response.statusCode == 200) {
body = JSON.parse(body);
weather = body.weather[0].id;
}
});
}
function testWeather()
{
setTimeout(function() {
if (weather >= 200 && weather < 800)
weather = true;
else
weather = false;
console.log(weather);
generateResponse(buildSpeechletResponse(weather, true), {});
}, 500);
}
이 스 니펫을 Cloud9 및 기타 IDE에서 수없이 실행했으며 완벽하게 작동하는 것 같습니다. 그러나 패키지에 압축하여 AWS Lambda에 업로드하면 다음 오류가 발생합니다.
{
"errorMessage": "Cannot find module '/var/task/index'",
"errorType": "Error",
"stackTrace": [
"Function.Module._load (module.js:276:25)",
"Module.require (module.js:353:17)",
"require (internal/module.js:12:17)"
]
}
나는 수많은 기사를 샅샅이 뒤지고 module-js, request 및이 코드를 실행해야하는 다른 많은 Node 모듈을 설치했지만이 문제를 해결할 수있는 것은 없습니다. 다음은 경우에 대비하여 내 디렉토리입니다.
- planyr.zip
- index.js
- node_modules
- package.json
문제가 무엇인지 아는 사람이 있습니까? 미리 감사드립니다.
고쳤다! 내 문제는 Finder에서 Mac의 내장 압축 기능을 사용하여 파일을 압축하려고 시도했다는 것입니다.
당신은 맥 사용자의 경우 당신이 (당신 포함 된 폴더 프로젝트의 루트 디렉토리에있을 때, 나처럼, 당신은 터미널에서 다음 스크립트를 실행해야합니다 index.js, node_modules등 파일).
zip -r ../yourfilename.zip *
Windows의 경우 :
Compress-Archive -LiteralPath node_modules, index.js -DestinationPath yourfilename.zip
허용 된 답변 업데이트 : 이 오류가 발생하면 zip 파일이 AWS에서 요구하는 유효한 형식이 아님을 의미합니다.
zip을 두 번 클릭하면 코드 파일 내에서 폴더를 찾을 수 있지만 람다는 zip을 두 번 클릭하면 직접 코드 파일이 표시되기를 원합니다.
이를 달성하려면 :
open terminal
cd your-lambda-folder
zip -r index.zip *
그런 다음 index.zipAWS Lambda에 업로드 합니다.
파일 이름과 핸들러 이름이 동일한 지 확인하십시오.
즉, 해당 zip파일에는 기능 bundle.js을 내보내는 파일이 handler있습니다.
exports.handler = (event, context, callback) => {//...}
This is probably a permissions issue with files inside your deployment zip. Try chmod 777 your files before packaging them in a zip file.
In my case it was because I had the handler file in inner src directory.
I had to change the 'Handler' property within Lambda from:
index.handler
to
src/index.handler
In my case the archive contained a folder "src" with index.js file, so I had to put to the handler: "src/index.handler"
In my case I had to replace
exports.handler = function eventHandler (event, context) {
with
exports.handler = function (event, context, callback) {
I got this error when I was using lambci/lambda:nodejs8.10 in windows.
I'd tried all of the solution listed above but none of which could help me deal with my issue(even though the error stack look the same as the question).
Here is my simple solution:
- using
--entrypointflag to run a container to find out if the file is mounted into the container. It turns out I may got the share drive issue with my Docker Desktop. - I switched my docker daemon that day before, but everything works fine except this problem.
- Anyway, remount my drive to Docker Desktop, you can both use the
dockercommand or just open the Docker Desktop setting to apply.
참고URL : https://stackoverflow.com/questions/41750026/aws-lambda-error-cannot-find-module-var-task-index
'programing tip' 카테고리의 다른 글
| Swift의 button.addTarget 액션에 매개 변수 첨부 (0) | 2020.09.13 |
|---|---|
| 일반 bash에서 regexp를 사용하여 부분 문자열 추출 (0) | 2020.09.13 |
| 다른 cmd.exe 프롬프트 내에서 새 cmd.exe 창을 만듭니다. (0) | 2020.09.13 |
| RequirementsApi 대 TargetApi 안드로이드 주석 (0) | 2020.09.12 |
| JS 객체를 정의하는이 방법에는 어떤 목적이 있습니까? (0) | 2020.09.12 |

