에러 메시지
{
"errorType": "Runtime.ImportModuleError",
"errorMessage": "Error: Cannot find module 'athena-express'\nRequire stack:\n- /var/task/index.js\n- /var/runtime/index.mjs",
"trace": [
"Runtime.ImportModuleError: Error: Cannot find module 'athena-express'",
"Require stack:",
"- /var/task/index.js",
"- /var/runtime/index.mjs",
" at _loadUserApp (file:///var/runtime/index.mjs:726:17)",
" at async Object.module.exports.load (file:///var/runtime/index.mjs:741:21)",
" at async file:///var/runtime/index.mjs:781:15",
" at async file:///var/runtime/index.mjs:4:1"
]
}
람다 코드를 실행하는데 필요한 라이브러리가 설치된 런타임이 없다는 오류이다.
여기에서는 athena-express
가 설치되지 않았다.
해결책으로는 Lambda용 Node.js 코드에서 사용할 라이브러리가 포함된 배포 패키지 또는 Lambda 계층을 생성하면 된다.
해결
- 빈 디렉토리 생성
- 디렉토리에서 필요한 라이브러리 설치
- 압축
- aws lambda layer로 publish해주기
- 필요한 lambda에 arn으로 layer 추가하기
- 성공
- 코드
$ curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.34.0/install.sh | bash
$ . ~/.nvm/nvm.sh
$ nvm install node
$ mkdir nodejs
$ cd nodejs
$ npm init
$ npm install --save athena-express
$ cd ../
$ zip -r layer.zip nodejs
$ aws lambda publish-layer-version --layer-name athena --zip-file fileb://layer.zip --compatible-runtimes nodejs12.x --region ap-northeast-2
'에러목록' 카테고리의 다른 글
[lambda]Task timed out after 3.00 (0) | 2022.07.27 |
---|