Amazon S3 功能介紹


1 存儲過程

       創建用於存儲數據元的桶,可以選擇數據元所駐留的地區(目前來說,選擇東京、新加坡會快些,美國本土更便宜),上傳數據元到桶,進行持久化存儲。另外,可以對上傳的數據元及桶進行訪問控制、加密等設置。每個AWS賬戶可以創建多個用戶,用戶可以對所擁有的數據進行上述權限控制。

       目前可存儲的你內容有:

(1)多媒體、音樂、圖片

(2)視頻監控文件

(3)醫療系統的檔案、資料

(4)靜態網站資料

2 管理

       通過AWS管理控制台對數據進行控制。AWS控制台類似於EC2的web控制界面,或者通過API接口(Java、.Net)、REST接口編程實現。

3 S3功能簡述

(1)創建桶、刪除桶

(2)寫入、讀取、刪除數據元,每個數據元的大小從1byte到5Tbyte

(3)根據用戶密鑰,查詢桶信息及數據元信息

(4)選擇數據所存儲的地區,東京 or 新加坡 or 其他

(5)數據元的權限設置,可以向指定的用戶開放,加密等

(6)使用基於REST和SOAP接口,提供JAVA,net的SDK

(7)便於添加其他功能,默認的下載協議是HTTP

(8)提供AWS管理平台,對數據進行管理

(9)在進行存儲或者檢索數據時,對數據進行校驗和計算,驗證是否損壞

(10)去冗余存儲,用戶可以自定義一些文件,比如縮略圖、轉碼媒體等,使得這些文件的存儲冗余副本數目低於標准的冗余副本數目

(11)數據源的訪問日志記錄,可用於審核等

(12)對數據元提供版本控制功能,用戶可以恢復到之前的版本

4 訪問控制機制

       S3的訪問控制機制,主要有四種。

(1) Identity and Access Management (IAM) 策略:

IAM讓擁有多名員工的組織能夠在一個AWS賬戶下創建和管理多個用戶,通過IAM策略,可以授予指定的用戶對桶和數據元的細化控制。

(2)訪問控制列表(ACL):

選擇性的授予對個別數據元或者桶的特定權限。

(3)桶策略:

桶策略可以添加或者拒絕對單一桶內的部分或者所有數據元的權限。

(4)查詢字符串身份驗證:

根據此項的驗證,能夠通過僅在限定時間段內有效的URL共享數據元。

4.1 使用IAM策略

       IAM策略就是AWS Identity and Access Management。使用此策略可以利用AWS賬戶創建多個用戶,給這些用戶分配證書、管理其權限。主要是針對用戶的。類似的還有ACL和桶策略。下面是三者的對比表:

 

       通過ACL,可以賦予其他的AWS賬戶相關權限來訪問本賬戶所擁有的資源,通過IAM,只能賦予本AWS賬戶下創建的用戶相關的訪問權限。控制級別不一樣。三者之間可以相互搭配,來組合安全策略。三者之間,在某些條件下也是等價的,比如:

 

在策略中,需要對objec 進行相關的action操作,就像上圖中的PutObject一樣,action列表如下。

Actions Related to Objects

  • s3:GetObject (covers REST GET Object, REST HEAD Object, REST GET Object torrent, SOAP GetObject, and SOAP GetObjectExtended)
  • s3:GetObjectVersion (covers REST GET Object, REST HEAD Object, REST GET Object torrent, SOAP GetObject, and SOAP GetObjectExtended)
  • s3:PutObject (covers the REST PUT Object, REST POST Object, REST Initiate Multipart Upload, REST Upload Part, REST Complete Multipart Upload, SOAP PutObject, and SOAP PutObjectInline)
  • s3:GetObjectAcl
  • s3:GetObjectVersionAcl
  • s3:PutObjectAcl
  • s3:PutObjectVersionAcl
  • s3:DeleteObject
  • s3:DeleteObjectVersion
  • s3:ListMultipartUploadParts
  • s3:AbortMultipartUpload
  • s3:GetObjectTorrent
  • s3:GetObjectVersionTorrent
  • s3:RestoreObject

Actions Related to Buckets

  • s3:CreateBucket
  • s3:DeleteBucket
  • s3:ListBucket
  • s3:ListBucketVersions
  • s3:ListAllMyBuckets (covers REST GET Service and SOAP ListAllMyBuckets)
  • s3:ListBucketMultipartUploads

Actions Related to Bucket Sub-Resources

  • s3:GetBucketAcl
  • s3:PutBucketAcl
  • s3:GetBucketCORS
  • s3:PutBucketCORS
  • s3:GetBucketVersioning
  • s3:PutBucketVersioning
  • s3:GetBucketRequestPayment
  • s3:PutBucketRequestPayment
  • s3:GetBucketLocation
  • s3:GetBucketPolicy
  • s3:DeleteBucketPolicy
  • s3:PutBucketPolicy
  • s3:GetBucketNotification
  • s3:PutBucketNotification
  • s3:GetBucketLogging
  • s3:PutBucketLogging
  • s3:GetBucketWebsite
  • s3:PutBucketWebsite
  • s3:DeleteBucketWebsite
  • s3:GetLifecycleConfiguration
  • s3:PutLifecycleConfiguration

同時,還有策略的Key值,可以根據策略的key來更加嚴格的控制資源。key值列表如下:

 

Action Applicable Keys Description

s3:PutObject

s3:x-amz-acl

The Amazon S3 canned ACL that is applied to the object. A canned ACL represents a predefined permission that can be applied to the object being PUT to Amazon S3.

Valid values: private | public-read | public-read-write | authenticated-read | bucket-owner-read |bucket-owner-full-control | log-delivery-write.

Example value: public-read

s3:x-amz-copy-source

The header that specifies the name of the source bucket and key name of the source object, separated by a slash (/). Used when copying an object.

Example value: /bucketname/keyname

s3:x-amz-grant-read, s3:x-amz-grant-write,​ s3:x-amz-grant-read-acp,​ s3:x-amz-grant-write​-acp,​ ​s3:x-amz-grant-full​-control

These conditions relate to the ACL-specific request headers the action supports. You can add a condition in your bucket policy to deny or grant the action based on the presence of these headers headers with specific values. For more information about the API and the request headers, go to PUT Object.

For an example policy that uses these condition keys, see Granting Cross-Account Permissions to Upload Objects While Ensuring the Bucket Owner Has Full Control .

s3:x-amz-server-side-encryption

Allow the specific action only if x-amz-server-side-encryption header is present in the request and its value matches the specified condition. with

Valid values: AES256

Example value: AES256

s3:x-amz-metadata-directive

The header that specifies whether the metadata is copied from the source object or replaced with metadata provided in the request. If copied, the metadata, except for the version ID, remains unchanged. Otherwise, all original metadata is replaced by the metadata you specify. Used when copying an object.

Valid values: COPY | REPLACE. The default is COPY.

Example value: REPLACE

s3:PutObjectAcl

s3:x-amz-acl

The Amazon S3 canned ACL that is applied to the object. A canned ACL represents a predefined permission that can be applied to the object being PUT to Amazon S3.

Valid values: private | public-read | public-read-write | authenticated-read | bucket-owner-read |bucket-owner-full-control | log-delivery-write.

Example value: public-read

s3:x-amz-grant-read, s3:x-amz-grant-write,​ s3:x-amz-grant-read-acp,​ s3:x-amz-grant-write​-acp,​ ​s3:x-amz-grant-full​-control

These conditions relate to the ACL-specific request headers the action supports. You can add a condition in your bucket policy to deny or grant the action based on the presence of these headers headers with specific values. For more information about the API and the request headers, go to PUT Object acl.

For an example policy that uses these condition keys, see Granting Cross-Account Permissions to Upload Objects While Ensuring the Bucket Owner Has Full Control .

s3:GetObjectVersion

s3:VersionId

The version ID of the object being retrieved.

Example value: Upfdndhfd8438MNFDN93jdnJFkdmqnh893

s3:GetObjectVersionAcl

s3:VersionId

The version ID of the object ACL being retrieved.

Example value: Upfdndhfd8438MNFDN93jdnJFkdmqnh893

s3:PutObjectVersionAcl

s3:VersionId

The version ID of the object ACL being PUT.

Example value: Upfdndhfd8438MNFDN93jdnJFkdmqnh893

s3:x-amz-acl

The Amazon S3 canned ACL that is applied to the object. A canned ACL represents a predefined permission that can be applied to the object being PUT to Amazon S3.

Valid values: private | public-read | public-read-write | authenticated-read | bucket-owner-read |bucket-owner-full-control | log-delivery-write.

Example value: public-read

s3:x-amz-grant-read, s3:x-amz-grant-write,​ s3:x-amz-grant-read-acp,​ s3:x-amz-grant-write​-acp,​ ​s3:x-amz-grant-full​-control

These conditions relate to the ACL-specific request headers the action supports. You can add a condition in your bucket policy to deny or grant the action based on the presence of these headers headers with specific values. For more information about the API and the request headers, go to PUT Object acl.

For an example policy that uses these condition keys, see Granting Cross-Account Permissions to Upload Objects While Ensuring the Bucket Owner Has Full Control .

s3:DeleteObjectVersion

s3:VersionId

The version ID of the object being deleted.

Example value: Upfdndhfd8438MNFDN93jdnJFkdmqnh893

桶策略:

Action Applicable Keys Description

s3:CreateBucket

s3:x-amz-acl

The Amazon S3 canned ACL that is applied to the bucket. A canned ACL represents a predefined permission that can be applied to the bucket being created.

Valid values: private | public-read | public-read-write | authenticated-read | bucket-owner-read |bucket-owner-full-control | log-delivery-write.

Example value: public-read

s3:LocationConstraint

Specifies the Region where the bucket will be created.

Valid values are us-west-1 (for Northern California) or EU (for Ireland). Do not specify a value for US Standard.

Example value: us-west-1

s3:x-amz-grant-read, s3:x-amz-grant-write,​ s3:x-amz-grant-read-acp,​ s3:x-amz-grant-write​-acp,​ ​s3:x-amz-grant-full​-control

These conditions relate to the ACL-specific request headers the action supports. You can add a condition in your bucket policy to deny or grant the action based on the presence of these headers headers with specific values. For more information about the API and the request headers, go to PUT Bucket.

For an example policy that uses these condition keys, see Granting Cross-Account Permissions to Upload Objects While Ensuring the Bucket Owner Has Full Control .

s3:ListBucket

s3:prefix

Limits the response to objects that begin with the specified prefix. Use this to allow or deny access to objects that begin with the prefix.

Example value: home

s3:delimiter

The character you use to group objects.

Example value: /

s3:max-keys

The number of objects to return from the call. The maximum allowed value (and default) is 1000.

For use with access policy language numeric conditions (for more information, see Numeric Conditions).

Example value: 100

s3:ListBucketVersions

s3:prefix

Header that lets you limit the response to include only keys that begin with the specified prefix.

Example value: home

s3:delimiter

The character you use to group objects.

Example value: /

s3:max-keys

The number of objects to return from the call. The maximum allowed value (and default) is 1000.

For use with access policy language numeric conditions (for more information, see Numeric Conditions).

Example value: 100

s3:PutBucketAcl

s3:x-amz-acl

The Amazon S3 canned ACL that is applied to the bucket. A canned ACL represents a predefined permission that can be applied to the bucket being created.

Valid values: private | public-read | public-read-write | authenticated-read | bucket-owner-read |bucket-owner-full-control | log-delivery-write.

Example value: public-read

s3:x-amz-grant-read, s3:x-amz-grant-write,​ s3:x-amz-grant-read-acp,​ s3:x-amz-grant-write​-acp,​ ​s3:x-amz-grant-full​-control

These conditions relate to the ACL-specific request headers the action supports. You can add a condition in your bucket policy to deny or grant the action based on the presence of these headers headers with specific values. For more information about the API and the request headers, go to PUT Bucket acl.

For an example policy that uses these condition keys, see Granting Cross-Account Permissions to Upload Objects While Ensuring the Bucket Owner Has Full Control .

        下面是一個利用策略進行權限控制的示例。在例子中,我們插入了一個組叫AllUsers,這包含了所有的從屬於同一個AWS賬戶的IAM用戶。現在賦予此組有對my_corporate_bucket/readonly文件夾中數據元的GetObject和GetObjectVersion權限。

{

   "Version":"2012-10-17",

   "Statement":[

      {

         "Effect":"Allow",

         "Action":[

            "s3:GetObject",

            "s3:GetObjectVersion"

         ],

         "Resource":"arn:aws:s3:::my_corporate_bucket/readonly/*"

      }

   ]

}

 

4.2 桶策略

       可以設定桶級別的允許、拒絕的操作權限。

下面是些桶權限相關的例子:

(1)設定桶策略

允許兩個用戶(1111-2222-3333, 4444-5555-6666)訪問執行桶mybucket中對象的GET請求。

PUT /?policy HTTP/1.1

Host: bucket.s3.amazonaws.com 

Date: Tue, 04 Apr 2010 20:34:56 GMT 

Authorization: AWS AKIAIOSFODNN7EXAMPLE:VGhpcyBSAMPLEBieSBlbHZpbmc= 

{

"Version":"2008-10-17",

"Id":"aaaa-bbbb-cccc-dddd",

"Statement" : [

    {

        "Effect":"Allow",

        "Sid":"1",

        "Principal" : {

            "AWS":["1111-2222-3333","4444-5555-6666"]

        },

        "Action":["s3:GetObject*"],

        "Resource":"arn:aws:s3:::mybucket/*"

    }

 ]

}

(2)獲取指定桶的桶策略:

GET ?policy HTTP/1.1

Host: mybucket.s3.amazonaws.com

Date: Wed, 28 Oct 2009 22:32:00 GMT

Authorization: AWS AKIAIOSFODNN7EXAMPLE:VGhpcyBSAMPLEBieSBlbHZpbmc=

(3)刪除某個桶的桶策略:

DELETE /?policy HTTP/1.1

Host: mybucket.s3.amazonaws.com 

Date: Tue, 04 Apr 2010 20:34:56 GMT 

Authorization: AWS AKIAIOSFODNN7EXAMPLE:VGhpcyBSAMPLEeSBlbHZpbmc=

(4)賦予多個AWS賬戶添加的權限

{

  "Version":"2008-10-17",

  "Statement":[{

         "Sid":"AddCannedAcl",

        "Effect":"Allow",

           "Principal": {

            "AWS": ["arn:aws:iam::111122223333:root","arn:aws:iam::444455556666:root"]

         },

           "Action":["s3:PutObject","s3:PutObjectAcl"

      ],

      "Resource":["arn:aws:s3:::bucket/*"

      ],

      "Condition":{

        "StringEquals":{

          "s3:x-amz-acl":["public-read"]

        }

      }

    }

  ]

}

(5)限定訪問IP

{

    "Version": "2008-10-17",

    "Id": "S3PolicyId1",

    "Statement": [

        {

            "Sid": "IPAllow",

            "Effect": "Allow",

            "Principal": {

                "AWS": "*"

            },

            "Action": "s3:*",

            "Resource": "arn:aws:s3:::bucket/*",

            "Condition" : {

                "IpAddress" : {

                    "aws:SourceIp": "192.168.143.0/24"

                },

                "NotIpAddress" : {

                    "aws:SourceIp": "192.168.143.188/32"

                }

            }

        }

    ]

}

更多例子:

http://docs.aws.amazon.com/AmazonS3/latest/dev/AccessPolicyLanguage_UseCases_s3_a.html

4.3 訪問控制列表ACL

       每個桶和數據元對象都有一個ACL。當一個請求發過來的時候,S3會檢查ACL列表來確定當前請求是否具有相應的權限。當桶或者數據元對象創建的時候,S3會生成一個默認的ACL,會賦予資源所有者對資源的所有操作權限。

<?xml version="1.0" encoding="UTF-8"?>

<AccessControlPolicy xmlns="http://s3.amazonaws.com/doc/2006-03-01/">

  <Owner>

    <ID>*** Owner-Canonical-User-ID ***</ID>

    <DisplayName>owner-display-name</DisplayName>

  </Owner>

  <AccessControlList>

    <Grant>

      <Grantee xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

               xsi:type="Canonical User">

        <ID>*** Owner-Canonical-User-ID ***</ID>

        <DisplayName>display-name</DisplayName>

      </Grantee>

      <Permission>FULL_CONTROL</Permission>

    </Grant>

  </AccessControlList>

</AccessControlPolicy>

  每個ACL最多含有100個Grant。其中,Grant元素標識了相關的權限說明。上面有兩個重要的元素,是Grantee和Permission。

4.3.1 Grantee

       每個Grantee可以是AWS賬戶或者是限定的S3用戶組。通過email地址或者標准的用戶ID來給指定的AWS賬戶賦權。S3會把相應的賬戶ID放入ACL中。如果是賦予group的話,目前S3提供了三種group。

(1)Authenticated User group:例如 http://acs.amazonaws.com/groups/global/AuthenticatedUsers。代表了所有的AWS賬戶,對這個組進行權限控制的話,會對所有的賬戶起作用。

(2)All User group:例如http://acs.amazonaws.com/groups/global/AllUsers。對這個組進行權限控制的話,所有的AWS注冊賬戶或者匿名賬戶都會起作用。

(3)Log Delivery group:例如http://acs.amazonaws.com/groups/s3/LogDelivery。桶的寫權限使得此組可以對這個桶寫服務端的訪問日志。

4.3.2 Permissions

       下面是一張權限的列表:

 

       同時,S3還提供了一些默認的grant,這就是canned ACL。

 

4.3.3 其他

       ACL提供了粗粒度的權限模型,桶策略提供了更加細膩的權限控制模型。二者可以單獨使用,也可以混合使用。

       Actions和Permissions也有區別。策略可以允許或者拒絕actions,ACLS可以賦予相應的permissions。actions是permissions的一方面。 

Object ACL Permissions

  • READ—Granting READ permission in an object ACL allows the s3:GetObjects3:GetObjectVersion, and s3:GetObjectTorrent actions to be performed on that object.
  • READ_ACP—Granting READ_ACP permission in an object ACL allows the s3:GetObjectAcl and s3:GetObjectVersionAcl actions to be performed on that object.
  • WRITE_ACP—Granting WRITE_ACP permission in an object ACL allows the s3:PutObjectAcl and s3:PutObjectVersionAcl actions to be performed on that object.
  • FULL_CONTROL—Granting FULL_CONTROL permission in an object ACL is equivalent to granting READREAD_ACP, and WRITE_ACP permission.

Bucket ACL Permissions

  • READ—Granting READ permission in a bucket ACL allows the s3:ListBuckets3:ListBucketVersions, and s3:ListBucketMultipartUploads actions to be performed on that bucket.
  • WRITE—Granting WRITE permission in a bucket ACL allows the s3:PutObject and s3:DeleteObject actions to be performed on any object in that bucket. In addition, when the grantee is the bucket owner, granting WRITE permission in a bucket ACL allows the s3:DeleteObjectVersion action to be performed on any version in that bucket.
  • READ_ACP—Granting READ_ACP permission in a bucket ACL allows the s3:GetBucketAcl action to be performed on that bucket.
  • WRITE_ACP—Granting WRITE_ACP permission in a bucket ACL allows the s3:PutBucketAcl action to be performed on that bucket.
  • FULL_CONTROL—Granting FULL_CONTROL permission in a bucket ACL is equivalent to granting READWRITEREAD_ACP, and WRITE_ACP permission.

5 發起請求

       發起請求可以有兩種方式,一種是通過提供的SDK接口,另一種是通過REST接口。

5.1 請求的包頭

(1)AWS Access Key Id:訪問的Key

(2)簽名:每個請求都必須包含一個有效的請求簽名

(3)時間戳:請求發起的時間戳,date和time

另外,還可以提供一個請求失效的時間戳。

5.2 請求步驟

發起一個驗證請求的步驟如下(請求只能是GET形式):

(1)創建一個request,其內容包含:

 

類似於:

GET /photos/puppy.jpg HTTP/1.1

Host: johnsmith.s3.amazonaws.com

Date: Mon, 26 Mar 2007 19:37:58 +0000 

Authorization: AWS AKIAIOSFODNN7EXAMPLE:frJIUN8DYpKDtOLCwo//yllqDzg=

(2)創建一個簽名:

 

簽名的計算格式如下: 

Authorization = "AWS" + " " + AWSAccessKeyId + ":" + Signature;
 
Signature = Base64( HMAC-SHA1( YourSecretAccessKeyID, UTF-8-Encoding-Of( StringToSign ) ) );
 
StringToSign = HTTP-Verb + "\n" +
    Content-MD5 + "\n" +
    Content-Type + "\n" +
    Date + "\n" +
    CanonicalizedAmzHeaders +
    CanonicalizedResource;
 
CanonicalizedResource = [ "/" + Bucket ] +
    <HTTP-Request-URI, from the protocol name up to the query string> +
    [ sub-resource, if present. For example "?acl", "?location", "?logging", or "?torrent"];
 
CanonicalizedAmzHeaders = <described below>

(3)發送請求和簽名到AWS:

 

(4)AWS獲取用戶的access key

 

(5)AWS重新計算簽名:

 

(6)把AWS計算的簽名值和用戶傳來的簽名值進行對比,返回驗證結果:

 

5. 3 桶的虛擬host

       可以通過url訪問指定的桶信息:http://bucketname.s3.amazonaws.com。或者可以通過在指定的域名后面追加桶的名字:http://my.bucketname.com/

6 桶

       一些條件限制:

(1)桶和桶是不能嵌套的

(2)每個AWS同時最多創建100個桶

(3)桶的名字是可重用的,前提是同一個名字對應的其他桶已經被刪除掉

(4)桶中的容量是無限制的,可以存儲任意多個對象

(5)桶名字的命名長度是3到63個字符,可包含字母、數字、斜杠、點號

(6)名字的開始和結束必須是小寫字母或者是數字,不能有兩個及以上連續的符號在一起

7 數據元

7.1 結構

       每個數據元都包含以下幾個部分:

(1)key:用於檢索數據元的唯一標識。utf8編碼,最多1024字節長度

(2)Version ID:key和version作為唯一識別一個數據元對象的標志,當添加數據元對象到S3的時候自動產生。每個數據元對象可以保留多個版本,默認不開啟版本管理,即只有一個版本。

(3)value:所存儲的具體數據,大小為0到5T字節。可以一次性的上傳5T的文件,也可以將大文件拆分成一個個的小部分,每個部分獨立的上傳。

(4)metadata:就是一系列的鍵值對,在上傳數據元對象的時候可以指定這個metadata,但是上傳完之后,就不能更改了。唯一可以修改的做法是在復制數據元的時候。metadata分為兩種,一種是系統metadata,另一種是用戶自定義的metadata。

系統metadata:

 

       用戶metadata:

如果是以rest接口實現的話,開頭必須是“x-amz-meta-”

每個數據元對象都和一個storage class相關聯,可以在使用使用 x-amz-storage-class關鍵字指定存儲類型,例如:

PUT /my-image.jpg HTTP/1.1

Host: myBucket.s3.amazonaws.com

Date: Wed, 12 Oct 2009 17:50:00 GMT

Authorization: AWS AKIAIOSFODNN7EXAMPLE:xQE0diMbLRepdf3YB+FIEXAMPLE=

Content-Type: image/jpeg

Content-Length: 11434

Expect: 100-continue

x-amz-storage-class: REDUCED_REDUNDANCY

storage class有如下幾種:

Standard:provides 99.999999999% durability and 99.99% availability

Reduced Redundancy Storage:provides 99.99% durability and 99.99% availability 

Glacier:suitable for archiving data

    另外可以更改storage class的類型,通過結合x-amz-metadata-directive 標簽和x-amz-storage-class,例如:

將storage class更改為RSS:

PUT /my-image.jpg HTTP/1.1

Host: bucket.s3.amazonaws.com

Date: Wed, 28 Oct 2009 22:32:00 GMT

x-amz-copy-source: /bucket/my-image.jpg

Authorization: AWS AKIAIOSFODNN7EXAMPLE:0RQf4/cRonhpaBX5sCYVf1bNRuU=

x-amz-storage-class: REDUCED_REDUNDANCY

x-amz-metadata-directive: COPY

將storage class更改為標准存儲:

PUT /my-image.jpg HTTP/1.1

Host: bucket.s3.amazonaws.com

Date: Wed, 28 Oct 2009 22:32:00 GMT

x-amz-copy-source: /bucket/my-image.jpg

Authorization: AWS AKIAIOSFODNN7EXAMPLE:0RQf4/cRonhpaBX5sCYVf1bNRuU=

x-amz-storage-class: STANDARD

x-amz-metadata-directive: COPY

(5)subresource:用於存儲對象的額外信息。

acl:包含授權信息列表,當創建數據元的時候,acl會定義數據元的訪問權限,可以更改這個acl。

torrent:支持BitTorrent協議。使用torrent,可以返回和數據元對象相關聯的torrent文件。可以在GET請求中指定torrent文件。可以查詢,但是不能修改、刪除、添加torrent文件。

(6)access control information:訪問控制信息

7.2 數據元的生命周期管理

       可以對指定的數據元對象定義管理規則,每個rule必須包含如下內容:

(1)數據元的key前綴,即rule的應用對象,可能是某一類的數據元

(2)action,對應到這些指定object對象的操作

(3)時間點或者周期長度,可以定時的執行上述的action事件

       如下是個生命周期管理的示例配置: 

<LifecycleConfiguration>
  <Rule>
    <ID>Example Rule</ID>
    <Prefix>projectdocs/</Prefix>
    <Status>Enabled</Status>
    <Transition>
      <Days>365</Days>
      <StorageClass>GLACIER</StorageClass>
    </Transition>
    <Expiration>
      <Days>3650</Days>
    </Expiration>
  </Rule>
</LifecycleConfiguration>

每個Lifecycle最多包含1000條rule。如果有版本的話,對應的數據元對象是不能進行生命周期管理設置的。

在rule中可以對數據元進行歸檔和刪除操作,分別需要注意如下。

對數據元進行歸檔處理之前應注意:

(1)處於Glacier storage classs中的數據元對象不是實時存在的,歸檔之前必須要存儲個臨時備份,此備份只在請求中指定的時間段存在。之后系統會刪除掉此備份;

(2)同樣,在轉變storage class的時候,也必須有個備份

(3)如果在規則定義的時候,指定的前綴為空,則是面向所有的數據元對象

       刪除數據元對象的時候應注意:

(1)刪除要慎重,刪除完,數據是不可恢復的

(2)指定的前綴為空,則是刪除所有的數據元對象

7.3 關於數據元的共享

       主要針對web應用,當web應用是在一個域中被加載,需要和其他域中的資源進行交互,這就需要用到數據的共享。可以選擇性的把自己在S3中的資源進行共享來構建web rich客戶端。

       共享可以在配置文件中進行配置實現。 

<CORSConfiguration>
 <CORSRule>
   <AllowedOrigin>http://www.example.com</AllowedOrigin>
   <AllowedMethod>PUT</AllowedMethod>
   <AllowedMethod>POST</AllowedMethod>
   <AllowedMethod>DELETE</AllowedMethod>

   <AllowedHeader>*</AllowedHeader>
 </CORSRule>
 <CORSRule>
   <AllowedOrigin>*</AllowedOrigin>
   <AllowedMethod>GET</AllowedMethod>
 </CORSRule>
</CORSConfiguration>

上例是桶中的配置遵循兩條規則。第一條是限制只能從指定的域中指定的方法來訪問資源。第二條是允許從所有的域中只能有GET方式獲取資源。

<CORSConfiguration>
 <CORSRule>
   <AllowedOrigin>http://www.example.com</AllowedOrigin>
   <AllowedMethod>PUT</AllowedMethod>
   <AllowedMethod>POST</AllowedMethod>
   <AllowedMethod>DELETE</AllowedMethod>
   <AllowedHeader>*</AllowedHeader>
  <MaxAgeSeconds>3000</MaxAgeSeconds>
  <ExposeHeader>x-amz-server-side-encryption</ExposeHeader>
  <ExposeHeader>x-amz-request-id</ExposeHeader>
  <ExposeHeader>x-amz-id-2</ExposeHeader>
 </CORSRule>
</CORSConfiguration>

       上例中指定了資源的緩存時間MaxAgeSeconds,以及http響應頭。

       定義的規則中可以動態的包含如下元素:

(1)AllowedMethod:GET,PUT,POST,DELETE,HEAD

(2)AllowedOrign:類似於http://*.example.com

(3)AllowedHeader:

(4)ExposeHeader:

(5)MaxAgeSeconds:秒級別,緩存響應的時間

       關於通用的一些HTTP響應頭信息(使用在REST接口中):

(1)Content-Length:響應的字節長度,字節為單位,類型是String,沒有默認值

(2)Connection:指定和服務器的連接是打開還是關閉,類型是Enum,只能是open或者close的一種,沒有默認值

(3)Date:響應的時間,類型是String,沒有默認值,值類似於Wed, 01 Mar 2009 12:00:00 GMT

(4)ETag:數據元對象的hash值,也可以是md5值

(5)Server:響應的Server的名字,字符串類型,默認值是AmazonS3

(6) x-amz-delete-marker:數據元對象返回是否刪除Marker,值只能是true或者false,默認是false

(7)x-amz-id-2:一個指定的token,類型是String,沒有默認值

(8)x-amz-request-id:用於區分request的唯一標識,類型是String,沒有默認值

(9)x-amz-version-id:數據元對象的version,如果允許有版本存在的話,S3會產生一個隨機的數字作為版本號,類型是String,有效值是null或者任何UTF8編碼的string,沒有默認值。

7.4 分段上傳操作

       當遇到大文件的時候,可以采用Multipart Upload來完成上傳操作和復制操作。分三個步驟完成:初始化upload,上傳upload部分,完成upload。

(1)Initation Multipart Upload:當客戶端請求多部分上傳時,S3會返回一個uploadID,在上傳分段以及完成上傳、退出上傳的時候,會用到此ID。

(2)Parts Upload:需要指定分段的編號,編號的范圍從1到10000,每上傳完一個分段,S3都會返回ETag頭作為響應。如果上傳的時候,分段的編號一樣,后上傳的會把之前上傳的覆蓋掉。

(3)Multipart Up分段load Completion(or Abort):完成上傳的時候,S3會通過拼接每個分段來創建一個完整的數據元對象。也可以退出上傳,退出之后,當前的UploadID就作廢了。

       可以並發的進行分段上傳。

       關於分段上傳,有以下需要注意的點:

 

8 數據保護

       S3會周期性的對存儲的數據元對象進行校驗(MD5結合CRC),如果發現數據損壞了,則會嘗試利用冗余的備份數據進行修復。並且,數據在進行網絡傳輸(讀、寫)的時候,也需要進行校驗和的計算、檢驗。

       S3對數據提供99.999999999%的持久性和99.99%的可靠性。

8.1 數據加密

       加密可以分為兩種,一種是在客戶端進行加密,一種是在服務端進行加密。針對第一種情況,客戶端加密,用戶可以自己管理加密過程,加密的密鑰。但是在服務端進行加密的話,操作會更簡單。因為密鑰等都會由S3來維護,加密完后再進行存儲,同樣,在讀取的時候會首先進行解密。Server端采用的256位的AES加密,加密的只是數據元對象的數據值。

8.2 數據的版本

       在同一個桶中,用戶可以擁有具有相同key的兩個數據元對象,但是二者的版本號不同。

 

       桶現在有三種狀態:unversioned(默認的狀態)、versioning-enabled、versioning-suspended。但是一旦開啟了version功能,就不能再變為unverisoned狀態了,只能把這個狀態掛起version-suspend。版本是針對桶級別的,一旦設置了,桶下面所有的存儲對象都會受到影響。

       開啟version可以有兩種方式:

(1)Put Bucket的請求中,添加versioning

(2)在請求中,添加Enabled狀態

PUT /?versioning HTTP/1.1

Host: bucketName.s3.amazonaws.com

Date: Wed, 12 Oct 2009 17:50:00 GMT

Authorization: AWS AKIAIOSFODNN7EXAMPLE:xQE0diMbLRepdf3YB+FIEXAMPLE=

Content-Type: text/plain

Content-Length: 124                         

<VersioningConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">

  <Status>Enabled</Status>

</VersioningConfiguration>

       當把version掛起的時候,已有的數據元對象不會發生什么變化。查詢的時候可以指定版本號。如果不指定,會返回最新的一個版本。

 

       通過HEAD來查詢指定版本的METADATA信息,格式如下:

HEAD /my-image.jpg?versionId=3HL4kqCxf3vjVBH40Nrjfkd HTTP/1.1

Host: bucket.s3.amazonaws.com

Date: Wed, 28 Oct 2009 22:32:00 GMT

Authorization: AWS AKIAIOSFODNN7EXAMPLE:0RQf4/cRonhpaBX5sCYVf1bNRuU=

8.3 刪除

如果要刪除已經開啟版本的數據對象時,是沒有辦法立即永久刪除的。S3只是針對需要刪除的數據對象的最新的版本里插入了一個刪除的標志位,當查詢的時候,就會給出提示說這個數據對象已經被刪除了,並且返回一個404錯誤頁面。

 

如果想要永久性的刪除,必須要指定版本號才行。

 

DELETE /photo.gif?versionId=UIORUnfnd89493jJFJ HTTP/1.1

Host: bucket.s3.amazonaws.com

Date: Wed, 12 Oct 2009 17:50:00 GMT

Authorization: AWS AKIAIOSFODNN7EXAMPLE:xQE0diMbLRepdf3YB+FIEXAMPLE=

Content-Type: text/plain

Content-Length: 0

       如果刪除多次,S3會依次給最新的版本上加入刪除標記,已有的刪除標記不會被刪掉:

 

       另外,可以通過指定版本ID移除刪除標記:

 

DELETE /photo.gif?versionId=4857693 HTTP/1.1

Host: bucket.s3.amazonaws.com

Date: Wed, 28 Oct 2009 22:32:00 GMT

Authorization: AWS AKIAIOSFODNN7EXAMPLE:0RQf4/cRonhpaBX5sCYVf1bNRuU=

另外,可以同時一次性刪除最多1000個數據元對象。

8.4 version-suspended狀態的操作

       如果當前是版本的掛起狀態即version-suspended狀態,那么新加入的數據對象的版本就是null:

 

如果null的version已經存在,則后添加的會把之前的覆蓋掉:

 

 

       查詢的時候,會取最新添加的版本:

 

       此狀態下只能移除version為null的版本,同樣,也是會加入刪除的標志位來進行刪除,即使多次刪除也是只對version為null的起作用:

 

       如果指定的刪除的versionID的話,依然會直接刪除:

 

8.5 其他

       當拷貝一個數據對象到同一個桶中的時候,被拷貝的數據對象就變成最新的版本,如果開啟版本的話。同樣,刪除一個最新的版本,次新的版本會變成最新的版本。

9 存儲靜態網站

       S3支持存儲靜態網站的一些資源和頁面。若已經存儲,則存儲的靜態網站在S3的訪問WEB地址如下:

<bucket-name>.s3-website-<AWS-region>.amazonaws.com

數據存儲在不同區域的話,域名會有些區別:

Region

Website endpoint

US Standard

bucket-name.s3-website-us-east-1.amazonaws.com

US West (Oregon) Region

bucket-name.s3-website-us-west-2.amazonaws.com

US West (Northern California) Region

bucket-name.s3-website-us-west-1.amazonaws.com

EU (Ireland) Region

bucket-name.s3-website-eu-west-1.amazonaws.com

Asia Pacific (Singapore) Region

bucket-name.s3-website-ap-southeast-1.amazonaws.com

Asia Pacific (Sydney) Region

bucket-name.s3-website-ap-southeast-2.amazonaws.com

Asia Pacific (Tokyo) Region

bucket-name.s3-website-ap-northeast-1.amazonaws.com

South America (Sao Paulo) Region

bucket-name.s3-website-sa-east-1.amazonaws.com

       當請求不合法的時候,S3會返回一些錯誤信息頁面,下面是具體的錯誤頁面內容及其觸發條件:

HTTP Error Code

Description

301 Moved Permanently

當用戶直接發送一個指向存儲在S3中靜態網站站點的請求時,S3會返回301錯誤頁面,並且會轉向到S3主界面:http://aws.amazon.com/s3

302 Found

若一個請求沒有以斜杠結尾,則S3會把最后一個請求值作為key來查詢數據對象,如果找不到,則S3會認為這最后一個請求值是文件夾的名字,並返回302錯誤。

304 Not Modified

若請求的頭部信息是: If-Modified-SinceIf-Unmodified-SinceIf-Match and/or If-None-Match ,則S3會判斷客戶端緩存的對象是否有同樣的頭部信息,若一樣的話,則會返回304錯誤。

400 Malformed Request

發起請求的地址不正確

403 Forbidden

請求沒有權限

404 Not Found

請求的資源不存在,可能是以下原因引起:

(1)查詢數據對象時,數據不存在;

(2)查詢文檔時,文檔不存在

(3)請求的url不存在

(4)url存在,但這不是指向的web

另外,也可以自定義404返回用於特定的場景。

500 Service Error

請求發生內部錯誤

503 Service Unavailable

請求過於頻繁,服務不可用

       S3還提供了一種觸發事件報警機制,當觸發條件滿足時,就會以郵件、短信等形式發出報警。目前只支持數據對象丟失的報警。可以在添加數據的時候指定這個出發事件:

PUT ?notification HTTP/1.1

Host: quotes.s3.amazonaws.com

Date: Wed, 02 June 2010 12:00:00 GMT

Authorization: AWS AKIAIOSFODNN7EXAMPLE:xQE0diMbLRepdf3YB+FIEXAMPLE=

<NotificationConfiguration>

   <TopicConfiguration>

       <Topic>arn:aws:sns:us-east-1:111122223333:myTopic</Topic>

           <Event>s3:ReducedRedundancyLostObject</Event>

   </TopicConfiguration>

</NotificationConfiguration>

       報警的內容包括如下幾個部分:

Name

Description

Service

固定字符串:Amazon S3.

Event

當前只有s3:ReducedRedundancyLostObject

Time

事件觸發時間

Bucket

桶的名字

Key

Key值

VersionId

如果有版本號,則是版本的id,如果沒有版本,則是空字符串

RequestID

請求ID號,全局唯一,標志是哪種操作觸發的

HostID

全局唯一,用於標志是那個host發出的報警

       下面就是報警的一個實例:

{

    "Service":"Amazon S3",

    "Event": "s3:ReducedRedundancyLostObject",

    "Time":"2010-02-11T23:48:22.000Z",

    "Bucket": "myphotos",

    "Key": "Home/2009/10/carvingpumpkins.jpg",

    "VersionId":"qfXHy5689N7n9mWVwanN_hIroMn_rzXl",

    "RequestId":"4442587FB7D0A2F9",

    "HostId":"fHZOHz+oQlKAFQ7RgVSklvcDNYI0v05gsOWWeJcyTTXWgGzI6CC5FZVICjD9bUzT"

}

10 支持BitTorrent

       可以使用BitTorrent協議來下載數據對象。

 

 注:內容來自亞馬遜S3官網,本文旨在讓更多的人了解S3的功能,便於開發出適合系統來推動技術的發展,如果有任何知識產權和版權等方面的問題請及時聯系我。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM