DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

The software you build is only as secure as the code that powers it. Learn how malicious code creeps into your software supply chain.

Apache Cassandra combines the benefits of major NoSQL databases to support data management needs not covered by traditional RDBMS vendors.

Generative AI has transformed nearly every industry. How can you leverage GenAI to improve your productivity and efficiency?

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workloads.

Related

  • Building Scalable Data Lake Using AWS
  • Building a Scalable ML Pipeline and API in AWS
  • Breaking AWS Lambda: Chaos Engineering for Serverless Devs
  • AWS Step Functions Local: Mocking Services, HTTP Endpoints Limitations

Trending

  • Intro to RAG: Foundations of Retrieval Augmented Generation, Part 1
  • How Can Developers Drive Innovation by Combining IoT and AI?
  • Customer 360: Fraud Detection in Fintech With PySpark and ML
  • Understanding IEEE 802.11(Wi-Fi) Encryption and Authentication: Write Your Own Custom Packet Sniffer
  1. DZone
  2. Software Design and Architecture
  3. Cloud Architecture
  4. Deploy ECR-Based AWS Lambda

Deploy ECR-Based AWS Lambda

Let's see how to deploy an ECR image-based Lambda onto the AWS Console.

By 
Tushar Mathur user avatar
Tushar Mathur
·
Jul. 25, 22 · Tutorial
Likes (2)
Comment
Save
Tweet
Share
5.6K Views

Join the DZone community and get the full member experience.

Join For Free

AWS Lambda is one of the most popular FaaS (function as a service) platforms out there. Its serverless capabilities and low cost per execution make it a go-to service for developers globally. Lambda supports multiple framework applications and multiple deployment models, and it helps developers customize their networking, permissions, and concurrency configurations.

When we talk about multiple deployment models in Lambda, container image-based deployments are one of the most popular ways to deploy their application on Lambda packaged into an image. With the benefits of containerization, developers can easily deploy applications by providing application dependencies in their application's Docker image instead of mentioning their dependencies and configuration separately in their Lambda. 

AWS also provides the ECR (Elastic Container Registry) service. Developers store their images in their image repository, which helps them by providing version-based deployment. The only cost you pay is for image storage and data transfer activity. 

Let's see how one can deploy an ECR image-based Lambda onto the AWS Console. (If you already have an image repository over ECR, then you can skip the first steps on creating one.)

Create ECR Image Repository and Add Image to It

 1. Open AWS Console and navigate to ECR service.

 2. Click on "Create repository" and fill out the required parameters like repository name and repository type (whether public or private), and based on your requirements, you can opt for image scan and encryption configuration.

3. Once your repository is created, then go to your repository and click on "View push commands."

4. After clicking on it, you will have a prompt stating the ways in which you can push your image to the repository.

5. Please follow the instruction provided into the prompt and push your image to the repository.

6. Once you push your image to the repository, it should look like this:

Create Lambda With ECR Image Using AWS CLI

 1. Please make sure you have AWS CLI installed into your system. You can verify it by typing aws --version.

2. You also need to configure your AWS credentials using aws configure --profile profile_name. Please add respective ID and secret of your credentials when asked.

 3. You can verify whether you correctly configured your user or not using aws sts get-caller-identity --profile profile_name. If you get the correct output, then you are good to go. Just make sure your user that is configured into your AWS CLI has the right permissions to create a Lambda and has sufficient ECR permissions to pull an image from it.

 4. Now, let's jump to creating a JSON file which will consist of Lambda's configuration. 

 
{
  "FunctionName": "ecrtestlambda",
  "PackageType": "Image",
  "Description": "ECR Testing Lambda",
  "Role": "arn:aws:iam::************:role/DemoRoleForEC2",
  "Code": {
      "ImageUri": "************.dkr.ecr.ap-south-1.amazonaws.com/tushar-batchjob-1609:latest"
  }
}

Let's understand this JSON file.

FunctionName represents the name of the function that you want to create.

PackageType represents the code package type. We have already mentioned Image, which means that the code is packaged as an image.

Description represents the function description, if you have any.

Role represents the IAM role that you want to configure to your Lambda, which helps in performing actions on behalf of your Lambda.

Code represents information on the source code location, whether a zip file or image URI.

Note: In this case we will use the ImageUri option as we are using an ECR image-based deployment. You can copy the image URI from your image repository section by clicking on the "Copy URI" link:

5. Save this JSON file into your known location.

6. Now let's go ahead with the creation of a Lambda. Use the below command to create a Lambda with respective ECR configuration.

 
aws lambda create-function --cli-input-json fileb://C:\Users\test\Downloads\lambdaconfig.json --profile profile_name --region region_name

Here you just need to mention your file path after the fileb:// section. As you can see, we have provided a --cli-input-json parameter which states that we are using the JSON file as input configuration for the Lambda.

Also, you need to mention the profile name (make sure it has required access to create Lambda and access ECR image, as explained before) and region name, as per your requirements.

7. With proper access and correct configuration, you should be able to create an ECR-based Lambda.

Important Notes

1. Your configured user on AWS CLI should have proper access to create Lambda and access to ECR images.

2. Your image should not be corrupted.

I hope this article was helpful to you in some way, and I thank you for taking the time to read it and go through it. Do like the post if you think it was helpful to you. 

Cheers!

AWS AWS Lambda

Opinions expressed by DZone contributors are their own.

Related

  • Building Scalable Data Lake Using AWS
  • Building a Scalable ML Pipeline and API in AWS
  • Breaking AWS Lambda: Chaos Engineering for Serverless Devs
  • AWS Step Functions Local: Mocking Services, HTTP Endpoints Limitations

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!