AWS, Cloud Computing

4 Mins Read

Build and Deploy Workloads using Elastic Container Registry

Overview

AWS provides many ways to deploy lambda functions, and in this blog, we are going to explore one of the ways to create lambda functions in AWS. We will create a lambda function using container images. We are going to create custom images using lambda python image from the ECR gallery provided by AWS. We will push the custom image to AWS ECR (Elastic Container registry) repository. Sometimes we need an underlying environment to run our application and for that AWS provide this feature. We can install any dependencies in the image and make it ready to run our application smoothly.

Introduction to Lambda

Lambda: It is a serverless computing service provided by AWS. Lambda is an event driven service.

In lambda we do not have to worry about underlying infrastructure it will be taken care by AWS as the name given serverless. We only need to write code and deploy it on lambda.

AWS provides three ways to create a lambda function:

Author from Scratch: This way of creating a lambda function will start with a simple hello world message.

Use a blueprint: This way of creating a lambda function give you a sample code that shows how to use lambda with AWS services or any popular third-party application.

It also includes sample code and function configuration presets for Node.js and Python runtimes.

Container Image: This way of creating a lambda function will give you the option to use your images with desired dependencies installed. Lambda also provides a set of open-source base images to create your container images.

For more details on lambda: What is AWS Lambda? – AWS Lambda (amazon.com)

  • Cloud Migration
  • Devops
  • AIML & IoT
Know More

Elastic Container Registry (ECR)

It is a private registry provided by Amazon as part of AWS services and it is used for managed container images.

Users can pull, push and manage images using the Docker command or any other preferred client. It is a secure and reliable registry for Docker and OCI images. It also provides resource-based permission using AWS IAM.

The client needs to authenticate to ECR as an AWS user to pull or push images in ECR.

For more on ECR visit: What is Amazon Elastic Container Registry? – Amazon ECR

Step-by-Step Guide to Create Docker Image

To create a docker image we need to launch a Linux EC2 or Linux local machine and provide ECR full access to an EC2 instance.

Note: Install docker in the machine and also the latest AWS CLI to configure and authenticate with ECR.

 Step 1: We need to create three files in ec2 named Dockerfile, requirement.txt, and app.py.

  • py contains a python script to print the “Hello Lambda” message on Lambda.
  • txt file contains all dependencies required to run app.py.

Dockerfile will contain the base image and it will execute the app.py file and also requirement.txt

Step1

App.py

Step1b

Requirement.txt

Step1c

Dockerfile

Step1d

Step 2: We can take the base image from the ECR gallery, where users created public images hosted on AWS ECR.

ECR gallery: https://gallery.ecr.aws/

Step2

Step 3: Create an ECR private repository and click on “view push commands” to log in and authenticate with AWS ECR so that we can push the image into the repository.

Step3

Step 4: Run the above commands to build the docker file and push the image in the ECR repository with the latest tag.

Creating Lambda Container Using ECR Image

Now we have our image in the ECR repository, we can use it to create a lambda function and test it.

Create a Lambda function in AWS from the AWS Lambda console.

https://ap-northeast-1.console.aws.amazon.com/lambda/

Use Container Image as the base image

Step4

Note: Choose runtime as per your docker image.

  • Click on browse to select the image present in the ECR repository
  • Click on the latest image and click the select image.

Step4b

  • Leave everything default and create a function.
  • After creating the function, we can test it using the default event.

Step4c

Conclusion

In this article, we get to know about AWS ECR and how can we create container images using AWS Lambda. It allows developers to build and deploy larger workloads with small and sizeable dependencies. We can create many images and push them to ECR and can use it according to need. We can also make a public repository and make your images public to other users. Lambda also provides open-source base images, and we can use those base images to create our desired image with the required dependencies installed. Developers can use such environments to test their applications. AWS ECR gallery has many numbers of images already published by other users; we can use that too.

ECR Gallery: https://gallery.ecr.aws/

Get your new hires billable within 1-60 days. Experience our Capability Development Framework today.

  • Cloud Training
  • Customized Training
  • Experiential Learning
Read More

About CloudThat

CloudThat is also the official AWS (Amazon Web Services) Advanced Consulting Partner and Training partner and Microsoft gold partner, helping people develop knowledge of the cloud and help their businesses aim for higher goals using best in industry cloud computing practices and expertise. We are on a mission to build a robust cloud computing ecosystem by disseminating knowledge on technological intricacies within the cloud space. Our blogs, webinars, case studies, and white papers enable all the stakeholders in the cloud computing sphere.

Drop a query if you have any questions regarding Amazon ECR and I will get back to you quickly.

To get started, go through our Consultancy page and Managed Services Package that is CloudThat’s offerings.

FAQs

1. Is there any limit in creating images in ECR?

ANS: – We can create many numbers of repositories and can push any number of images to them.

2. Can we also create a public repository in ECR?

ANS: – Yes, we can create both public as well as a private repository in ECR.

WRITTEN BY Kishan Singh

Kishan Singh works as Research Associate (Infra, Migration, and Security) at CloudThat. He is Azure Administrator and Azure Developer certified. He is highly organized and an excellent communicator with good experience in Cyber Security and Cloud technologies. He works with a positive attitude and has a good problem-solving approach.

Share

Comments

  1. sruti samatkar

    Jan 4, 2023

    Reply

    Good read

    • Kishan Singh

      Jan 4, 2023

      Reply

      Thank You!

  2. Komal

    Jan 4, 2023

    Reply

    Informative

    • Kishan Singh

      Jan 4, 2023

      Reply

      Thank You!

    Click to Comment

Get The Most Out Of Us

Our support doesn't end here. We have monthly newsletters, study guides, practice questions, and more to assist you in upgrading your cloud career. Subscribe to get them all!