monkeybanana
monkeybanana

Reputation: 267

Amazon S3 + Lambda (Node.JS) clarification on the s3.upload() method

I am following this tutorial wherein the programmer used this code:

await s3
      .upload({ Bucket: bucket, Key: target_filename, Body: file_stream })
      .promise();

Now, I understand that the method above would use the initialized variables file_stream, bucket, and target_filename (which he didn't bother typing out in his tutorial).

But the tutorial is hard to follow since (for what I know) the Key parameter inside the upload is the actual directory of the file to be re-uploaded back to S3.

This is confusing because at the file_stream variable, another Key parameter exists inside the method getObject().

So, is the filename inside the getObject() method should be the same as target_filename of the upload() method? and can you initialize the variables mentioned just to make it clearer for this question? Thank you.

Upvotes: 1

Views: 44

Answers (1)

jellycsc
jellycsc

Reputation: 12359

No, the filename inside the getObject() method may not be the same as the target_filename in upload(). Let's look at a concrete example. Suppose you have a photo.zip file stored on S3 and its key is a/b/photo.zip, and you want to unzip it and reupload it to c/d/photo.jpg assuming that the photo.zip only contains one file. Then, the filename should be a/b/photo.zip, and the target_filename should be c/d/photo.jpg. As you can see, they are clearly different.

Upvotes: 1

Related Questions