When working with AWS EC2 instances, securely managing permissions is crucial. Instead of manually configuring AWS credentials (which is insecure), we use IAM roles to grant access to AWS services. This article walks through setting up IAM roles for an EC2 instance and why it’s the best practice.
To begin, connect to your EC2 instance using either:
For simplicity, EC2 Instance Connect is used in this example.
Expected output: ec2-user
```
whoami
```
When running AWS CLI commands (e.g., listing IAM users):
aws iam list-users
You might see an error:
"Unable to locate credentials. You can configure credentials by running 'aws configure'."
AWS suggests configuring credentials using: