AWS SDK for JavaScript IAM Client provides comprehensive Identity and Access Management functionality for Node.js, Browser and React Native applications. It enables programmatic management of AWS users, groups, roles, policies, and access credentials with over 165 IAM operations.
npm install @aws-sdk/client-iamimport { IAMClient, CreateUserCommand } from "@aws-sdk/client-iam";For CommonJS:
const { IAMClient, CreateUserCommand } = require("@aws-sdk/client-iam");import { IAMClient, CreateUserCommand, ListUsersCommand } from "@aws-sdk/client-iam";
// Initialize client
const client = new IAMClient({ region: "us-east-1" });
// Create a user
const createUserCommand = new CreateUserCommand({
UserName: "test-user",
Path: "/users/"
});
try {
const createResult = await client.send(createUserCommand);
console.log("User created:", createResult.User?.UserName);
} catch (error) {
console.error("Error creating user:", error);
}
// List users
const listUsersCommand = new ListUsersCommand({});
const listResult = await client.send(listUsersCommand);
console.log("Users:", listResult.Users?.map(u => u.UserName));The AWS IAM Client is built around several key components:
Core client initialization, configuration options, and authentication setup for all IAM operations.
interface IAMClientConfig {
region?: string;
credentials?: AwsCredentialIdentityProvider;
endpoint?: string;
maxAttempts?: number;
}Comprehensive user lifecycle management including creation, deletion, modification, and access configuration.
interface CreateUserCommandInput {
UserName: string;
Path?: string;
PermissionsBoundary?: string;
Tags?: Tag[];
}
interface User {
UserName: string;
UserId: string;
Arn: string;
Path: string;
CreateDate: Date;
PasswordLastUsed?: Date;
PermissionsBoundary?: AttachedPermissionsBoundary;
Tags?: Tag[];
}Management of IAM groups and roles for organizing users and defining assumable identities.
interface CreateGroupCommandInput {
GroupName: string;
Path?: string;
}
interface CreateRoleCommandInput {
RoleName: string;
AssumeRolePolicyDocument: string;
Path?: string;
Description?: string;
MaxSessionDuration?: number;
PermissionsBoundary?: string;
Tags?: Tag[];
}Complete policy lifecycle management including managed policies, inline policies, and policy attachments.
interface CreatePolicyCommandInput {
PolicyName: string;
PolicyDocument: string;
Path?: string;
Description?: string;
Tags?: Tag[];
}
interface Policy {
PolicyName?: string;
PolicyId?: string;
Arn?: string;
Path?: string;
DefaultVersionId?: string;
AttachmentCount?: number;
PermissionsBoundaryUsageCount?: number;
IsAttachable?: boolean;
Description?: string;
CreateDate?: Date;
UpdateDate?: Date;
Tags?: Tag[];
}Management of access keys, signing certificates, SSH keys, and other security credentials.
interface CreateAccessKeyCommandInput {
UserName?: string;
}
interface AccessKey {
UserName: string;
AccessKeyId: string;
Status: StatusType;
SecretAccessKey: string;
CreateDate?: Date;
}Multi-Factor Authentication device management for securing IAM user access with TOTP and hardware tokens.
interface CreateVirtualMFADeviceCommandInput {
VirtualMFADeviceName: string;
Path?: string;
}
interface VirtualMFADevice {
SerialNumber: string;
Base32StringSeed?: Uint8Array;
QRCodePNG?: Uint8Array;
User?: User;
EnableDate?: Date;
}Identity provider management for federated authentication using SAML 2.0 and OpenID Connect protocols.
interface CreateSAMLProviderCommandInput {
Name: string;
SAMLMetadataDocument: string;
Tags?: Tag[];
}
interface CreateOpenIDConnectProviderCommandInput {
Url: string;
ClientIDList?: string[];
ThumbprintList?: string[];
Tags?: Tag[];
}Instance profile management for providing AWS credentials to EC2 instances and compute services through IAM roles.
interface CreateInstanceProfileCommandInput {
InstanceProfileName: string;
Path?: string;
Tags?: Tag[];
}
interface InstanceProfile {
Path: string;
InstanceProfileName: string;
InstanceProfileId: string;
Arn: string;
CreateDate: Date;
Roles: Role[];
}AWS account-level IAM settings including account aliases, password policies, and security preferences.
interface CreateAccountAliasCommandInput {
AccountAlias: string;
}
interface UpdateAccountPasswordPolicyCommandInput {
MinimumPasswordLength?: number;
RequireSymbols?: boolean;
RequireNumbers?: boolean;
RequireUppercaseCharacters?: boolean;
RequireLowercaseCharacters?: boolean;
AllowUsersToChangePassword?: boolean;
MaxPasswordAge?: number;
PasswordReusePrevention?: number;
HardExpiry?: boolean;
}interface Tag {
Key: string;
Value: string;
}
enum StatusType {
Active = "Active",
Inactive = "Inactive",
Expired = "Expired"
}
interface AttachedPermissionsBoundary {
PermissionsBoundaryType?: PermissionsBoundaryAttachmentType;
PermissionsBoundaryArn?: string;
}
enum PermissionsBoundaryAttachmentType {
PermissionsBoundaryPolicy = "PermissionsBoundaryPolicy"
}
interface IAMServiceException extends Error {
name: string;
message: string;
$fault: "client" | "server";
$metadata: ResponseMetadata;
}
interface ResponseMetadata {
httpStatusCode?: number;
requestId?: string;
extendedRequestId?: string;
cfId?: string;
attempts?: number;
totalRetryDelay?: number;
}