S3 API Usage
使用示例
S3 API 操作
AWS CLI
您可以使用 AWS 命令行接口 向 Alluxio S3 API 发送 S3 API 请求。 请注意,您必须提供 --endpoint参数来指定 Alluxio S3 REST API 的位置,并包含服务器的基本 URI。 端点格式为 --endpoint "http://{alluxio.worker.web.hostname}:{alluxio.worker.rest.port}/"。
如涉及 授权 标头操作,您可能需要先配置 AWS 凭证。
有关 Alluxio 如何使用该标头的详细信息,请参阅授权标头
$ aws configure --profile alluxio-s3
AWS Access Key ID [None]: {user}
AWS Secret Access Key [None]: {dummy value}
Default region name [None]:
Default output format [None]:REST Clients
您可以直接使用任何 HTTP client 向 Alluxio S3 API 发送 S3 API 请求。 基本 URI 为 /;请求应指向 http://{alluxio.worker.web.hostname}:{alluxio.worker.rest.port}/。
目前,Alluxio S3 API 不存在access key和secret key验证。 因此,授权标头仅用于指定执行请求的目标用户。 The header follows the AWS Signature Version 4 format.
$ curl -i -H "Authorization: AWS4-HMAC-SHA256 Credential=testuser/... SignedHeaders=... Signature=..." ...AWS CLI
$ aws --profile alluxio-s3 --endpoint "http://localhost:29998/" s3api copy-object \
--copy-source=testbucket/test.txt --bucket=testbucket --key=test_copy.txt
{
"CopyObjectResult": {
"ETag": "911df44b7ff57801ca8d74568e4ebfbe",
"LastModified": "2022-05-03T11:37:16.015000+00:00"
}
}
$ aws --profile alluxio-s3 --endpoint "http://localhost:29998/" s3api list-objects \
--bucket=testbucket
{
"Contents": [
{
"Key": "test.txt",
"LastModified": "2022-05-03T11:35:59.243000+00:00",
"Size": 27040
},
{
"Key": "test_copy.txt",
"LastModified": "2022-05-03T11:37:16.185000+00:00",
"Size": 27040
}
]
}REST Clients
$ curl -i -H "Authorization: AWS4-HMAC-SHA256 Credential=testuser/... SignedHeaders=... Signature=..." \
-H "x-amz-copy-source: testbucket/test.txt" \
-X PUT http://localhost:29998/testbucket/test_copy.txt
HTTP/1.1 200 OK
Date: Tue, 03 May 2022 21:50:07 GMT
Content-Type: application/xml
Content-Length: 135
Server: Jetty(9.4.43.v20210629)
<CopyObjectResult>
<ETag>911df44b7ff57801ca8d74568e4ebfbe</ETag>
<LastModified>2022-05-03T14:50:07.781Z</LastModified>
</CopyObjectResult>
$ curl -i -H "Authorization: AWS4-HMAC-SHA256 Credential=testuser/... SignedHeaders=... Signature=..." \
-X GET http://localhost:29998/testbucket
HTTP/1.1 200 OK
Date: Tue, 03 May 2022 21:50:26 GMT
Content-Type: application/xml
Content-Length: 434
Server: Jetty(9.4.43.v20210629)
<ListBucketResult>
<version2>false</version2>
<Contents>
<Key>test.txt</Key>
<Size>27040</Size>
<LastModified>2022-05-03T14:47:36.600Z</LastModified>
</Contents>
<Contents>
<Key>test_copy.txt</Key>
<Size>27040</Size>
<LastModified>2022-05-03T14:50:07.790Z</LastModified>
</Contents>
<Marker/>
<IsTruncated>false</IsTruncated>
<Prefix/>
<Name>testbucket</Name>
<MaxKeys>1000</MaxKeys>
<EncodingType>url</EncodingType>
</ListBucketResult>Last updated