How would you configure the AWS CLI to work with multiple AWS accounts, and what precautions should you take when doing so?
I would configure separate AWS CLI profiles using:
aws configure --profile dev
aws configure --profile prod
and use them with the --profile option or the AWS_PROFILE environment variable.
aws sts get-caller-identity --profile prod
Key precautions include:
- Using separate named profiles for each account.
- Verifying the account ID before running administrative commands.
- Following the principle of least privilege.
- Enabling MFA for sensitive accounts.
- Using IAM roles instead of long-term access keys whenever possible.
- Rotating credentials regularly.
- Avoiding the use of the default profile for production environments.
These practices improve security and help prevent accidental changes to production resources.