@aws-sdk/client-iam
Description
AWS SDK for JavaScript IAM Client for Node.js, Browser and React Native.
Identity and Access Management
Identity and Access Management (IAM) is a web service for securely controlling access to Amazon Web Services services. With IAM, you can centrally manage users, security credentials such as access keys, and permissions that control which Amazon Web Services resources users and applications can access. For more information about IAM, see Identity and Access Management (IAM) and the Identity and Access Management User Guide.
Programmatic access to IAM
We recommend that you use the Amazon Web Services SDKs to make programmatic API calls to IAM. The Amazon Web Services SDKs consist of libraries and sample code for various programming languages and platforms (for example, Java, Ruby, .NET, iOS, and Android). The SDKs provide a convenient way to create programmatic access to IAM and Amazon Web Services. For example, the SDKs take care of tasks such as cryptographically signing requests, managing errors, and retrying requests automatically. For more information, see Tools to build on Amazon Web Services.
Alternatively, you can also use the IAM Query API to make direct calls to the IAM service. For more information about calling the IAM Query API, see Making query requests in the Identity and Access Management User Guide. IAM supports GET and POST requests for all actions. That is, the API does not require you to use GET for some actions and POST for others. However, GET requests are subject to the limitation size of a URL. Therefore, for operations that require larger sizes, use a POST request.
Signing requests
Requests must be signed using an access key ID and a secret access key. We strongly recommend that you do not use your Amazon Web Services account access key ID and secret access key for everyday work with IAM. You can use the access key ID and secret access key for an IAM user or you can use the Security Token Service to generate temporary security credentials and use those to sign requests.
To sign requests, we recommend that you use Signature Version 4. If you have an existing application that uses Signature Version 2, you do not have to update it to use Signature Version 4. However, some operations now require Signature Version 4. The documentation for operations that require version 4 indicate this requirement.
Additional resources
-
Amazon Web Services security credentials. This topic provides general information about the types of credentials used for accessing Amazon Web Services.
-
IAM best practices. This topic presents a list of suggestions for using the IAM service to help secure your Amazon Web Services resources.
-
Signing Amazon Web Services API requests. This set of topics walk you through the process of signing a request using an access key ID and secret access key.
Installing
To install this package, use the CLI of your favorite package manager:
npm install @aws-sdk/client-iamyarn add @aws-sdk/client-iampnpm add @aws-sdk/client-iam
Getting Started
Import
The AWS SDK is modulized by clients and commands.
To send a request, you only need to import the IAMClient and
the commands you need, for example ListGroupsCommand:
// ES5 example
const { IAMClient, ListGroupsCommand } = require("@aws-sdk/client-iam");
// ES6+ example
import { IAMClient, ListGroupsCommand } from "@aws-sdk/client-iam";
Usage
To send a request:
- Instantiate a client with configuration (e.g. credentials, region).
- See docs/CLIENTS for configuration details.
- See @aws-sdk/config for additional options.
- Instantiate a command with input parameters.
- Call the
sendoperation on the client, providing the command object as input.
const client = new IAMClient({ region: "REGION" });
const params = { /** input parameters */ };
const command = new ListGroupsCommand(params);
Async/await
We recommend using the await operator to wait for the promise returned by send operation as follows:
// async/await.
try {
const data = await client.send(command);
// process data.
} catch (error) {
// error handling.
} finally {
// finally.
}
Promises
You can also use Promise chaining.
client
.send(command)
.then((data) => {
// process data.
})
.catch((error) => {
// error handling.
})
.finally(() => {
// finally.
});
Aggregated client
The aggregated client class is exported from the same package, but without the "Client" suffix.
IAM extends IAMClient and additionally supports all operations, waiters, and paginators as methods.
This style may be familiar to you from the AWS SDK for JavaScript v2.
If you are bundling the AWS SDK, we recommend using only the bare-bones client (IAMClient).
More details are in the blog post on
modular packages in AWS SDK for JavaScript.
import { IAM } from "@aws-sdk/client-iam";
const client = new IAM({ region: "REGION" });
// async/await.
try {
const data = await client.listGroups(params);
// process data.
} catch (error) {
// error handling.
}
// Promises.
client
.listGroups(params)
.then((data) => {
// process data.
})
.catch((error) => {
// error handling.
});
// callbacks (not recommended).
client.listGroups(params, (err, data) => {
// process err and data.
});
Troubleshooting
When the service returns an exception, the error will include the exception information, as well as response metadata (e.g. request id).
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;
* }
*/
}
See also docs/ERROR_HANDLING.
Getting Help
Please use these community resources for getting help. We use GitHub issues for tracking bugs and feature requests, but have limited bandwidth to address them.
- Visit the Developer Guide or API Reference.
- Check out the blog posts tagged with
aws-sdk-json 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.
Contributing
This client code is generated automatically. Any modifications will be overwritten the next time the @aws-sdk/client-iam package is updated.
To contribute to client you can check our generate clients scripts.
License
This SDK is distributed under the Apache License, Version 2.0, see LICENSE for more information.
Client Commands (Operations List)
AcceptDelegationRequest
AcquireRole
AddClientIDToOpenIDConnectProvider
AddRoleToInstanceProfile
AddUserToGroup
AssociateDelegationRequest
AttachGroupPolicy
AttachRolePolicy
AttachUserPolicy
ChangePassword
CreateAccessKey
CreateAccountAlias
CreateDelegationRequest
CreateGroup
CreateInstanceProfile
CreateLoginProfile
CreateOpenIDConnectProvider
CreatePolicy
CreatePolicyVersion
CreateRole
CreateSAMLProvider
CreateServiceLinkedRole
CreateServiceSpecificCredential
CreateUser
CreateVirtualMFADevice
DeactivateMFADevice
DeleteAccessKey
DeleteAccountAlias
DeleteAccountPasswordPolicy
DeleteGroup
DeleteGroupPolicy
DeleteInstanceProfile
DeleteLoginProfile
DeleteOpenIDConnectProvider
DeletePolicy
DeletePolicyVersion
DeleteRole
DeleteRolePermissionsBoundary
DeleteRolePolicy
DeleteSAMLProvider
DeleteServerCertificate
DeleteServiceLinkedRole
DeleteServiceSpecificCredential
DeleteSigningCertificate
DeleteSSHPublicKey
DeleteUser
DeleteUserPermissionsBoundary
DeleteUserPolicy
DeleteVirtualMFADevice
DetachGroupPolicy
DetachRolePolicy
DetachUserPolicy
DisableOrganizationsRootCredentialsManagement
DisableOrganizationsRootSessions
DisableOutboundWebIdentityFederation
EnableMFADevice
EnableOrganizationsRootCredentialsManagement
EnableOrganizationsRootSessions
EnableOutboundWebIdentityFederation
GenerateCredentialReport
GenerateOrganizationsAccessReport
GenerateServiceLastAccessedDetails
GetAccessKeyLastUsed
GetAccountAuthorizationDetails
GetAccountPasswordPolicy
GetAccountProperties
GetAccountSummary
GetContextKeysForCustomPolicy
GetContextKeysForPrincipalPolicy
GetCredentialReport
GetDelegationRequest
GetGroup
GetGroupPolicy
GetHumanReadableSummary
GetInstanceProfile
GetLoginProfile
GetMFADevice
GetOpenIDConnectProvider
GetOrganizationsAccessReport
GetOutboundWebIdentityFederationInfo
GetPolicy
GetPolicyVersion
GetRole
GetRolePolicy
GetRoleTemplateVersion
GetSAMLProvider
GetServerCertificate
GetServiceLastAccessedDetails
GetServiceLastAccessedDetailsWithEntities
GetServiceLinkedRoleDeletionStatus
GetSSHPublicKey
GetUser
GetUserPolicy
ListAccessKeys
ListAccountAliases
ListAttachedGroupPolicies
ListAttachedRolePolicies
ListAttachedUserPolicies
ListDelegationRequests
ListEntitiesForPolicy
ListGroupPolicies
ListGroups
ListGroupsForUser
ListInstanceProfiles
ListInstanceProfilesForRole
ListInstanceProfileTags
ListMFADevices
ListMFADeviceTags
ListOpenIDConnectProviders
ListOpenIDConnectProviderTags
ListOrganizationsFeatures
ListPolicies
ListPoliciesGrantingServiceAccess
ListPolicyTags
ListPolicyVersions
ListRolePolicies
ListRoles
ListRoleTags
ListSAMLProviders
ListSAMLProviderTags
Command API Reference / Input / [Output](https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/Package/-aws-sdk-client-iam/Interface/ListSAMLPro