我尝试使用无服务器 Lambda 层,我看过有关它的教程,但结果出现错误“找不到模块......”
service: aws-nodejs
package:
exclude:
- .gitignore
- package.json
- .git/**
provider:
name: aws
profile: sandbox
runtime: nodejs12.x
layers:
testLayer:
path: testLayer
compatibleRuntimes:
- nodejs12.x
allowedAccounts:
- '*'
functions:
hello:
handler: handler.hello
layers:
- arn:aws:lambda:us-east-1:*:layer:testLayer:15
events:
- http:
path: test
method: get
cors: true
Run Code Online (Sandbox Code Playgroud)
当我部署它时,我的终端中没有任何错误,在 AWS 上,我看到了我的层,当我下载它时,我有我的 package.json 和 moment 依赖项,以及带有 moment 的 node_modules 文件夹
我的 handler.js 看起来像这样:
'use strict';
module.exports.hello = async (event, context) => {
const moment = require('moment')
const a = moment('2016-01-01')
return {
statusCode: …Run Code Online (Sandbox Code Playgroud)