除了授權方式外,您還可以在MaxCompute中使用AccessKey訪問Tablestore的資料。
準備工作
擷取Tablestore資源所屬帳號的AccessKeyId和AccessKeySecret,如果該AK是資源所屬帳號的子帳號,那麼該子帳號至少需要對錶格儲存相關的資源具有以下許可權:
{
"Version": "1",
"Statement": [
{
"Action": [
"ots:ListTable",
"ots:DescribeTable",
"ots:GetRow",
"ots:PutRow",
"ots:UpdateRow",
"ots:DeleteRow",
"ots:GetRange",
"ots:BatchGetRow",
"ots:BatchWriteRow",
"ots:ComputeSplitPointsBySize"
],
"Resource": "*",
"Effect": "Allow"
}
]
}
--您也可以自訂其他許可權
在MaxCompute中使用AccessKey訪問Tablestore
同授權方式不同的是,需要在建立外表時在LOCATION
中顯示寫入AK資訊,其格式為:
LOCATION 'tablestore://${AccessKeyId}:${AccessKeySecret}@${InstanceName}.${Region}.ots-internal.aliyuncs.com'
假設需要訪問的Tablestore資源的資訊為:
AccessKeyId | AccessKeySecret | 執行個體名稱 | 地區 | 網路模式 |
---|---|---|---|---|
abcd | 1234 | cap1 | cn-hangzhou | 內網訪問 |
建立外表的語句為:
CREATE EXTERNAL TABLE ads_log_ots_pt_external
(
vid bigint,
gt bigint,
longitude double,
latitude double,
distance double ,
speed double,
oil_consumption double
)
STORED BY 'com.aliyun.odps.TableStoreStorageHandler'
WITH SERDEPROPERTIES (
'tablestore.columns.mapping'=':vid, :gt, longitude, latitude, distance, speed, oil_consumption',
'tablestore.table.name'='vehicle_track'
)
LOCATION 'tablestore://abcd:1234@cap1.cn-hangzhou.ots-internal.aliyuncs.com'
對資料訪問的操作步驟請參考使用MaxCompute訪問Tablestore中的步驟3.通過外部表格訪問Tablestore資料。