AWS Lambda function for upload/putObject image works only on local machine
See original GitHub issueI have a lambda function which uses ‘request’ to get a stream of a file by URL and suppose to upload it to a bucket on s3. It is working perfectly on my local machine using node but not inside the lambda. After running the lambda, I have an empty file with the name I wanted.
Stuff you should know
- The lambda function is async
- The node version is 8.10
- In the example you see putObject, but I have also tried with upload
- Even when adding a manual sleep of 90-120 seconds to let the lambda run, the file is not uploaded
- I tried using context.succeed or callback(‘some result’), but it still did not work properly
This is the relevant part of the code
module.exports.handler = async(event, context, callback) => {
const path = 'bucketToUpload';
const name = 'imageFileName.jpg';
let options = {
uri: responseUrl, // This is the url of the image
encoding: null
};
let reqRes = await request(options); // Here I have the stream
let awsPutRes = await s3.client.putObject({
Body: reqRes.body,
Key: name,
Bucket: path
}).promise();
};
Would really appreciate any help or directions for this issue.
Issue Analytics
- State:
- Created 5 years ago
- Comments:6 (2 by maintainers)
Top Results From Across the Web
AWS Lambda function for upload/putObject image works only ...
It is working perfectly on my local machine using node but not inside the lambda. After running the lambda, I have an empty...
Read more >Uploading to Amazon S3 directly from a web or mobile ... - AWS
This Lambda function is granted the S3WritePolicy policy to the bucket by the AWS SAM template. The uploaded object must match the same...
Read more >Upload image or PDF files to Amazon S3 through API Gateway
How do I upload an image or PDF file to Amazon S3 through API Gateway? ... to perform the PutObject and GetObject actions...
Read more >Uploading objects - Amazon Simple Storage Service
Upload files or folders to an Amazon S3 bucket. ... You can upload any file type—images, backups, data, movies, etc.—into an S3 bucket....
Read more >Using an Amazon S3 trigger to invoke a Lambda function
The Lambda function retrieves the source S3 bucket name and the key name of the uploaded object from the event parameter that it...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
So after some more tries I was able to solve the issue.
Here is part of the code:
Instead of using ‘request’ lib I am using ‘request-promise-native’ to get the stream from the url. (thanks for that @srchase ) And also using the .promise() of aws-sdk library to make it fully work.
Hello @ChenFeldman,
This doesn’t look like an issue with the SDK, but with Lambda and reqeust.
I was able to get it working with request-promises-native instead though: