AWS SDK for JavaScript Detective Client for Node.js, Browser and React Native
npm install @aws-sdk/client-detectiveAWS SDK for JavaScript Detective Client for Node.js, Browser and React Native.
Detective uses machine learning and purpose-built visualizations to help you to
analyze and investigate security issues across your Amazon Web Services (Amazon Web Services) workloads. Detective automatically extracts time-based events such
as login attempts, API calls, and network traffic from CloudTrail and Amazon Virtual Private Cloud (Amazon VPC) flow logs. It also extracts findings detected by
Amazon GuardDuty.
The Detective API primarily supports the creation and management of behavior
graphs. A behavior graph contains the extracted data from a set of member accounts, and is
created and managed by an administrator account.
To add a member account to the behavior graph, the administrator account sends an
invitation to the account. When the account accepts the invitation, it becomes a member
account in the behavior graph.
Detective is also integrated with Organizations. The organization
management account designates the Detective administrator account for the
organization. That account becomes the administrator account for the organization behavior
graph. The Detective administrator account is also the delegated administrator
account for Detective in Organizations.
The Detective administrator account can enable any organization account as a
member account in the organization behavior graph. The organization accounts do not receive
invitations. The Detective administrator account can also invite other accounts to
the organization behavior graph.
Every behavior graph is specific to a Region. You can only use the API to manage
behavior graphs that belong to the Region that is associated with the currently selected
endpoint.
The administrator account for a behavior graph can use the Detective API to do
the following:
Enable and disable Detective. Enabling Detective creates a new
behavior graph.
View the list of member accounts in a behavior graph.
Add member accounts to a behavior graph.
Remove member accounts from a behavior graph.
Apply tags to a behavior graph.
The organization management account can use the Detective API to select the
delegated administrator for Detective.
The Detective administrator account for an organization can use the Detective API to do the following:
Perform all of the functions of an administrator account.
Determine whether to automatically enable new organization accounts as member
accounts in the organization behavior graph.
An invited member account can use the Detective API to do the following:
View the list of behavior graphs that they are invited to.
Accept an invitation to contribute to a behavior graph.
Decline an invitation to contribute to a behavior graph.
Remove their account from a behavior graph.
All API actions are logged as CloudTrail events. See Logging Detective API Calls with CloudTrail.
We replaced the term "master account" with the term "administrator account". An
administrator account is used to centrally manage multiple accounts. In the case of
Detective, the administrator account manages the accounts in their behavior
graph.
npm install @aws-sdk/client-detectiveyarn add @aws-sdk/client-detectivepnpm add @aws-sdk/client-detectiveThe AWS SDK is modulized by clients and commands.
To send a request, you only need to import the DetectiveClient and
the commands you need, for example ListGraphsCommand:
``js`
// ES5 example
const { DetectiveClient, ListGraphsCommand } = require("@aws-sdk/client-detective");
`ts`
// ES6+ example
import { DetectiveClient, ListGraphsCommand } from "@aws-sdk/client-detective";
To send a request, you:
- Initiate client with configuration (e.g. credentials, region).
- Initiate command with input parameters.
- Call send operation on client with command object as input.destroy()
- If you are using a custom http handler, you may call to close open connections.
`js
// a client can be shared by different commands.
const client = new DetectiveClient({ region: "REGION" });
const params = { /* input parameters / };
const command = new ListGraphsCommand(params);
`
#### Async/await
We recommend using await
operator to wait for the promise returned by send operation as follows:
`js`
// async/await.
try {
const data = await client.send(command);
// process data.
} catch (error) {
// error handling.
} finally {
// finally.
}
Async-await is clean, concise, intuitive, easy to debug and has better error handling
as compared to using Promise chains or callbacks.
#### Promises
You can also use Promise chaining
to execute send operation.
`js`
client.send(command).then(
(data) => {
// process data.
},
(error) => {
// error handling.
}
);
Promises can also be called using .catch() and .finally() as follows:
`js`
client
.send(command)
.then((data) => {
// process data.
})
.catch((error) => {
// error handling.
})
.finally(() => {
// finally.
});
#### Callbacks
We do not recommend using callbacks because of callback hell,
but they are supported by the send operation.
`js`
// callbacks.
client.send(command, (err, data) => {
// process err and data.
});
#### v2 compatible style
The client can also send requests using v2 compatible style.
However, it results in a bigger bundle size and may be dropped in next major version. More details in the blog post
on modular packages in AWS SDK for JavaScript
`ts
import * as AWS from "@aws-sdk/client-detective";
const client = new AWS.Detective({ region: "REGION" });
// async/await.
try {
const data = await client.listGraphs(params);
// process data.
} catch (error) {
// error handling.
}
// Promises.
client
.listGraphs(params)
.then((data) => {
// process data.
})
.catch((error) => {
// error handling.
});
// callbacks.
client.listGraphs(params, (err, data) => {
// process err and data.
});
`
When the service returns an exception, the error will include the exception information,
as well as response metadata (e.g. request id).
`js`
try {
const data = await client.send(command);
// process data.
} catch (error) {
const { requestId, cfId, extendedRequestId } = error.$metadata;
console.log({ requestId, cfId, extendedRequestId });
/**
* The keys within exceptions are also parsed.
* You can access them by specifying exception names:
* if (error.name === 'SomeServiceException') {
* const value = error.specialKeyInException;
* }
*/
}
Please use these community resources for getting help.
We use the GitHub issues for tracking bugs and feature requests, but have limited bandwidth to address them.
- Visit Developer Guide
or API Reference.
- Check out the blog posts tagged with aws-sdk-js
on AWS Developer Blog.
- Ask a question on StackOverflow and tag it with aws-sdk-js.
- Join the AWS JavaScript community on gitter.
- If it turns out that you may have found a bug, please open an issue.
To test your universal JavaScript code in Node.js, browser and react-native environments,
visit our code samples repo.
This client code is generated automatically. Any modifications will be overwritten the next time the @aws-sdk/client-detective` package is updated.
To contribute to client you can check our generate clients scripts.
This SDK is distributed under the
Apache License, Version 2.0,
see LICENSE for more information.
AcceptInvitation
Command API Reference / Input / Output
BatchGetGraphMemberDatasources
Command API Reference / Input / Output
BatchGetMembershipDatasources
Command API Reference / Input / Output
CreateGraph
Command API Reference / Input / Output
CreateMembers
Command API Reference / Input / Output
DeleteGraph
Command API Reference / Input / Output
DeleteMembers
Command API Reference / Input / Output
DescribeOrganizationConfiguration
Command API Reference / Input / Output
DisableOrganizationAdminAccount
Command API Reference / Input / Output
DisassociateMembership
Command API Reference / Input / Output
EnableOrganizationAdminAccount
Command API Reference / Input / Output
GetInvestigation
Command API Reference / Input / Output
GetMembers
Command API Reference / Input / Output
ListDatasourcePackages
Command API Reference / Input / Output
ListGraphs
Command API Reference / Input / Output
ListIndicators
Command API Reference / Input / Output
ListInvestigations
Command API Reference / Input / Output
ListInvitations
Command API Reference / Input / Output
ListMembers
Command API Reference / Input / Output
ListOrganizationAdminAccounts
Command API Reference / Input / Output
ListTagsForResource
Command API Reference / Input / Output
RejectInvitation
Command API Reference / Input / Output
StartInvestigation
Command API Reference / Input / Output
StartMonitoringMember
Command API Reference / Input / Output
TagResource
Command API Reference / Input / Output
UntagResource
Command API Reference / Input / Output
UpdateDatasourcePackages
Command API Reference / Input / Output
UpdateInvestigationState
Command API Reference / Input / Output
UpdateOrganizationConfiguration