I have a lambda function which was working fine but I wanted to import a package so I created a directory with index.js and installed my npm package.
Then created a zip of this folder and uploaded it using
aws lambda update-function-code --function-name smrtfac-test
--zip-file fileb://lambda.zip
But now I am getting this error
index.handler is undefined or not exported
What could be the reason for it?
my index.js and node_modules are in the same directory.
This usually occurs when you zip up the directory, instead of zipping up the contents of the directory. When you open your zip file to browse the content, the index.js file should be in the root of the zip file, not in a folder.
You could also change the Handler section as below if your index.js is not directly under root folder as below
Consider using Lambda Layers for node modules: https://docs.aws.amazon.com/lambda/latest/dg/configuration-layers.html#configuration-layers-path
This is because you are probably submitting the project inside a directory. You just zip all the files directly instead of zipping them into a directory. The index file needs to be at the root to be able to be read and accessed by lambda.
If you're using typescript with CDK, make sure you are not exporting another function within your main function file.
Related
I received following error in CloudWatch Logs after using AWS CodePipeline (AWS CodeBuild) to deploy my C# Lambda Function Code
Could not find the required 'MyAssembly.deps.json'.
This file should be present at the root of the deployment package.: LambdaException
The problem in my case was that the linux file permissions on files inside the Zip were set to 000; so when the zip was extracted by AWS Lambda; AWS Lambda did not have file permission to access the file MyAssembly.deps.json
I was using C# System.IO.Compression.ZipFile.CreateFromDirectory to author the zip file. I had to shell out to the native zip program to produce a zip file which worked.
Big thanks to https://forums.aws.amazon.com/message.jspa?messageID=856247
I know this is bit old question but writing answer for any user who are still facing the problem on windows system.
this is with dotnet core 3.1
The first command in package manager console to ensure the .deps.json included in publish files
dotnet publish /p:GenerateRuntimeConfigurationFiles=true
and than zip all files of publish folder in the same name of namespace folder. upload the zip file to AWS lambda using console.
worked.
If not than copy all project files ( not the published) in zip and upload to aws lambda.
In a handler of mine, I open a .mmdb file for doing geo lookups. In my package, I use ./ notation to reference the file since the handler and file are in the same directory. Now that I want to deploy the function using serverless, I've included the file within the include block in my serverless.yml file. Based on the package size that I'm seeing, the file is being uploaded, however I'm getting the error
open ./GeoLite2-City.mmdb: no such file or directory
when running the lambda. What is the proper way to get the location of the file from within my lambda?
I solved my problem by listing the contents of the directory that I was using in my lambda, using the code found in this answer: List directory in Go. After doing so I realized that I was in the root directory of the entire folder that I uploaded, not the directory of the specific package I was running the code from (containing main.go)
I imported boto3 for my lambda function in python. When i test lambda it gives this error : No module named boto3 which is rather expected.
Then i referred to the docs,to this link to be exact https://docs.aws.amazon.com/lambda/latest/dg/lambda-python-how-to-create-deployment-package.html and realized i need to create a deployment package the issue is i didn't understand the docs well enough to keep up and would like them to be explained again in a simpler way by someone that has already done the required steps.
You need to make a folder in your local system, install the required libraries into that folder, zip the contents of the folder and upload the zipped file to the AWS Lambda.
Make a folder in local system
I don't think you need help in this. Lets suppose you made a folder in D drive named yellow-bot
Install the required libraries into the folder
You can install the required packages in the folder using below command
pip install {package-name} -t "{path-to-project-dir}"
In your case it would be:
pip install apiai -t "D:\yellow-bot"
Zip the contents of the folder
Now after installing the required libraries there will be multiple files and folders in your yellow-bot folder. You need to select all and zip the content. Please note that do not zip the folder, instead you go inside the folder and zip the contents.
It would be something like below screenshot.
Create lambda function and upload zip
Now go to AWS Lambda, create a lambda function, give correct run-time and all that. Then select upload zip file in code entry type. Select your zip and click on upload.
Make sure to give correct Handler.
It follows naming convention as:
The filename.handler-method value in your function. For example,
"main.handler" would call the handler method defined in main.py.
Since in this case I have uploaded connector.py file and entry function was called lambda_handler() so correct Handler would be connector.lambda_handler
Click on Save and you are done.
Hope it helps.
I'm trying to compress an image on Lambda using mozjpeg, but am having some issues.
The binary doesn't have execute permissions, and so I'm getting this error:
"exports._errnoException (util.js:870:11)",
"ChildProcess.spawn (internal/child_process.js:298:11)",
"Object.exports.spawn (child_process.js:362:9)",
"ret.catch.module.exports.promise (/var/task/node_modules/imagemin-mozjpeg/node_modules/exec-buffer/node_modules/execa/index.js:132:26)",
"/var/task/node_modules/imagemin-mozjpeg/node_modules/exec-buffer/index.js:36:15"
When I try to fix the permissions, I get this error:
'chmod: changing permissions of ‘/var/task/node_modules/imagemin-mozjpeg/node_modules/mozjpeg/vendor/cjpeg’: Read-only file system\n'
Is there a way to get the binaries to execute within node_modules, or an alternative to executing them manually from the tmp dir without the benefit of their nodejs wrappers?
You need to ensure that the method you use to zip your files includes preserving or setting the execute permissions in Unix format. They will then be preserved when the file is unzipped from S3.
The default for uploaded images appears to be /storage/app/public/profiles/, but the frontend generated URL of /storage/profiles/image isn't being found.
I tried to find any sort of routing for that directory and haven't been able to do so. Any help would be appreciated.
You must link to the storage directory. From the documentation:
Once Spark is installed, you should link the public/storage directory to your storage/app/public directory. Otherwise, user profile photos stored on the local disk will not be available
And the relevant code:
ln -s /path/to/storage/app/public /path/to/public/storage
Just delete the storage folder inside public folder and run the command using absolute paths(from root folder).