AWS IAM – EC2 Instance Won’t Recognize IAM Role

amazon ec2amazon-iamamazon-web-services

I'm trying to download ECR images on my EC2 instance without having to provide a credentials file. So I created a role with the policy AmazonEC2ContainerRegistryReadOnly and attached to my running instance. However, when I run aws ecr describe-repositories --region us-east-2, I get the following error:

Unable to locate credentials. You can configure credentials by running "aws configure".

I'm not sure if attaching the role to the instance is sufficient, but I already tried to restart the instance and it still doesn't work.

Here's some screenshots from the AWS Console that may help find the problem:

Best Answer

Reinstalling/upgrading AWS cli made it work.

The AWS cli was at version 1, after upgrading to version 2 it worked. Before that, I launched a new EC2 instance (Amazon Linux 2) with the attached role and it worked at AWS cli version 1, the exact same of the old machine.