A Practical Guide to Managing AWS Organizations with the AWS CLI
Managing multiple AWS accounts can quickly become complex without a solid governance framework. AWS Organizations provides a centralized way to structure accounts, apply policies, and consolidate billing. The AWS CLI Organizations interface extends that power to the command line, enabling automation, repeatable setups, and faster workflows. This guide explains how to use the AWS CLI Organizations effectively, covering essential commands, best practices, and common scenarios you’re likely to encounter when operating a multi-account AWS environment.
Understanding the role of the AWS CLI Organizations
The AWS CLI Organizations toolset helps you perform routine tasks that would otherwise require clicking through the AWS Management Console. Whether you’re provisioning new accounts, organizing them into Organizational Units (OUs), or enforcing policy controls with service control policies (SCPs), the AWS CLI Organizations commands make it easier to script and audit your governance posture. For teams that manage multiple environments—dev, staging, production, and partners—the ability to script changes promotes consistency and reduces manual error. In short, AWS CLI Organizations is a powerful ally for teams pursuing scalable, compliant cloud management.
Prerequisites and setup
- Install and configure the AWS CLI (version 2+) on your workstation or CI/CD runner.
- Ensure you have the necessary IAM permissions in the master or delegated account. Typical permissions include organizations:* and specific actions for the operations you plan to run.
- Be aware that AWS Organizations is a global service; you won’t need to specify a region for most operations, though some commands may require an account-level context.
- Consider using named profiles or role assumed credentials if you need to operate from multiple AWS accounts or across accounts in the organization.
Core workflows with the AWS CLI Organizations
Below are common workflows you’ll likely implement with the AWS CLI Organizations. Each workflow includes a high-level description and representative commands you can adapt to your environment.
Initialize or verify your organization
You can describe the current organization to confirm its structure and features. If you’re starting from scratch, an organization is typically created when the first account is provisioned, but you can also explicitly initialize an organization with a feature set.
aws organizations describe-organization
# Optional: create an organization with a specified feature set
aws organizations create-organization --feature-set ALL
Structure your accounts with organizational units (OUs)
OUs help you group accounts by function, environment, or compliance requirements. Create OUs beneath a root and assign accounts to them as they are onboarded.
aws organizations create-organizational-unit --parent-id ou-aaaa-bbbb --name Engineering
aws organizations create-organizational-unit --parent-id ou-aaaa-bbbb --name Security
Provision new accounts and invite existing ones
New accounts can be created directly, or you can invite external accounts to join your organization. The create-account process can be asynchronous, so you’ll typically poll the status until it completes.
aws organizations create-account --email newuser@example.com --account-name DevOpsAccount --role-name OrganizationAccountAccessRole
aws organizations invite-account-to-organization --target Id=123456789012,Type=ACCOUNT --notes "Onboarding new project"
Handle invitations and handshakes
Invitations are tracked as handshakes. You may need to accept or decline, and you can inspect the status of outstanding handshakes.
aws organizations list-handshakes-for-organization
aws organizations accept-handshake --handshake-id h-abcdef12345
Move accounts within the hierarchy
As needs evolve, you can reorganize accounts by moving them between roots or OUs. This helps maintain logical separation for access control and cost attribution.
aws organizations move-account --account-id 111122223333 --source-parent-id ou-aaaa-bbbb --destination-parent-id ou-cccc-dddd
Apply and manage policies
Service Control Policies (SCPs) are central to governing what actions accounts can perform. You can list, create, attach, and detach policies, and enable or disable policy types at the organization level.
aws organizations list-policies --filter "SERVICE_CONTROL_POLICY"
aws organizations create-policy --name "RestrictS3" --description "SCP for restricted S3 actions" --type SERVICE_CONTROL_POLICY --content file://scp-content.json
aws organizations attach-policy --policy-id p-xxxxxxxx --target Id=ou-aaaa-bbbb
aws organizations detach-policy --policy-id p-xxxxxxxx --target Id=ou-aaaa-bbbb
aws organizations enable-policy-type --policy-type SERVICE_CONTROL_POLICY --root-id r-aaaaaaaa
Query lineage and accounts
Getting a clear picture of your accounts and their placement is essential for audits and planning. You can list accounts, roots, and the organizational units under a parent.
aws organizations list-accounts
aws organizations list-organizational-units-for-parent --parent-id ou-aaaa-bbbb
aws organizations list-parents --child-id 222233334444
Practical tips for productive use of AWS CLI Organizations
- Use profiles to segregate credentials for different accounts. This helps prevent accidental cross-account changes.
- Automate common onboarding tasks by scripting account creation, OU assignment, and policy application with a single script.
- Prefer idempotent operations where possible. For example, check for the existence of an OU or policy before attempting to create it to avoid errors during repeated runs.
- When dealing with asynchronous actions (like create-account and invite-account-to-organization), implement polling with a timeout to handle eventual completion gracefully.
- Audit and version-control your deployment scripts. Keep a changelog of structural changes to your AWS Organizations to support compliance and rollback.
Best practices for security and governance
- Adopt a least-privilege approach for IAM roles involved in AWS CLI Organizations operations. Limit who can create accounts, move accounts, or attach policies.
- Enable MFA and use cross-account roles to reduce long-lived credentials in automation scripts.
- Document your OU structure and policy expectations. A clear blueprint helps new team members and auditors understand governance rules quickly.
- Regularly review SCPs to ensure they reflect current security requirements and business needs. Remove outdated policies to minimize surface area.
- Keep a separate production directory of hosts or pipelines that are responsible for critical changes, with appropriate approval workflows before changes are applied at scale.
Common pitfalls and troubleshooting
- Misplaced entities: After creating an OU or moving an account, verify the new parent using describe or list commands to confirm the structure is as intended.
- Permission drift: If a script fails due to permission errors, review the IAM policy attached to the executing role and ensure it includes the proper organizations:* permissions and equivalent resource ARNs.
- Latency in propagation: Some changes, such as policy attachments, may take a moment to propagate across the organization. Implement a short delay or polling strategy between steps.
- Handling asynchronous account creation: The create-account flow returns a status that you must poll until completion. Plan for eventual consistency in automation.
Troubleshooting and observability tips
- Verify identity with a quick check:
aws sts get-caller-identityto confirm which account/role is executing the command. - Log and monitor CLI outputs. Redirect verbose logging to files in CI pipelines to aid debugging.
- Use structured output formats (JSON) and pipe results into tools like jq for programmatic processing.
Examples of real-world scenarios
Scenario 1: Onboard a new engineering account and place it under an Engineering OU with a baseline SCP applied. Scenario 2: Move a project account from Development to Production OU after readiness checks. Scenario 3: Centralize cost reporting by ensuring all accounts are included in consolidated billing and tagged consistently for reporting.
Conclusion
The AWS CLI Organizations interface enables proactive governance for a multi-account AWS environment. By combining the power of commands for creating organizations, structuring OUs, provisioning accounts, inviting existing ones, moving accounts, and applying SCPs, teams can automate repetitive tasks, reduce human error, and maintain clear control over security and costs. The key to success with AWS CLI Organizations is to start small, adopt idempotent patterns, and progressively automate your onboarding and governance workflows. With thoughtful setup and disciplined automation, you can harness the full potential of AWS Organizations while keeping operations predictable, auditable, and scalable. In practice, many teams find that the combination of AWS CLI and AWS Organizations—often referred to in industry circles as AWS CLI Organizations—delivers a reliable, repeatable path to cloud governance at scale.