使用 AWS CLI 的 Detective 範例
下列程式碼範例示範如何使用 AWS Command Line Interface 搭配 Detective 來執行動作,並實作常見案例。
Actions 是大型程式的程式碼摘錄,必須在內容中執行。雖然動作會告訴您如何呼叫個別服務函數,但您可以在其相關情境中查看內容中的動作。
每個範例均包含完整原始程式碼的連結,您可在連結中找到如何在內容中設定和執行程式碼的相關指示。
主題
動作
以下程式碼範例顯示如何使用 accept-invitation。
- AWS CLI
-
接受在行為圖表中成為會員帳戶的邀請
下列
accept-invitation範例接受邀請,因而在行為圖表 arn:aws:detective:us-east-1:111122223333:graph:123412341234 中成為會員帳戶。aws detective accept-invitation \ --graph-arnarn:aws:detective:us-east-1:111122223333:graph:123412341234此命令不會產生輸出。
如需詳細資訊,請參閱《Amazon Detective 管理指南》中的回應行為圖表邀請。
-
如需 API 詳細資訊,請參閱《AWS CLI 命令參考》中的 AcceptInvitation
。
-
以下程式碼範例顯示如何使用 create-graph。
- AWS CLI
-
啟用 Amazon Detective,並建立新的行為圖表
下列
create-graph範例為在執行命令的區域中執行命令 AWS 的帳戶,啟用 Detective。建立新的行為圖表,並以該帳戶做為其管理員帳戶。該命令也會將 Finance 值指派給 Department 標籤。aws detective create-graph \ --tags '{"Department": "Finance"}'輸出:
{ "GraphArn": "arn:aws:detective:us-east-1:111122223333:graph:027c7c4610ea4aacaf0b883093cab899" }如需詳細資訊,請參閱《Amazon Detective 管理指南》中的啟用 Amazon Detective。
-
如需 API 詳細資訊,請參閱《AWS CLI 命令參考》中的 CreateGraph
。
-
以下程式碼範例顯示如何使用 create-members。
- AWS CLI
-
邀請會員帳戶至行為圖表
下列
create-members範例邀請兩個 AWS 帳戶成為行為圖表 arn:aws:detective:us-east-1:111122223333:graph:123412341234 中的會員帳戶。對於每個帳戶,請求提供 AWS 帳戶 ID 和帳戶根使用者電子郵件地址。請求包含要插入邀請電子郵件的自訂訊息。aws detective create-members \ --accountsAccountId=444455556666,EmailAddress=mmajor@example.comAccountId=123456789012,EmailAddress=jstiles@example.com\ --graph-arnarn:aws:detective:us-east-1:111122223333:graph:123412341234\ --message"This is Paul Santos. I need to add your account to the data we use for security investigation in Amazon Detective. If you have any questions, contact me at psantos@example.com."輸出:
{ "Members": [ { "AccountId": "444455556666", "AdministratorId": "111122223333", "EmailAddress": "mmajor@example.com", "GraphArn": "arn:aws:detective:us-east-1:111122223333:graph:123412341234", "InvitedTime": 1579826107000, "MasterId": "111122223333", "Status": "INVITED", "UpdatedTime": 1579826107000 }, { "AccountId": "123456789012", "AdministratorId": "111122223333", "EmailAddress": "jstiles@example.com", "GraphArn": "arn:aws:detective:us-east-1:111122223333:graph:123412341234", "InvitedTime": 1579826107000, "MasterId": "111122223333", "Status": "VERIFICATION_IN_PROGRESS", "UpdatedTime": 1579826107000 } ], "UnprocessedAccounts": [ ] }如需詳細資訊,請參閱《Amazon Detective 管理指南》中的「邀請會員帳至行為圖表<https://docs.aws.amazon.com/detective/latest/adminguide/graph-admin-add-member-accounts.html>」。
邀請會員帳戶而不傳送邀請電子郵件
下列
create-members範例邀請兩個 AWS 帳戶成為行為圖表 arn:aws:detective:us-east-1:111122223333:graph:123412341234 中的會員帳戶。對於每個帳戶,請求提供 AWS 帳戶 ID 和帳戶根使用者電子郵件地址。會員帳戶不會收到邀請電子郵件。aws detective create-members \ --accountsAccountId=444455556666,EmailAddress=mmajor@example.comAccountId=123456789012,EmailAddress=jstiles@example.com\ --graph-arnarn:aws:detective:us-east-1:111122223333:graph:123412341234\ --disable-email-notification輸出:
{ "Members": [ { "AccountId": "444455556666", "AdministratorId": "111122223333", "EmailAddress": "mmajor@example.com", "GraphArn": "arn:aws:detective:us-east-1:111122223333:graph:123412341234", "InvitedTime": 1579826107000, "MasterId": "111122223333", "Status": "INVITED", "UpdatedTime": 1579826107000 }, { "AccountId": "123456789012", "AdministratorId": "111122223333", "EmailAddress": "jstiles@example.com", "GraphArn": "arn:aws:detective:us-east-1:111122223333:graph:123412341234", "InvitedTime": 1579826107000, "MasterId": "111122223333", "Status": "VERIFICATION_IN_PROGRESS", "UpdatedTime": 1579826107000 } ], "UnprocessedAccounts": [ ] }如需詳細資訊,請參閱《Amazon Detective 管理指南》中的「邀請會員帳至行為圖表<https://docs.aws.amazon.com/detective/latest/adminguide/graph-admin-add-member-accounts.html>」。
-
如需 API 詳細資訊,請參閱《AWS CLI 命令參考》中的 CreateMembers
。
-
以下程式碼範例顯示如何使用 delete-graph。
- AWS CLI
-
停用 Detective 並刪除行為圖表
下列
delete-graph範例會停用 Detective,並刪除指定的行為圖表。aws detective delete-graph \ --graph-arnarn:aws:detective:us-east-1:111122223333:graph:123412341234此命令不會產生輸出。
如需詳細資訊,請參閱《Amazon Detective 管理指南》中的停用 Amazon Detective。
-
如需 API 詳細資訊,請參閱《AWS CLI 命令參考》中的 DeleteGraph
。
-
以下程式碼範例顯示如何使用 delete-members。
- AWS CLI
-
將會員帳戶從行為圖表中移除
下列
delete-members範例從行為圖表 arn:aws:detective:us-east-1:111122223333:graph:123412341234 中移除兩個會員帳戶。若要識別帳戶,請求會提供 AWS 帳戶 ID。aws detective delete-members \ --account-ids444455556666123456789012\ --graph-arnarn:aws:detective:us-east-1:111122223333:graph:123412341234輸出:
{ "AccountIds": [ "444455556666", "123456789012" ], "UnprocessedAccounts": [ ] }如需詳細資訊,請參閱《Amazon Detective 管理指南》中的「從行為圖表<https://docs.aws.amazon.com/detective/latest/adminguide/graph-admin-remove-member-accounts.html>移除會員帳戶」。
-
如需 API 詳細資訊,請參閱《AWS CLI 命令參考》中的 DeleteMembers
。
-
以下程式碼範例顯示如何使用 disassociate-membership。
- AWS CLI
-
從行為圖表中放棄成員資格
下列 disassociate-membership 範例會從行為圖表 arn:aws:detective:us-east-1:111122223333:graph:123412341234 中移除執行該命令的 AWS 帳戶。
aws detective disassociate-membership \ --graph-arnarn:aws:detective:us-east-1:111122223333:graph:123412341234如需詳細資訊,請參閱《Amazon Detective 管理指南》中的「從行為圖表<https://docs.aws.amazon.com/detective/latest/adminguide/member-remove-self-from-graph.html>中移除您的帳戶」。
-
如需 API 詳細資訊,請參閱《AWS CLI 命令參考》中的 DisassociateMembership
。
-
以下程式碼範例顯示如何使用 get-members。
- AWS CLI
-
擷取所選行為圖表會員帳戶的相關資訊
下列
get-members範例擷取行為圖表 arn:aws:detective:us-east-1:111122223333:graph:123412341234 中兩個會員帳戶的相關資訊。對於這兩個帳戶,請求會提供 AWS 帳戶 ID。aws detective get-members \ --account-ids444455556666123456789012\ --graph-arnarn:aws:detective:us-east-1:111122223333:graph:123412341234輸出:
{ "MemberDetails": [ { "AccountId": "444455556666", "AdministratorId": "111122223333", "EmailAddress": "mmajor@example.com", "GraphArn": "arn:aws:detective:us-east-1:111122223333:graph:123412341234", "InvitedTime": 1579826107000, "MasterId": "111122223333", "Status": "INVITED", "UpdatedTime": 1579826107000 } { "AccountId": "123456789012", "AdministratorId": "111122223333", "EmailAddress": "jstiles@example.com", "GraphArn": "arn:aws:detective:us-east-1:111122223333:graph:123412341234", "InvitedTime": 1579826107000, "MasterId": "111122223333", "Status": "INVITED", "UpdatedTime": 1579826107000 } ], "UnprocessedAccounts": [ ] }如需詳細資訊,請參閱《Amazon Detective 管理指南》中的「檢視行為圖表中的帳戶清單<https://docs.aws.amazon.com/detective/latest/adminguide/graph-admin-view-accounts.html>」。
-
如需 API 詳細資訊,請參閱《AWS CLI 命令參考》中的 GetMembers
。
-
以下程式碼範例顯示如何使用 list-graphs。
- AWS CLI
-
檢視您的帳戶所管理的行為圖表清單
下列
list-graphs範例會擷取目前區域內呼叫帳戶做為管理員的行為圖表。aws detective list-graphs輸出:
{ "GraphList": [ { "Arn": "arn:aws:detective:us-east-1:111122223333:graph:123412341234", "CreatedTime": 1579736111000 } ] }-
如需 API 詳細資訊,請參閱《AWS CLI 命令參考》中的 ListGraphs
。
-
以下程式碼範例顯示如何使用 list-invitations。
- AWS CLI
-
檢視帳戶所屬或受邀加入的行為圖表清單
下列
list-invitations範例會擷取呼叫帳戶已受邀請的行為圖表。結果僅包含開啟和接受的邀請。不包含遭拒的邀請或移除的成員資格。aws detective list-invitations輸出:
{ "Invitations": [ { "AccountId": "444455556666", "AdministratorId": "111122223333", "EmailAddress": "mmajor@example.com", "GraphArn": "arn:aws:detective:us-east-1:111122223333:graph:123412341234", "InvitedTime": 1579826107000, "MasterId": "111122223333", "Status": "INVITED", "UpdatedTime": 1579826107000 } ] }如需詳細資訊,請參閱《Amazon Detective 管理指南》中的「檢視行為圖表邀請清單<https://docs.aws.amazon.com/detective/latest/adminguide/member-view-graph-invitations.html>」。
-
如需 API 詳細資訊,請參閱《AWS CLI 命令參考》中的 ListInvitations
。
-
以下程式碼範例顯示如何使用 list-members。
- AWS CLI
-
列出行為圖表中的會員帳戶
下列
list-members範例會擷取行為圖表arn:aws:detective:us-east-1:111122223333:graph:123412341234的受邀和啟用的會員帳戶。結果不包含已移除的會員帳戶。aws detective list-members \ --graph-arnarn:aws:detective:us-east-1:111122223333:graph:123412341234輸出:
{ "MemberDetails": [ { "AccountId": "444455556666", "AdministratorId": "111122223333", "EmailAddress": "mmajor@example.com", "GraphArn": "arn:aws:detective:us-east-1:111122223333:graph:123412341234", "InvitedTime": 1579826107000, "MasterId": "111122223333", "Status": "INVITED", "UpdatedTime": 1579826107000 }, { "AccountId": "123456789012", "AdministratorId": "111122223333", "EmailAddress": "jstiles@example.com", "GraphArn": "arn:aws:detective:us-east-1:111122223333:graph:123412341234", "InvitedTime": 1579826107000, "MasterId": "111122223333", "PercentOfGraphUtilization": 2, "PercentOfGraphUtilizationUpdatedTime": 1586287843, "Status": "ENABLED", "UpdatedTime": 1579973711000, "VolumeUsageInBytes": 200, "VolumeUsageUpdatedTime": 1586287843 } ] }如需詳細資訊,請參閱《Amazon Detective 管理指南》中的檢視行為圖表中的帳戶清單。
-
如需 API 詳細資訊,請參閱《AWS CLI 命令參考》中的 ListMembers
。
-
以下程式碼範例顯示如何使用 list-tags-for-resource。
- AWS CLI
-
擷取指派給行為圖表的標籤
下列
list-tags-for-resource範例會傳回指派給指定之行為圖表的標籤。aws detective list-tags-for-resource \ --resource-arnarn:aws:detective:us-east-1:111122223333:graph:123412341234輸出:
{ "Tags": { "Department" : "Finance" } }如需詳細資訊,請參閱《Amazon Detective 管理指南》中的管理行為圖表的標籤。
-
如需 API 詳細資訊,請參閱《AWS CLI 命令參考》中的 ListTagsForResource
。
-
以下程式碼範例顯示如何使用 reject-invitation。
- AWS CLI
-
拒絕成為行為圖表中的會員帳戶的邀請
下列
reject-invitation範例拒絕在行為圖表 arn:aws:detective:us-east-1:111122223333:graph:123412341234 中成為會員帳戶的邀請。aws detective reject-invitation \ --graph-arnarn:aws:detective:us-east-1:111122223333:graph:123412341234此命令不會產生輸出。
如需詳細資訊,請參閱《Amazon Detective 管理指南》中的「回應行為圖表邀請<https://docs.aws.amazon.com/detective/latest/adminguide/member-invitation-response.html>」。
-
如需 API 詳細資訊,請參閱《AWS CLI 命令參考》中的 RejectInvitation
。
-
以下程式碼範例顯示如何使用 tag-resource。
- AWS CLI
-
將標籤指派給資源
下列
tag-resource範例將 Department 標籤的值指派給指定的行為圖表。aws detective tag-resource \ --resource-arnarn:aws:detective:us-east-1:111122223333:graph:123412341234\ --tags '{"Department":"Finance"}'此命令不會產生輸出。
如需詳細資訊,請參閱《Amazon Detective 管理指南》中的管理行為圖表的標籤。
-
如需 API 詳細資訊,請參閱《AWS CLI 命令參考》中的 TagResource
。
-
以下程式碼範例顯示如何使用 untag-resource。
- AWS CLI
-
將標籤值從資源中移除
下列
untag-resource範例從指定的行為圖表中移除 Department 標籤。aws detective untag-resource \ --resource-arnarn:aws:detective:us-east-1:111122223333:graph:123412341234\ --tag-keys"Department"此命令不會產生輸出。
如需詳細資訊,請參閱《Amazon Detective 管理指南》中的管理行為圖表的標籤。
-
如需 API 詳細資訊,請參閱《AWS CLI 命令參考》中的 UntagResource
。
-