Cross Account Access of Image URI in Lambda with ECR Permissions
Tags: aws, ecr, lambda
Published: 2023-11-11 11:37:08

“ I have checked the documents to create a lambda function with input as image uri of cross account. So I found that it can be possible to give permissions on ecr repo of cross account. Pricing of ecr is based on gb per month.”

Amazon Elastic Container Registry is a fully managed container registry offering high performance hosting so you can reliably deploy application images and artifacts anywhere. It's easy to store, share and deploy your container software anywhere. Amazon ECR is a managed service that helps you to optimize your Amazon ec2 instances. ECR makes it easy to manage your Amazon ECS clusters and to use Amazon ECS resources more effectively. ECR helps you to automate the process of managing and deploying applications on Amazon ECS.

In this post, you will get to know how to cross account access of image uri in lambda with ecr permissions. Here I have created a ecr repository, push of image to ecr and create a lambda function with input as image uri.

#Architecture Overview
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6g8a544ycslr3z1uhme6.jpg)
The architecture diagram shows the overall deployment architecture with data flow, ecr and lambda.

#Solution overview
The blog post consist of the following phases:
1. Create of Elastic Container Registry and Push of Image to ECR
2. Add the Permissions in ECR Repo with Required Parameters
3. Create of Lambda Function with Container Image URI

##Phase 1: Create of Elastic Container Registry and Push of Image to ECR
1. Open the elastic container registry console and create a private repository. Also push the image to ecr.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0x28dr72nench3d4zj94.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5jtw1y1dq7ayl5lw4vhj.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/x5m7rc3lexzzsmmm3rkk.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0p9bb9vxr49egau28n0b.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0270bsr32p37wtf6u3mu.png)

##Phase 2: Add the Permissions in ECR Repo with Required Parameters 
1. Open the elastic container image and goto permission tab. Add the permissions in ecr as per required cross account access.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/j12lrym5avd2nuwp4vd8.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2czfvxn6tvr6m027ikgd.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hcaxyeeqfat905xa7gt3.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1ahyfza44zrbzrd80hvy.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/yazbp60f8gcavdcjnv88.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/nguay84xy9qwkr2grfp1.png)

##Phase 3: Create of Lambda Function with Container Image URI
1. Open the lambda console and create a lambda function with input as ecr image uri.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ugqsyiha6hhe3huexp8z.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jch6etusb1klofd52x3v.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qmdvtrair4rtk7eeuaf3.png)

#Clean-up
Delete ECR and Lambda.

#Pricing
I review the pricing and estimated cost of this example. 

Cost of Data Transfer = $0.0

Cost of EC2 Container Registry (ECR) = $0.000089

Cost of Lambda = $0.0

Total Cost = $0.000089

#Summary
In this post, I showed “Cross account access of image uri in lambda with ecr permissions”.

For more details on Amazon Elastic Container Registry, Checkout Get started Amazon Elastic Container Registry, open the [Amazon Elastic Container Registry console](https://us-east-1.console.aws.amazon.com/ecr/home?region=us-east-1). To learn more, read the [Amazon Elastic Container Registry documentation](https://docs.aws.amazon.com/ecr/?icmpid=docs_homepage_containers).

Thanks for reading!

Connect with me: [Linkedin](https://www.linkedin.com/in/gargee-bhatnagar-6b7223114)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/38sdi4nsp89fnui8h7dk.png)