0

Is it possible to upload to an Amazon S3 bucket using an already prepared presigned-url through the command line. If so, how do I do this?

Running aws s3 cp <local_file> <presigned_url> doesn't work. I can't find any documentation related to presigned urls on the internet, so I would imagine that this isn't possible, but I'm still hopeful.

smac2020
  • 9,637
  • 4
  • 24
  • 38
mooglin
  • 500
  • 5
  • 17
  • You should not use the `aws` cli for that but instead just use e.g. `curl`: https://stackoverflow.com/a/9085141/2442804 – luk2302 Oct 15 '21 at 15:13
  • Does this answer your question? [Upload to s3 with curl using pre-signed URL (getting 403)](https://stackoverflow.com/questions/9067993/upload-to-s3-with-curl-using-pre-signed-url-getting-403) – luk2302 Oct 15 '21 at 15:25
  • The whole point of pre-signed URLs is so that you don't have to supply credentials. If you had credentials, you would be using the awscli (or a custom app that uses a credentialed AWS SDK). BTW that pre-signed URL includes the bucket and key so, assuming that you have local AWS credentials with the relevant permission, you could technically infer the bucket/key from the pre-signed URL and then upload using `aws s3 cp`. – jarmod Oct 15 '21 at 16:25

1 Answers1

0

Yes. If you already have the presigned url for put-object, just use curl:

curl "presignedurl" --upload-file yourfile.txt

I just tested and works great. For example:

curl "https://test-bucket.s3.amazonaws.com/test.txt?AWSAccessKeyId=ASDFLWKAS0F123&Signature=667S%22F%24%ASDasdfasdf%2Fasdfl&Expires=1634314495" --upload-file test.txt

In case you want to generate a presigned url, you can just check here for examples: https://docs.aws.amazon.com/AmazonS3/latest/userguide/PresignedUrlUploadObject.html

Nimantha
  • 6,405
  • 6
  • 28
  • 69