1개 답변
- 최신
- 최다 투표
- 가장 많은 댓글
0
Per the CLI's documentation, the generated presigned URLs are only usable for GET
s.
I have this recipe saved for when I need to POST
; if you need to PUT
, you should be able to modify it to use generate_presigned_url()
instead of generate_presigned_post()
. Note that this uses the boto3 library with Python, so you will need to arrange to have that available for your Python install to access (e.g. pip install boto3
). The output includes values formatted for both curl and httpie, which I hope will be useful.
Python script to get presigned POST URL:
import boto3 client = boto3.client("s3") # get presigned info # note other params can be passed here, including expiration # see https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/s3.html#S3.Client.generate_presigned_post info = client.generate_presigned_post(Bucket="some-bucket", Key="filename.txt") # print the "fields" out in the right format to feed to httpie print(" ".join(f"{k}='{v}'" for (k, v) in info["fields"].items())) # for curl, use this print(" ".join(f"-F {k}='{v}'" for (k, v) in info["fields"].items())) # confirm the URL print(info["url"])
Below are examples of using the returned values. You will may need to remove the comment lines for your shell to be happy.
Use with httpie:
http --form -v \ # this the the URL from Python output https://some-bucket.s3.amazonaws.com/ \ # these are the copy/pasted fields from Python output key='filename.txt' AWSAccessKeyId='AKIA...EWS3' policy='eyJl...dfQ==' signature='RcU...XLw=' \ # this is the file to upload file@local-filename.txt
Use with curl:
curl -X POST \ # the copy/pasted fields -F key='filename.txt' -F AWSAccessKeyId='AKIA...EWS3' -F policy='eyJle...dfQ==' -F signature='RcU9...XLw=' \ # the file to upload -F file=@local-filename.txt \ # the URL https://some-bucket.s3.amazonaws.com/
관련 콘텐츠
- AWS 공식업데이트됨 2년 전
Wow, thanks for the detailed and prompt response! I figured I might need to use an SDK to generate one for PUT. Seems like a shortcoming in the CLI to me, though.