AWS CLI を使用した Detective の例 - AWS Command Line Interface

AWS CLI を使用した Detective の例

次のコード例は、Detective で AWS Command Line Interfaceを使用してアクションを実行し、一般的なシナリオを実装する方法を示しています。

アクションはより大きなプログラムからのコードの抜粋であり、コンテキスト内で実行する必要があります。アクションは個々のサービス機能を呼び出す方法を示していますが、コンテキスト内のアクションは、関連するシナリオで確認できます。

各例には完全なソースコードへのリンクが含まれており、コードの設定方法と実行方法に関する手順を確認できます。

トピック

アクション

次のコード例は、accept-invitation を使用する方法を示しています。

AWS CLI

動作グラフのメンバーアカウントになるための招待を受け入れるには

次の accept-invitation の例では、動作グラフ arn:aws:detective:us-east-1:111122223333:graph:123412341234 のメンバーアカウントになるための招待を受け入れます。

aws detective accept-invitation \ --graph-arn arn:aws:detective:us-east-1:111122223333:graph:123412341234

このコマンドでは何も出力されません。

詳細については、「Amazon Detective Administration Guide」の「Responding to a behavior graph invitation」を参照してください。

  • API の詳細については、「AWS CLI コマンドリファレンス」の「AcceptInvitation」を参照してください。

次の例は、create-graph を使用する方法を説明しています。

AWS CLI

Amazon Detective を有効にして新しい動作グラフを作成するには

次の create-graph の例では、コマンドが実行されているリージョンでコマンドを実行する AWS アカウントに対して Detective を有効にします。そのアカウントを管理者アカウントとする新しい動作グラフが作成されます。このコマンドは、部門タグに「財務」という値を割り当てます。

aws detective create-graph \ --tags '{"Department": "Finance"}'

出力:

{ "GraphArn": "arn:aws:detective:us-east-1:111122223333:graph:027c7c4610ea4aacaf0b883093cab899" }

詳細については、「Amazon Detective Administration Guide」の「Enabling Amazon Detective」を参照してください。

  • API の詳細については、「AWS CLI コマンドリファレンス」の「CreateGraph」を参照してください。

次のコード例は、create-members を使用する方法を示しています。

AWS CLI

動作グラフにメンバーアカウントを招待するには

次の create-members の例では、動作グラフ arn:aws:detective:us-east-1:111122223333:graph:123412341234 のメンバーアカウントになるよう 2 つの AWS アカウントを招待します。アカウントごとに、このリクエストで AWS アカウント ID とアカウントルートユーザーのメールアドレスが提供されます。リクエストには、招待メールに挿入するカスタムメッセージが含まれています。

aws detective create-members \ --accounts AccountId=444455556666,EmailAddress=mmajor@example.com AccountId=123456789012,EmailAddress=jstiles@example.com \ --graph-arn arn: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 Administration Guide」の「Inviting member accounts to a behavior graph<https://docs.aws.amazon.com/detective/latest/adminguide/graph-admin-add-member-accounts.html>」を参照してください。

招待メールを送信せずにメンバーアカウントを招待するには

次の create-members の例では、動作グラフ arn:aws:detective:us-east-1:111122223333:graph:123412341234 のメンバーアカウントになるよう 2 つの AWS アカウントを招待します。アカウントごとに、このリクエストで AWS アカウント ID とアカウントルートユーザーのメールアドレスが提供されます。メンバーアカウントには招待メールは届きません。

aws detective create-members \ --accounts AccountId=444455556666,EmailAddress=mmajor@example.com AccountId=123456789012,EmailAddress=jstiles@example.com \ --graph-arn arn: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 Administration Guide」の「Inviting member accounts to a behavior graph<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-arn arn:aws:detective:us-east-1:111122223333:graph:123412341234

このコマンドでは何も出力されません。

詳細については、「Amazon Detective Administration Guide」の「Disabling Amazon Detective」を参照してください。

  • API の詳細については、「AWS CLI コマンドリファレンス」の「DeleteGraph」を参照してください。

次の例は、delete-members を使用する方法を説明しています。

AWS CLI

動作グラフからメンバーアカウントを削除するには

次の delete-members の例では、動作グラフ arn:aws:detective:us-east-1:111122223333:graph:123412341234 から 2 つのメンバーアカウントを削除します。アカウントを識別するには、リクエストで AWS アカウント ID を提供します。

aws detective delete-members \ --account-ids 444455556666 123456789012 \ --graph-arn arn:aws:detective:us-east-1:111122223333:graph:123412341234

出力:

{ "AccountIds": [ "444455556666", "123456789012" ], "UnprocessedAccounts": [ ] }

詳細については、「Amazon Detective Administration Guide」の「Removing member accounts from a behavior graph<https://docs.aws.amazon.com/detective/latest/adminguide/graph-admin-remove-member-accounts.html>」を参照してください。

  • API の詳細については、「AWS CLI コマンドリファレンス」の「DeleteMembers」を参照してください。

次のコード例は、disassociate-membership を使用する方法を示しています。

AWS CLI

動作グラフのメンバーシップを辞退するには

次のメンバーシップの関連付け解除の例では、動作グラフ arn:aws:detective:us-east-1:111122223333:graph:123412341234 からコマンドを実行する AWS アカウントを削除します。

aws detective disassociate-membership \ --graph-arn arn:aws:detective:us-east-1:111122223333:graph:123412341234

詳細については、「Amazon Detective Administration Guide」の「Removing your account from a behavior graph<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 の 2 つのメンバーアカウントに関する情報を取得します。2 つのアカウントに対し、リクエストで AWS アカウント ID が提供されます。

aws detective get-members \ --account-ids 444455556666 123456789012 \ --graph-arn arn: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 Administration Guide」の「Viewing the list of accounts in a behavior graph<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 Administration Guide」の「Viewing your list of behavior graph invitations<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-arn arn: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 Administration Guide」の「Viewing the list of accounts in a behavior graph」を参照してください。

  • API の詳細については、「AWS CLI コマンドリファレンス」の「ListMembers」を参照してください。

次のコード例は、list-tags-for-resource を使用する方法を示しています。

AWS CLI

動作グラフに割り当てられたタグを取得するには

次の list-tags-for-resource の例では、指定された動作グラフに割り当てられたタグを返します。

aws detective list-tags-for-resource \ --resource-arn arn:aws:detective:us-east-1:111122223333:graph:123412341234

出力:

{ "Tags": { "Department" : "Finance" } }

詳細については、「Amazon Detective Administration Guide」の「Managing tags for a behavior graph」を参照してください。

  • API の詳細については、「AWS CLI コマンドリファレンス」の「ListTagsForResource」を参照してください。

次の例は、reject-invitation を使用する方法を説明しています。

AWS CLI

動作グラフのメンバーアカウントになるための招待を拒否するには

次の reject-invitation の例では、動作グラフ arn:aws:detective:us-east-1:111122223333:graph:123412341234 のメンバーアカウントになるための招待を拒否します。

aws detective reject-invitation \ --graph-arn arn:aws:detective:us-east-1:111122223333:graph:123412341234

このコマンドでは何も出力されません。

詳細については、「Amazon Detective Administration Guide」の「Responding to a behavior graph invitation<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-arn arn:aws:detective:us-east-1:111122223333:graph:123412341234 \ --tags '{"Department":"Finance"}'

このコマンドでは何も出力されません。

詳細については、「Amazon Detective Administration Guide」の「Managing tags for a behavior graph」を参照してください。

  • API の詳細については、AWS CLI コマンドリファレンスの「TagResource」を参照してください。

次の例は、untag-resource を使用する方法を説明しています。

AWS CLI

リソースからタグ値を削除するには

次の untag-resource の例では、指定された動作グラフから Department タグを削除します。

aws detective untag-resource \ --resource-arn arn:aws:detective:us-east-1:111122223333:graph:123412341234 \ --tag-keys "Department"

このコマンドでは何も出力されません。

詳細については、「Amazon Detective Administration Guide」の「Managing tags for a behavior graph」を参照してください。

  • API の詳細については、「AWS CLI コマンドリファレンス」の「UntagResource」を参照してください。