PreSigned URL
Diese Seite ist noch nicht in deiner Sprache verfügbar. Englische Seite aufrufen
Create a presigned URL using a S3 client
Section titled “Create a presigned URL using a S3 client”The following example uses S3cmd to create a presigned URL:
With the commandsignurlyou can create an url, that publishes an object temporary.
s3cmd signurl <bucket-name> <expiry_epoch|+expiry_offset>The value forexpiry_epochrepresents an epoch timestamp of the expiry date and time. Alternative you can also define a+followed by the time the url should stay valid. For thes3://my-example-bucketbucket, the command will look like this:
$ s3cmd signurl s3://my-example-bucket/testfile.txt +3600 http://object.storage.eu01.onstackit.cloud:443/my-example-bucket/testfile.txt?AWSAccessKeyId=KPVIPPUECP9XX40CVKEA&Expires=1638891653&Signature=abI28tb61IZoUmbXV4cu3opc18w%3DThis will create a URL which will grant read access to the filetestfilein the named bucket for 3600s(1h).
Create a presigned URL using the Python SDK
Section titled “Create a presigned URL using the Python SDK”The following small example will show how to use the AWS S3 Python SDK (Boto3) to create a presigned URL with write access (PUT) to a specific object within a bucket:
import boto3 def request\_presigned\_post(): S3\_ENDPOINT = "https://object.storage.eu01.onstackit.cloud" S3\_ACCESS\_KEY = "YOUR\_ACCESS\_KEY" S3\_SECRET\_KEY = "YOUR\_SECRET\_KEY" S3\_BUCKET = "YOUR\_BUCKET" s3key = "YOUR\_FILE" #create s3 client s3client = boto3.client('s3', endpoint\_url=S3\_ENDPOINT, aws\_access\_key\_id=S3\_ACCESS\_KEY, aws\_secret\_access\_key=S3\_SECRET\_KEY, ) #create presigned url presigned\_request = s3client.generate\_presigned\_url( 'put\_object', Params={'Bucket': S3\_BUCKET, 'Key': s3key}, ExpiresIn=3600) print(presigned\_request) def main(): request\_presigned\_post() if \_\_name\_\_ == "\_\_main\_\_": main()For further information please see the official boto3 documentation!