To allow AWS Account B to be able to connect to Account A ECR image repository to push or pull images, you must create a policy that allows the secondary account to perform those API calls against the repository.
Follow this article in Youtube
-
- Ensure you have tagged the repositories in
Account A- Minimum of one repository with atleast the following tag,
- TagKey:
Team - TagValue:
Payments
Account Buser(ex:devusr2) with AWS CLI access- Note down
Account A & BIDs
- Ensure you have tagged the repositories in
-
The following policy allows user
devusr2to push and pull images to a repo which has the tagkeyTeamand its value asPayments. As this policy is assigned to only to the particular repo, the user will not get access to any other repo{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": [ "ecr:GetAuthorizationToken", "ecr:BatchCheckLayerAvailability", "ecr:GetDownloadUrlForLayer", "ecr:GetRepositoryPolicy", "ecr:DescribeRepositories", "ecr:ListImages", "ecr:DescribeImages", "ecr:BatchGetImage", "ecr:InitiateLayerUpload", "ecr:UploadLayerPart", "ecr:CompleteLayerUpload", "ecr:PutImage" ], "Condition": { "StringLike": { "aws:ResourceTag/Team": "Payments" } }, "Principal": { "AWS": [ "arn:aws:iam::YOUR-ACCOUNT-B-ID:user/devusr2" ] }, "Sid": "AllowCrossAccountPushAndPull" } ] } -
From the terminal with AWS CLI configured with
devusr2credentials as profiledev-accrun the following,- Get ECR Credentials
Change the
YOUR-ACCOUNT-A-ID&dev-acc$(aws ecr get-login --registry-ids YOUR-ACCOUNT-A-ID --no-include-email --region eu-central-1 --profile dev-acc) - Prepare Docker Image
Change the repo name
my-first-repo& imagemy-first-repo:latestto suit your environmentdocker tag my-first-repo:latest YOUR-ACCOUNT-A-ID.dkr.ecr.eu-central-1.amazonaws.com/my-first-repo:v1
- Push Image to Repo
Change the repo name
my-first-repoto suit your environmentdocker push YOUR-ACCOUNT-A-ID.dkr.ecr.eu-central-1.amazonaws.com/my-first-repo:v1
- Get ECR Credentials
Change the
Please open a GitHub issue.
Please open a GitHub issue. I do encourage you to contribute your changes and send me pull request.
