Here is the complete answer, after I completed all the steps - I was able to use ECR
The error can have 2 values:
1) You are not authorized because the ECR policy is not tied to your user
2) You are not authorized because you are using 2FA, and using cli is not safe unless you set a temporary session token
Here is a list of all the steps to gain access (including 2FA processing)
- First of all, you must create a policy that gives you access to the GetAuthorizationToken action in the ECR.
- Attach this policy to either the user or the group (IMHO are always better for groups / roles, my voice is for roles, for example, DevOps)
- Verify that AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY are set in your environment. I recommend using the aws folder with shared credentials and profiles.
If you have 2FA enabled
- You need to generate a session token using this command
aws sts get-session-token --serial-number arn-of-the-mfa-device --token-code code-from-token . arn-of-the-mfa-device can be found in your profile, section 2FA. Token generated token from the device. - Update aws credentials with
AccessKeyId , SecretAccessKey and SessionToken . AWS recommends using a cron job to update the token, which means that if you do this, you are testing something, most likely 2FA is not enabled in your prod resources. You can increase the session by providing --duration-seconds , but only up to 36 hours. A good explanation can be found at authenticate-mfa-cli
That should do the job.
source share