如需類似 Amazon Timestream for LiveAnalytics 的功能,請考慮使用 Amazon Timestream for InfluxDB。它提供簡化的資料擷取和單一位數毫秒查詢回應時間,以進行即時分析。在這裡進一步了解。
本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。
Amazon Timestream for LiveAnalytics 身分型政策範例
根據預設,IAM 使用者和角色沒有建立或修改 Timestream for LiveAnalytics 資源的許可。他們也無法使用 AWS Management Console、CQLSH AWS CLI、 或 AWS API 執行任務。IAM 管理員必須建立 IAM 政策,授予使用者和角色在指定資源上執行特定 API 作業的所需許可。管理員接著必須將這些政策連接至需要這些許可的 IAM 使用者或群組。
若要了解如何使用這些範例 JSON 政策文件建立 IAM 身分型政策,請參閱《IAM 使用者指南》中的在 JSON 標籤上建立政策。
政策最佳實務
身分型政策會判斷您帳戶中的某人是否可以建立、存取或刪除 Timestream for LiveAnalytics 資源。這些動作可能會讓您的 AWS 帳戶產生費用。當您建立或編輯身分型政策時,請遵循下列準則及建議事項:
-
開始使用 AWS 受管政策並轉向最低權限許可 – 若要開始將許可授予您的使用者和工作負載,請使用將許可授予許多常見使用案例的 AWS 受管政策。它們可在您的 中使用 AWS 帳戶。我們建議您定義特定於使用案例 AWS 的客戶受管政策,以進一步減少許可。如需更多資訊,請參閱 IAM 使用者指南中的 AWS 受管政策或任務職能的AWS 受管政策。
-
套用最低權限許可 – 設定 IAM 政策的許可時,請僅授予執行任務所需的許可。為實現此目的,您可以定義在特定條件下可以對特定資源採取的動作,這也稱為最低權限許可。如需使用 IAM 套用許可的更多相關資訊,請參閱 IAM 使用者指南中的 IAM 中的政策和許可。
-
使用 IAM 政策中的條件進一步限制存取權 – 您可以將條件新增至政策,以限制動作和資源的存取。例如,您可以撰寫政策條件,指定必須使用 SSL 傳送所有請求。如果透過特定 使用服務動作 AWS 服務,您也可以使用條件來授予存取,例如 AWS CloudFormation。如需詳細資訊,請參閱 IAM 使用者指南中的 IAM JSON 政策元素:條件。
-
使用 IAM Access Analyzer 驗證 IAM 政策,確保許可安全且可正常運作 – IAM Access Analyzer 驗證新政策和現有政策,確保這些政策遵從 IAM 政策語言 (JSON) 和 IAM 最佳實務。IAM Access Analyzer 提供 100 多項政策檢查及切實可行的建議,可協助您撰寫安全且實用的政策。如需詳細資訊,請參閱《IAM 使用者指南》中的使用 IAM Access Analyzer 驗證政策。
-
需要多重要素驗證 (MFA) – 如果您的案例需要 IAM 使用者或 中的根使用者 AWS 帳戶,請開啟 MFA 以提高安全性。如需在呼叫 API 操作時請求 MFA,請將 MFA 條件新增至您的政策。如需詳細資訊,請參閱《IAM 使用者指南》https://docs.aws.amazon.com/IAM/latest/UserGuide/id_credentials_mfa_configure-api-require.html中的透過 MFA 的安全 API 存取。
如需 IAM 中最佳實務的相關資訊,請參閱 IAM 使用者指南中的 IAM 安全最佳實務。
使用 Timestream for LiveAnalytics 主控台
LiveAnalytics 的 Timestream 不需要特定許可,即可存取 Amazon Timestream for LiveAnalytics 主控台。您需要至少 個唯讀許可,才能列出和檢視 AWS 您帳戶中 Timestream for LiveAnalytics 資源的詳細資訊。如果您建立比最基本必要許可更嚴格的身分型政策,則對於具有該政策的實體 (IAM 使用者或角色) 而言,主控台就無法如預期運作。
允許使用者檢視他們自己的許可
此範例會示範如何建立政策,允許 IAM 使用者檢視附加到他們使用者身分的內嵌及受管政策。此政策包含在主控台或使用 或 AWS CLI AWS API 以程式設計方式完成此動作的許可。
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "ViewOwnUserInfo",
"Effect": "Allow",
"Action": [
"iam:GetUserPolicy",
"iam:ListGroupsForUser",
"iam:ListAttachedUserPolicies",
"iam:ListUserPolicies",
"iam:GetUser"
],
"Resource": ["arn:aws:iam::*:user/${aws:username}"]
},
{
"Sid": "NavigateInConsole",
"Effect": "Allow",
"Action": [
"iam:GetGroupPolicy",
"iam:GetPolicyVersion",
"iam:GetPolicy",
"iam:ListAttachedGroupPolicies",
"iam:ListGroupPolicies",
"iam:ListPolicyVersions",
"iam:ListPolicies",
"iam:ListUsers"
],
"Resource": "*"
}
]
}
Timestream for LiveAnalytics 中的常見操作
以下是允許 Timestream for LiveAnalytics 服務中常見操作的範例 IAM 政策。
允許所有操作
以下是允許 Timestream for LiveAnalytics 中所有操作的範例政策。
- JSON
-
-
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"timestream:*"
],
"Resource": "*"
}
]
}
允許 SELECT 操作
下列範例政策允許對特定資源進行 SELECT
樣式查詢。
將 取代<account_ID>
為您的 Amazon 帳戶 ID。
- JSON
-
-
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"timestream:Select",
"timestream:DescribeTable",
"timestream:ListMeasures"
],
"Resource": "arn:aws:timestream:us-east-1:111122223333
:database/sampleDB/table/DevOps"
},
{
"Effect": "Allow",
"Action": [
"timestream:DescribeEndpoints",
"timestream:SelectValues",
"timestream:CancelQuery"
],
"Resource": "*"
}
]
}
允許多個資源的 SELECT 操作
下列範例政策允許對多個資源進行 SELECT
樣式查詢。
將 取代<account_ID>
為您的 Amazon 帳戶 ID。
- JSON
-
-
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"timestream:Select",
"timestream:DescribeTable",
"timestream:ListMeasures"
],
"Resource": [
"arn:aws:timestream:us-east-1:111122223333
:database/sampleDB/table/DevOps",
"arn:aws:timestream:us-east-1:111122223333
:database/sampleDB/table/DevOps1",
"arn:aws:timestream:us-east-1:111122223333
:database/sampleDB/table/DevOps2"
]
},
{
"Effect": "Allow",
"Action": [
"timestream:DescribeEndpoints",
"timestream:SelectValues",
"timestream:CancelQuery"
],
"Resource": "*"
}
]
}
下列範例政策允許使用者執行中繼資料查詢,但不允許使用者執行在 Timestream for LiveAnalytics 中讀取或寫入實際資料的操作。
- JSON
-
-
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"timestream:DescribeEndpoints",
"timestream:DescribeTable",
"timestream:ListMeasures",
"timestream:SelectValues",
"timestream:ListTables",
"timestream:ListDatabases",
"timestream:CancelQuery"
],
"Resource": "*"
}
]
}
允許 INSERT 操作
下列範例政策允許使用者在帳戶 database/sampleDB/table/DevOps
中的 上執行 INSERT
操作<account_id>
。
將 取代<account_ID>
為您的 Amazon 帳戶 ID。
- JSON
-
-
{
"Version": "2012-10-17",
"Statement": [
{
"Action": [
"timestream:WriteRecords"
],
"Resource": [
"arn:aws:timestream:us-east-1:111122223333
:database/sampleDB/table/DevOps"
],
"Effect": "Allow"
},
{
"Action": [
"timestream:DescribeEndpoints"
],
"Resource": "*",
"Effect": "Allow"
}
]
}
允許 CRUD 操作
下列範例政策允許使用者在 Timestream for LiveAnalytics 中執行 CRUD 操作。
- JSON
-
-
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"timestream:DescribeEndpoints",
"timestream:CreateTable",
"timestream:DescribeTable",
"timestream:CreateDatabase",
"timestream:DescribeDatabase",
"timestream:ListTables",
"timestream:ListDatabases",
"timestream:DeleteTable",
"timestream:DeleteDatabase",
"timestream:UpdateTable",
"timestream:UpdateDatabase"
],
"Resource": "*"
}
]
}
取消查詢並選取資料,而不指定資源
下列範例政策允許使用者取消查詢,並對不需要資源規格的資料執行Select
查詢:
- JSON
-
-
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"timestream:SelectValues",
"timestream:CancelQuery"
],
"Resource": "*"
}
]
}
建立、描述、刪除和描述資料庫
下列範例政策允許使用者建立、描述、刪除和描述資料庫 sampleDB
:
- JSON
-
-
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"timestream:CreateDatabase",
"timestream:DescribeDatabase",
"timestream:DeleteDatabase",
"timestream:UpdateDatabase"
],
"Resource": "arn:aws:timestream:us-east-1:111122223333
:database/sampleDB"
}
]
}
依標籤限制列出的資料庫{"Owner": "${username}"}
下列範例政策允許使用者列出所有以鍵值對 標記的資料庫{"Owner": "${username}"}
:
- JSON
-
-
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"timestream:ListDatabases"
],
"Resource": "arn:aws:timestream:us-east-1:111122223333
:database/*",
"Condition": {
"StringEquals": {
"aws:ResourceTag/Owner": "${aws:username}"
}
}
}
]
}
列出資料庫中的所有資料表
下列範例政策會列出資料庫 中的所有資料表sampleDB
:
- JSON
-
-
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"timestream:ListTables"
],
"Resource": "arn:aws:timestream:us-east-1:111122223333
:database/sampleDB/"
}
]
}
在資料表上建立、描述、刪除、更新和選取
下列範例政策允許使用者建立資料表、描述資料表、刪除資料表、更新資料表,以及對資料庫 DevOps
中的資料表執行Select
查詢sampleDB
:
- JSON
-
-
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"timestream:CreateTable",
"timestream:DescribeTable",
"timestream:DeleteTable",
"timestream:UpdateTable",
"timestream:Select"
],
"Resource": "arn:aws:timestream:us-east-1:111122223333
:database/sampleDB/table/DevOps"
}
]
}
依資料表限制查詢
下列範例政策允許使用者查詢資料庫 DevOps
以外的所有資料表sampleDB
:
- JSON
-
-
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"timestream:Select"
],
"Resource": "arn:aws:timestream:us-east-1:111122223333
:database/sampleDB/table/*"
},
{
"Effect": "Deny",
"Action": [
"timestream:Select"
],
"Resource": "arn:aws:timestream:us-east-1:111122223333
:database/sampleDB/table/DevOps"
}
]
}
您可以在身分型政策中使用條件,根據標籤控制對 Timestream for LiveAnalytics 資源的存取。本節將提供一些範例。
下列範例示範如何建立政策,在資料表的 Owner
包含該使用者名稱的值時,將檢視資料表的許可授予使用者。
- JSON
-
-
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "ReadOnlyAccessTaggedTables",
"Effect": "Allow",
"Action": ":Select",
"Resource": "arn:aws::us-east-2:111122223333
:database/mydatabase/table/*",
"Condition": {
"StringEquals": {
"aws:ResourceTag/Owner": "${aws:username}"
}
}
}
]
}
您可以將此政策連接到您帳戶中的 IAM 使用者。如果名為 的使用者richard-roe
嘗試檢視 Timestream for LiveAnalytics 資料表,則該資料表必須加上標籤 Owner=richard-roe
或 owner=richard-roe
。否則,他便會被拒絕存取。條件標籤鍵 Owner
符合 Owner
和 owner
,因為條件索引鍵名稱不區分大小寫。如需詳細資訊,請參閱《IAM 使用者指南》中的 IAM JSON 政策元素:條件。
如果傳入請求的標籤具有金鑰Owner
和值 ,則下列政策會授予使用者建立具有標籤的資料表的許可username
:
- JSON
-
-
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "CreateTagTableUser",
"Effect": "Allow",
"Action": [
":Create",
":TagResource"
],
"Resource": "arn:aws::us-east-2:111122223333
:database/mydatabase/table/*",
"Condition": {
"ForAnyValue:StringEquals": {
"aws:RequestTag/Owner": "${aws:username}"
}
}
}
]
}
以下政策允許在env
標籤設定為 dev
或 的任何資料庫上使用 DescribeDatabase
APItest
:
- JSON
-
-
{ "Version": "2012-10-17",
"Statement": [
{
"Sid": "AllowDescribeEndpoints",
"Effect": "Allow",
"Action": [
"timestream:DescribeEndpoints"
],
"Resource": "*"
},
{
"Sid": "AllowDevTestAccess",
"Effect": "Allow",
"Action": [
"timestream:DescribeDatabase"
],
"Resource": "*",
"Condition": {
"StringEquals": {
"timestream:tag/env": [
"dev",
"test"
]
}
}
}
]
}
{ "Version": "2012-10-17",
"Statement": [
{
"Sid": "AllowTagAccessForDevResources",
"Effect": "Allow",
"Action": [
"timestream:TagResource"
],
"Resource": "*",
"Condition": {
"StringEquals": {
"aws:RequestTag/env": [
"test",
"dev"
]
}
}
}
]
}
此政策使用Condition
金鑰來允許將具有金鑰env
和值 test
、 qa
或 的標籤dev
新增至資源。
排程查詢
列出、刪除、更新、執行 ScheduledQuery
下列範例政策允許使用者列出、刪除、更新和執行排定的查詢。
- JSON
-
-
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"timestream:DeleteScheduledQuery",
"timestream:ExecuteScheduledQuery",
"timestream:UpdateScheduledQuery",
"timestream:ListScheduledQueries",
"timestream:DescribeEndpoints"
],
"Resource": "*"
}
]
}
使用客戶受管 KMS 金鑰的 CreateScheduledQuery
下列範例政策允許使用者建立使用客戶受管 KMS 金鑰 <keyid for ScheduledQuery>
加密的排程查詢。
- JSON
-
-
{
"Version": "2012-10-17",
"Statement": [
{
"Action": [
"iam:PassRole"
],
"Resource": [
"arn:aws:iam::123456789012:role/ScheduledQueryExecutionRole"
],
"Effect": "Allow"
},
{
"Action": [
"timestream:CreateScheduledQuery",
"timestream:DescribeEndpoints"
],
"Resource": "*",
"Effect": "Allow"
},
{
"Action": [
"kms:DescribeKey",
"kms:GenerateDataKey"
],
"Resource": "arn:aws:kms:us-west-2:123456789012:key/<keyid for ScheduledQuery>
",
"Effect": "Allow"
}
]
}
DescribeScheduledQuery 使用客戶受管 KMS 金鑰
下列範例政策允許使用者描述使用客戶受管 KMS 金鑰建立的排程查詢;<keyid for ScheduledQuery>
。
- JSON
-
-
{
"Version": "2012-10-17",
"Statement": [
{
"Action": [
"timestream:DescribeScheduledQuery",
"timestream:DescribeEndpoints"
],
"Resource": "*",
"Effect": "Allow"
},
{
"Action": [
"kms:Decrypt"
],
"Resource": "arn:aws:kms:us-west-2:123456789012:key/<keyid for ScheduledQuery>
",
"Effect": "Allow"
}
]
}
執行角色許可 (針對排程查詢使用客戶受管 KMS 金鑰,針對錯誤報告使用 SSE-KMS)
將下列範例政策連接至 ScheduledQueryExecutionRoleArn
參數中指定的 IAM 角色,該 CreateScheduledQuery
API 使用客戶受管 KMS 金鑰進行排程查詢加密,並將SSE-KMS
加密用於錯誤報告。
- JSON
-
-
{
"Version": "2012-10-17",
"Statement": [
{
"Action": [
"kms:GenerateDataKey"
],
"Resource": "arn:aws:kms:us-west-2:123456789012:key/<keyid for ScheduledQuery>
",
"Effect": "Allow"
},
{
"Action": [
"kms:Decrypt"
],
"Resource": [
"arn:aws:kms:us-west-2:123456789012:key/<keyid for database-1>
",
"arn:aws:kms:us-west-2:123456789012:key/<keyid for database-n>
",
"arn:aws:kms:us-west-2:123456789012:key/<keyid for ScheduledQuery>
"
],
"Effect": "Allow"
},
{
"Action": [
"sns:Publish"
],
"Resource": [
"arn:aws:sns:us-west-2:123456789012:scheduled-query-notification-topic
-*"
],
"Effect": "Allow"
},
{
"Action": [
"timestream:Select",
"timestream:SelectValues",
"timestream:WriteRecords"
],
"Resource": "*",
"Effect": "Allow"
},
{
"Action": [
"s3:PutObject",
"s3:GetBucketAcl"
],
"Resource": [
"arn:aws:s3:::scheduled-query-error-bucket
",
"arn:aws:s3:::scheduled-query-error-bucket
/*"
],
"Effect": "Allow"
}
]
}
執行角色信任關係
以下是 CreateScheduledQuery
API ScheduledQueryExecutionRoleArn
參數中指定之 IAM 角色的信任關係。
- JSON
-
-
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"Service": [
"timestream.amazonaws.com"
]
},
"Action": "sts:AssumeRole"
}
]
}
允許存取帳戶內建立的所有排程查詢
將下列範例政策連接至 ScheduledQueryExecutionRoleArn
CreateScheduledQuery
API 參數中指定的 IAM 角色,以允許存取帳戶 Account_ID
內建立的所有排程查詢。
- JSON
-
-
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"Service": "timestream.amazonaws.com"
},
"Action": "sts:AssumeRole",
"Condition": {
"StringEquals": {
"aws:SourceAccount": "Account_ID
"
},
"ArnLike": {
"aws:SourceArn": "arn:aws:timestream:us-west-2:111122223333
:scheduled-query/*"
}
}
}
]
}
允許存取具有特定名稱的所有排程查詢
將下列範例政策連接至 ScheduledQueryExecutionRoleArn
CreateScheduledQuery
API 參數中指定的 IAM 角色,以允許存取帳戶 Account_ID
中名稱開頭為 Scheduled_Query_Name
的所有排程查詢。
- JSON
-
-
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"Service": "timestream.amazonaws.com"
},
"Action": "sts:AssumeRole",
"Condition": {
"StringEquals": {
"aws:SourceAccount": "Account_ID
"
},
"ArnLike": {
"aws:SourceArn": "arn:aws:timestream:us-west-2:111122223333
:scheduled-query/Scheduled_Query_Name
*"
}
}
}
]
}