本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。
使用 的偵測範例 AWS CLI
下列程式碼範例示範如何使用 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 帳戶 IDs。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 帳戶 IDs。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範例會從指定的行為圖表中移除部門標籤。aws detective untag-resource \ --resource-arnarn:aws:detective:us-east-1:111122223333:graph:123412341234\ --tag-keys"Department"此命令不會產生輸出。 如需詳細資訊,請參閱《Amazon Detective 管理指南》中的管理行為圖表的標籤。 - 
                    如需 API 詳細資訊,請參閱《AWS CLI 命令參考》中的 UntagResource 。 
 
-