AWS Lambda Function

Asked

Viewed 67 times

0

I’m creating a Lambda Function on AWS to perform file upload. At the moment I make the request as POST, where I send in the body the document in Base64 format.

However, I am having some problems because Base64 is being slapped.

Would anyone know if there’s a limit to that?

  • 2

    To my knowledge, lambda AWS is not a function, but it is a serverless service in which you provide an end-point to do some processing. So I found the description very strange lambda function in the title/body of the text. Without more details of your test, of your up-to-date end-point code, I don’t see how anyone without a crystal ball could help. A priori, AWS should provide you with enough working memory space for you to be able to do POST arbitrary in size, but more detail is needed to say anything

3 answers

0

Use the S3 SDK to upload, there are several supported languages and it will be much cheaper.

If you have never used do some testing with the CLI first, it will help a lot.

0

Note that you mentioned that Base64 is being truncated in Lambda, but actually this would happen in the Gateway API. You can see an example of a request in this documentation.

Using an AWS Lambda function to upload is certainly not the best solution, mainly because of the cost. Probably what you’re trying to do is pass a base64 for the function and using the SDK of AWS S3 to upload.

S3 itself already has SDK’s in the most different languages to upload (including Javascript, which should probably be your case, in the frontend), as seen in this documentation. It may also be of interest to the documentation of S3 Transfer Acceleration.

0

Here’s an example from Function Lambda, however, it’s good that you capture your Function logs with Cloudwatch and analyze because you might not even be getting to Function Lambda.

var AWS = require('aws-sdk');
var s3Bucket = new AWS.S3({ params: { Bucket: 'seuBucket' } });
exports.handler = function(event, context, callback) {
  var buf = new Buffer(event.avatar.base.replace(/^data:image\/\w+;base64,/, ""), 'base64');
  var data = {
    Key: 'avatar/edimar.png',
    Body: buf,
    ContentEncoding: 'base64',
    ContentType: 'image/webp'
  };
  s3Bucket.putObject(data, function(err, data) {
    if (err) {
      console.log(err);
      console.log('Error uploading data: ', data);
    }
    else {
      console.log('succesfully uploaded the image!');
      callback(err, 'ok');
    }
  });
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.