Intake of ECR Image URI in Lambda through CloudFormation
Tags: cloudformation, lambda, ecr, ec2instance
Published: 2022-12-29 17:35:06

“ I have checked the documents to create a lambda function with input as image uri. So I found that it can be possible using cloudformation stack for automated purpose. 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 Intake of ecr image uri in lambda through cloudformation. Here I have created a ecr repository, IAM role, ec2 instance with push of image to ecr and cloudformation stack to create a lambda function.

#Architecture Overview
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/r18m0h3now2i8nii8veq.png)
The architecture diagram shows the overall deployment architecture with data flow, iam role, ec2 instance, ecr and cloudformation.

#Solution overview
The blog post consist of the following phases:
1. Create of Elastic Container Registry, IAM Role, EC2 Instance with Push of Image to ECR and also Create of Lambda through CloudFormation Stack
2. Output of Stack as Lambda Function with Image URI and Other Configuration for Lambda

##Phase 1: Create of Elastic Container Registry, IAM Role, EC2 Instance with Push of Image to ECR and also Create of Lambda through CloudFormation Stack

1. Open the elastic container registry console and create a private repository. Also push the image to ecr using ec2 instance. Create an IAM role and cloudformation stack. The cloudformation stack creates a lambda function with input as ecr image uri.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

##Phase 2: Output of Stack as Lambda Function with Image URI and Other Configuration for Lambda

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

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

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

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

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

#Clean-up
Delete ECR, Iam Role, EC2 Instance, S3 Bucket and Cloudformation Stack.

#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 EC2 = $0.02

Cost of S3 = $0.0

Cost of Lambda = $0.0

Total Cost = $0.020089

#Summary
In this post, I showed “Intake of ecr image uri in lambda through cloudformation”.

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).

For more details on AWS CloudFormation, Checkout Get started AWS CloudFormation, open the [AWS CloudFormation console](https://us-east-1.console.aws.amazon.com/cloudformation/home?region=us-east-1#/). To learn more, read the [AWS CloudFormation documentation](https://docs.aws.amazon.com/cloudformation/?id=docs_gateway).

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)