- Più recenti
- Maggior numero di voti
- Maggior numero di commenti
Hi, can you use markup to make your code more readable like this?
const https = require('https'); const path = require('path');
From your error message "errorType": "TypeError", "errorMessage": "Cannot read properties of undefined (reading '0')", "trace": [ "TypeError: Cannot read properties of undefined (reading '0')", " at Runtime.module.exports.handler (/var/task/index/index.js:36:23)", " at runMicrotasks ()", " at processTicksAndRejections (node:internal/process/task_queues:96:5)"
, I can observe that there's a problem in line 36 caused by indexing an undefined
object which is supposed to be an array.
Sorry code is now formatted correctly. This lambda function uses a PUT trigger of a file being uploaded to an S3 bucket which should be used as the file to generate a PDF from
Seems like the input
event
was not set properly. It should have the same structure as presented in this documentation.You said the "lambda function uses a PUT trigger of a file being uploaded to an S3 bucket", then did you actually upload a file to S3 bucket and have this function triggered automatically?
Add a
console.log(event)
line beforebody = event.Records[0].body;
to check if the Lambda event is propagated correctly. As a general tip for developers, you should utilize logging functionality to inspect the problematic places (in this case,event
).
When uploading the code it was too large to use the inline code editor and no deploy code button was visible so I assume the code deployed. I received this info message after uploading code:
The deployment package of your Lambda function "DocConversionTest" is too large to enable inline code editing. However, you can still invoke your function.
I tried uploading a file to S3 but nothing seemed to trigger via Lambda function so I manually clicked the test button and thats how I received the error message.
I also tried adding the name of the uploaded file to to the Body = 'filename.ext'; replacing the event.Records[0].body; - this actually worked when I ran via test button, but obviously is not the desired way to trigger.
Tried uploading a file again and it still doesn't seem to trigger the function
When uploading the code it was too large to use the inline code editor and no deploy code button was visible so I assume the code deployed. I received this info message after uploading code:
The deployment package of your Lambda function "DocConversionTest" is too large to enable inline code editing. However, you can still invoke your function.
You can export the deployed package from Lambda Console.
I tried uploading a file to S3 but nothing seemed to trigger via Lambda function Tried uploading a file again and it still doesn't seem to trigger the function
Which prefix or suffix did you configure for S3 Bucket trigger event? Did you upload your file to the location that matches the S3 prefix and suffix?
Contenuto pertinente
- AWS UFFICIALEAggiornata 4 mesi fa
- AWS UFFICIALEAggiornata un anno fa
I would like to help you but your code is kind of all over the place. Can you provide more information? Is the file being uploaded a compressed file? Your code would suggest the file being uploaded is always a
*.tar.br
file type. If this is true, you should download the file first then extract it, convert it and finally upload it. I would recommend that you scale back your script to just console logging theevent
and then building out your script from there. I can help provide an example if you provide the steps necessary to complete the task as well as help you set up S3 and Lambda correctly.I would also recommend checking out the following websites: https://plainenglish.io/blog/4-reasons-why-var-is-considered-obsolete-in-modern-javascript and https://www.w3schools.com/js/js_es6.asp