I keep getting this error and I don't know what is causing it.
I am having an API that based on a condition will post to another API, but I get this error in my wrapping API.
Here is the code ...
handler.js
'use strict';
const axios = require('axios');
module.exports.thumbnailWrapperAPI = (event, context, callback) => {
const incomingData = JSON.parse(event.body);
if(incomingData.source.includes('png') || incomingData.source.includes('jpg')){
const newLocal = 'some endpoint...';
// call image resizing API...
axios.post(newLocal,{
source: incomingData.source,
target: incomingData.target,
width: incomingData.width
})
.then(response => callback(null,response))
.catch(error => callback(error))
} else if(incomingData.source.includes('html')) {
// handle HTML
} else {
//...
};
};
serverless.yaml
service: thumbnailWrapperAPI
provider:
name: aws
runtime: nodejs8.10
region: eu-west-1
functions:
thumbnailWrapperAPI:
handler: handler.thumbnailWrapperAPI
events:
- http:
path: generatethumbnail/
method: post
cors: true
Any advice would be appreciated.
ERROR MESSAGE:
Unable to import module 'handler': Error
at Function.Module._resolveFilename (module.js:547:15)
at Function.Module._load (module.js:474:25)
at Module.require (module.js:596:17)
at require (internal/module.js:11:18)
at Object.<anonymous> (/var/task/handler.js:2:15)
at Module._compile (module.js:652:30)
at Object.Module._extensions..js (module.js:663:10)
at Module.load (module.js:565:32)
at tryModuleLoad (module.js:505:12)
at Function.Module._load (module.js:497:3)
To resolve this error, create a deployment package or Lambda layer that includes the libraries that you want to use in your Python code for Lambda. Important: Make sure that you put the library that you import for Python inside the /python folder.
This function handler name reflects the function name ( lambda_handler ) and the file where the handler code is stored ( lambda_function.py ). To change the function handler name in the Lambda console, on the Runtime settings pane, choose Edit.
The error message doesn't help too much, but I found out that this message is often caused by a lost npm package. If you test the lambda in the AWS console, you can see the specific details.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With