Skip to content
GitHubXDiscord

UserToGroupAddition

The UserToGroupAddition resource allows you to add IAM users to an IAM group, helping you manage permissions efficiently. For more details, refer to the official AWS documentation on AWS IAM UserToGroupAdditions.

Create a UserToGroupAddition with the required properties to add users to an IAM group.

import AWS from "alchemy/aws/control";
const userGroupAddition = await AWS.IAM.UserToGroupAddition("basicUserGroupAddition", {
GroupName: "Developers",
Users: ["alice", "bob"],
adopt: false // Default is false: This will fail if the resource already exists
});

Configure a UserToGroupAddition to automatically adopt existing resources if they are found.

const advancedUserGroupAddition = await AWS.IAM.UserToGroupAddition("advancedUserGroupAddition", {
GroupName: "Admins",
Users: ["charlie", "dave"],
adopt: true // This will adopt the existing resource if it already exists
});

Demonstrate adding multiple users to a group in a single operation.

const multiUserGroupAddition = await AWS.IAM.UserToGroupAddition("multiUserGroupAddition", {
GroupName: "Testers",
Users: ["eve", "frank", "grace"],
adopt: false // This will create a new resource
});

Show how to handle errors when trying to add users to a non-existing group.

try {
const errorUserGroupAddition = await AWS.IAM.UserToGroupAddition("errorUserGroupAddition", {
GroupName: "NonExistentGroup",
Users: ["heidi"],
adopt: false // This will throw an error if the group does not exist
});
} catch (error) {
console.error("Failed to add user to group:", error);
}