S3裏面的對象默認都是私有的,僅僅全部者能夠訪問。可是,全部者能夠經過本身的權限對對象文件建立 presigned URL,這樣子在指定的時間內容許其餘人來下載這個文件。ide
AWS Presigned URL 通常是在SDK裏面使用,容許生成一個臨時的URL,這個URL裏面包含了Token和過時時間,這樣子用戶能夠經過這個臨時的URL來訪問S3 的資源。code
咱們用AWS CLI 也能夠生成Presigned URL。對象
好比說,登陸一個EC2實例,這個EC2已經分配了對應的IAM Role能夠管理S3,所以我能夠直接執行相關的命令。blog
下面例子中, 我建立一個新的bucket,而且上傳一個text文件。token
aws s3 mb s3://beanxyztest echo "hello world" >> hello.txt aws s3 cp hello.txt s3://beanxyztest
這個文件默認是沒法從外網訪問的,由於我沒有配置任何public read權限。資源
若是我執行下面的命令,他會對我指定的key執行presign的操做,後面的expries-in 參數表示多少秒以後過時,默認是3600秒it
aws s3 presign s3://beanxyztest/hello.txt --expires-in 60 https://beanxyztest.s3.amazonaws.com/hello.txt?AWSAccessKeyId=ASIAVTZSLTQTVKAWGT4J&Signature=fKsfkPE24S2lZ5PdXR9B5hsMwt8%3D&x-amz-security-token=IQoJb3JpZ2luX2VjEMz%2F%2F%2F%2F%2F%2F%2F%2F%2F%2FwEaDmFwLXNvdXRoZWFzdC0yIkcwRQIgPXw5nlFMqy3DaSbbC1prhKpeh644EviNaklqgyrGwjUCIQDVhopxw1CV%2BaNBgVWPScz%2Fh%2FCzQTb4Q8n0zbNkzErfDyrHAwiF%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F8BEAIaDDM4NjExNTgwNDE5OSIMFNGn51kUMMQI7KmPKpsD%2FkYXZemodSgiLcH4%2BqoIZUzS3xhDR5kvFvwy9rVux7zWTh%2B6TXloce98HRRUIorvsRO7F5%2FXXgQM5alnfOyZJhelnxWLQfuAZgpktV9UlqvAKvAw2PR04x2y%2BwA8Adc2brZYsDwUR%2BylrOue7F%2FUGzwJwLehkp9T0KN7hwG0wicm2D7BqCsjGMuAgGy%2FdedwQij%2B4YgWA%2BPENmq7h1da6OcQVQQduNI6DrwXj9ivWK5u5F8mzY5wpzbrFBfCIqCcyqiKnZWEO1e3sp9Tz4gKchC7TTmFquMHScfA3Oo97TcmbIPAR1ZLObZTCsJqcCfGH581XIeUq3OIA6pwm0Wi%2FjhUrw%2FQGWI8kopwMs0nfn4qLzNYOcw1khFLnb0x7nc3PHI%2FZ6uy27xahWbHbhbeMtC5PBlp%2Fw2WO09ywcEcD%2B45E957g9TqY1Syu8VqEkqqRXbKb5%2FjdVlnjyksMes9rn9kFHl%2Fpatcac3z7TkeuXdGJoA%2B5XE64IuBb0MQhwx7dmgqjHWsiWl%2FqGPkOf4jrbwuHwO8DyDtyXMPMMOitf8FOusB67Qv0QHESN0zJDuAac8CHuAyKgnjI8gbj23HEGXmtmT8vGdxXwrycbDqeya6lUA5ucZKnFUleZOpk31fP76jpL0NFCUFrE%2BFjjHTGtvMiPiSD%2Fxo%2BcPKwV3pKdgXHwvZUlgxIbJycO4sBV4TFr%2FhHT%2BLRgmdyDCYMvSoUHWabe4gtIgrA%2BRNhcXQELHBgd83VP0dAp0VEAj%2BmPRE6jPoj7Hd3BIYa0Q8n22ewo%2FlEextUsCqnD%2Fvfed9E5X34yBWXcWNk5LHtu4Vg7zpCGSbdqyLtFDXNM4kuGvfrpX3%2BNC1cpXPr70prLPYYg%3D%3D&Expires=1609389937
而後經過這個URL我就能夠直接打開對應的文件了class