I try to use layers of AWS Lambda, watched a tutorial about it, but I get an error "cannot find module ..."
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
When i deploy it, i don't have any errors in my terminal, and on AWS, i see my layer and when i download it, i have my package.json
with moment dependency, and the node_modules folder with moment
my handler.js looks like this :
'use strict';
module.exports.hello = async (event, context) => {
const moment = require('moment')
const a = moment('2016-01-01')
return {
statusCode: 200,
body: JSON.stringify({
message: 'Hey' + a
}),
};
};
My files structure :
testLayer/
node_modules/
moment/
package.json
serverless.yml
handler.js
package.json
Do you have any idea of what i doing wrong ?