Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

351
Views
cómo descargar la imagen y poner S3 en lambda nodejs
'use strict'; var https = require('http'); var aws = require('aws-sdk'); var fs = require('fs'); aws.config.update({ accessKeyId: 'id', secretAccessKey: 'key', region: 'ap-northeast-1' }); var s3bucket = new aws.S3(); var bucketName = "bukcetName" exports.handler = (event, context, callback) => { https.get("URL.jpg", function(res, body){ body = new Buffer(res.body, 'binary'); var params = { Bucket:bucketName, Key: "testLambda", Body: body, ACL: 'public-read' }; s3bucket.upload(params, function(err, data) { context.done(null, 'Finished UploadObjectOnS3'); }); }); };

Pasarela API ---> lambda

quiero descargar desde URL en lambda y ese contenido poner S3.

No puedo obtener datos binarios de la URL, pero puedo poner cualquier dato en cualquier directorio en S3, gracias, ayuda.

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

He hecho algunos cambios en tu código para que funcione mejor.
-No necesitas la 'fs'.
-El método correcto es 'putObject' en lugar de 'upload'.
¡Gracias!

 'use strict'; var AWS = require('aws-sdk'); var s3 = new AWS.S3(); var http = require('http'); aws.config.update({ accessKeyId: 'id', secretAccessKey: 'key', region: 'ap-northeast-1' }); var s3bucket = new AWS.S3(); var bucketName = "bukcetName"; exports.handler = (event, context, callback) => { http.get("URL.jpg", function(res){ var imageData = ''; res.setEncoding('binary'); res.on('data', function(chunk){ imageData += chunk; }); res.on('end', function(){ var params = { Bucket: bucketName, Key: "testLambda", Body: new Buffer(imageData, 'binary'), ACL: 'public-read' }; s3.putObject(params, function(err, data) { if (err) console.log(err, err.stack); else console.log(data); context.done(null, 'Finished UploadObjectOnS3'); }); }); }); };
about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!