Sunday, November 30, 2025

Pushing Docker App to AWS ECR for Lambda Deployment Utilizing AWS CLI




Pushing Docker App to AWS ECR for Lambda Deployment Utilizing AWS CLI

On this tutorial, you’ll discover ways to arrange AWS CLI for safe authentication, construct a Docker picture on your FastAPI AI inference app, and push it to AWS Elastic Container Registry (ECR). This ensures your containerized utility is prepared for seamless deployment to AWS Lambda, enabling scalable, serverless AI inference.

This lesson is the final of a 4-part collection on AWS Lambda:

  1. Introduction to Serverless Mannequin Deployment with AWS Lambda and ONNX
  2. Changing a PyTorch Mannequin to ONNX for FastAPI (Docker) Deployment
  3. FastAPI Docker Deployment: Getting ready ONNX AI Fashions for AWS Lambda
  4. Pushing Docker App to AWS ECR for Lambda Deployment Utilizing AWS CLI (this tutorial)

To discover ways to arrange AWS CLI, containerize your FastAPI AI app, and push it to AWS ECR for Lambda deployment, simply hold studying.

On the lookout for the supply code to this submit?

Leap Proper To The Downloads Part

Setting Up AWS CLI and Pushing the FastAPI AI App to AWS ECR for Lambda Deployment

Within the earlier lesson, we containerized our FastAPI AI inference app and examined it regionally utilizing Docker, guaranteeing constant execution throughout environments. Since AWS Lambda helps container-based deployment, this step was important for our serverless setup.

Key Takeaways from Lesson 3:

  • Constructed a FastAPI-based AI inference server that hundreds an ONNX mannequin for picture classification.
  • Ran the app regionally with Uvicorn to validate performance.
  • Created a Dockerfile to bundle the FastAPI app right into a container.
  • Constructed and examined the Docker container, guaranteeing the app runs easily inside it.
  • Verified the FastAPI inference endpoint utilizing Postman, cURL, and browser requests.

By the top of Lesson 3, we had a totally purposeful FastAPI AI inference server operating inside a Docker container.

Earlier than deploying it to AWS Lambda, we have to retailer the container in AWS Elastic Container Registry (ECR) so Lambda can entry it.


What Is AWS CLI and Why Do We Want It?

The AWS Command Line Interface (AWS CLI) is a robust device that permits builders to work together with AWS companies immediately from the command line relatively than the AWS Administration Console. It gives a unified command-line device for effectively managing AWS sources.

AWS CLI helps you execute instructions for AWS companies like Lambda, ECR, S3, IAM, EC2, API Gateway, and extra with out manually navigating the AWS Console.

AWS CLI is particularly helpful for:

  • Automation: Automate repetitive AWS duties utilizing scripts.
  • Quicker Execution: Working CLI instructions is faster than clicking by means of the AWS UI.
  • Infrastructure as Code (IaC): The AWS CLI integrates with instruments (e.g., Terraform and AWS CloudFormation).
  • Distant Server Administration: Run instructions from any system with out opening the AWS Administration Console.

Why Do We Want AWS CLI in This Deployment?

On this lesson, we’ll use AWS CLI to:

  • Authenticate with AWS by configuring credentials and permissions.
  • Create a personal AWS Elastic Container Registry (ECR) to retailer our Docker picture.
  • Push the FastAPI AI inference app’s Docker picture to AWS ECR so AWS Lambda can entry it.
  • Confirm our saved Docker photographs inside ECR with out utilizing the AWS Console.
  • Work together with AWS Lambda later for deployment and testing.

Utilizing AWS CLI will simplify our deployment course of, making it extra environment friendly and repeatable. As an alternative of manually establishing AWS companies by means of the console, we will execute a couple of instructions to attain the identical outcomes.

Determine 1 outlines the end-to-end AWS CLI workflow for deploying our FastAPI utility to AWS ECR.

Determine 1: AWS CLI workflow for constructing and pushing the FastAPI Docker picture to AWS ECR (supply: picture by the writer)

Why Is AWS CLI Higher Than Utilizing the AWS Console?

Desk 1: Evaluating AWS CLI and AWS Console for managing AWS companies (supply: by the writer)

What Is ECR (Elastic Container Registry)?

AWS Elastic Container Registry (ECR) is a totally managed container picture registry. It permits builders to retailer, handle, and deploy Docker container photographs with out sustaining their very own container repositories. ECR integrates seamlessly with AWS companies similar to AWS Lambda, ECS (Elastic Container Service), and EKS (Elastic Kubernetes Service), making it straightforward to deploy containerized purposes within the AWS cloud.

With AWS ECR, you get:

  • Scalability: Routinely scales along with your container picture storage wants.
  • Safety: Provides fine-grained entry management with AWS IAM (Id and Entry Administration).
  • Reliability: Extremely accessible storage for container photographs throughout AWS areas.
  • Deep AWS Integration: Works with AWS companies like Lambda, ECS, and CodeBuild.

As an alternative of utilizing public registries (e.g., Docker Hub), AWS ECR gives a safe, non-public approach to handle container photographs inside AWS, decreasing exterior dependencies and bettering deployment safety.


Public vs. Personal Repositories in AWS ECR

AWS ECR helps two sorts of repositories: Public and Personal. Understanding their variations helps in selecting the best possibility on your deployment.

Desk 2: Comparability of public vs. non-public ECR repositories for FastAPI AI mannequin deployment (supply: by the writer)

Since public repositories are accessible to anybody, they’re greatest suited to open-source tasks or sharing container photographs with the developer neighborhood. Nevertheless, AWS Lambda doesn’t assist public repositories, which means non-public ECR repositories are obligatory for Lambda-based deployments.

For safe, production-ready AI inference, non-public repositories guarantee managed entry, safety, and seamless integration with AWS Lambda.

Determine 2: AWS ECR Personal Repository for FastAPI AI Inference App (supply: by the writer)

Why Are We Utilizing a Personal AWS ECR Repository?

On this tutorial, we’re utilizing a non-public ECR repository as a result of:

  • Obligatory for AWS Lambda: Lambda solely helps non-public ECR repositories, not public ones.
  • Safety and Entry Management: Solely authenticated AWS customers (through IAM roles) can push/pull photographs.
  • Restricted Entry: The AI mannequin shouldn’t be made publicly accessible.
  • Seamless Integration with AWS Lambda: Ensures our FastAPI AI inference mannequin might be deployed securely.
  • Compliance and Privateness: Important for enterprise purposes that require strict knowledge safety.

Since AWS Lambda doesn’t assist public ECR repositories, we should use a personal repository to retailer and deploy our containerized AI mannequin. This ensures safe entry, prevents unauthorized use, and integrates easily with AWS Lambda.


What’s Subsequent? Setting Up AWS CLI and Pushing the FastAPI AI App to AWS ECR for Lambda Deployment

Now that we perceive AWS CLI, its position in managing AWS companies, AWS ECR for storing container photographs, and why we use a personal repository for safety, it’s time to arrange AWS CLI and push our FastAPI AI app to AWS ECR.

Within the upcoming sections, we’ll:

  • Set up AWS CLI and arrange authentication with AWS credentials.
  • Confirm AWS CLI entry to make sure it may possibly work together with AWS companies.
  • Create a personal ECR repository to securely retailer our FastAPI container picture.
  • Construct and push the FastAPI AI app Docker picture to AWS ECR for Lambda deployment.

As soon as our containerized AI mannequin is efficiently saved in ECR, we might be able to arrange and deploy it to AWS Lambda within the subsequent part. Let’s start!


Configuring Your Improvement Surroundings

To comply with this information, you want Docker put in in your machine. Since we’re deploying a containerized AI inference mannequin, Docker might be used to construct, check, and push our picture to AWS Elastic Container Registry (ECR).

Obtain and set up Docker from:

After set up, confirm that Docker is operating by executing:

$ docker --version

It is best to see an output just like:

Docker model 25.0.1, construct 29cf629

In the event you’re new to Docker, check with our information on Getting Began with Docker.


Want Assist Configuring Your Improvement Surroundings?

Having bother configuring your improvement setting? Need entry to pre-configured Jupyter Notebooks operating on Google Colab? You’ll want to be a part of PyImageSearch College — you may be up and operating with this tutorial in a matter of minutes.

All that mentioned, are you:

  • Quick on time?
  • Studying in your employer’s administratively locked system?
  • Eager to skip the effort of preventing with the command line, bundle managers, and digital environments?
  • Able to run the code instantly in your Home windows, macOS, or Linux system?

Then be a part of PyImageSearch College immediately!

Achieve entry to Jupyter Notebooks for this tutorial and different PyImageSearch guides pre-configured to run on Google Colab’s ecosystem proper in your net browser! No set up required.

And better of all, these Jupyter Notebooks will run on Home windows, macOS, and Linux!


Venture Construction

Earlier than pushing our Docker picture to AWS ECR, let’s rapidly overview which recordsdata from our venture are literally used on this lesson. The listing construction under is shared throughout all classes, however just a few elements are required at this stage:

$ tree . -L 1
resnet-aws-serverless-classifier/
├── src/
│   ├── server.py            # Included in Docker picture – FastAPI inference server
│   ├── convert.py           # Not used right here – utilized in Lesson 2 for ONNX export
│   ├── onnxt.py             # Not used – ONNX Runtime CLI examples (later classes)
│   ├── onnx_local.py        # Not used – Native ONNX runtime checks (later)
│   └── __init__.py
├── fashions/
│   ├── resnetv2_50.onnx     # Used – ONNX mannequin loaded contained in the Docker picture
│   └── imagenet_classes.txt # Used – Label file for mannequin predictions
├── knowledge/
│   ├── cat.jpg / canine.jpg    # Elective – Used to check the API regionally earlier than pushing to ECR
│   ├── cat_base64.txt       # Not used – for Lambda JSON payloads (later)
│   ├── occasion.json / payload.json / response.json  # Not used – Lambda checks (later)
├── checks/                   # Not used on this lesson
├── frontend/                # Not used – utilized in Classes 7–8
├── Dockerfile               # Not used – Lambda container construct (subsequent lesson)
├── Dockerfile.native         # Used – builds the native FastAPI Docker picture
├── docker-compose.native.yml # Not used but
├── dev.sh                   # Elective helper script
├── necessities.txt         # Used – put in inside Docker picture
├── requirements-local.txt   # Used – FastAPI/Docker improvement dependencies
├── .dockerignore
├── .gitignore
└── README.md

We solely use:

  • src/server.py
  • fashions/resnetv2_50.onnx
  • fashions/imagenet_classes.txt
  • knowledge/cat.jpg, knowledge/canine.jpg (optionally available)
  • Dockerfile.native
  • necessities.txt, requirements-local.txt

The remaining recordsdata belong to future classes (Lambda testing, ONNX benchmarking, Subsequent.js UI, and many others.).


AWS CLI Set up and Setup

Earlier than deploying our AI mannequin to AWS Lambda, we have to configure the AWS Command Line Interface (CLI) to authenticate requests to AWS companies (e.g., ECR and Lambda). The AWS CLI permits us to work together with AWS companies immediately from the terminal, making duties like managing Lambda features, pushing Docker photographs to AWS ECR, and establishing API Gateway a lot simpler.

On this part, we’ll:

  • Set up AWS CLI in your native machine.
  • Arrange AWS credentials to authenticate with AWS companies.
  • Confirm entry to AWS Lambda, ECR, and different required companies.

Step 1: Set up AWS CLI

The AWS CLI is obtainable for Home windows, macOS, and Linux. Observe the official AWS CLI set up information primarily based in your OS.

Alternatively, you’ll be able to set up it immediately utilizing the command line:

macOS:

curl "https://awscli.amazonaws.com/AWSCLIV2.pkg" -o "AWSCLIV2.pkg"
sudo installer -pkg AWSCLIV2.pkg -target /

Linux:

curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
unzip awscliv2.zip
sudo ./aws/set up
Determine 3: Putting in the AWS CLI v2 on macOS utilizing the official installer bundle (supply: picture by the writer)

After set up, confirm the AWS CLI model:

Determine 4: Verifying the AWS CLI set up with the aws --version command (supply: picture by the writer)

Step 2: Create AWS Entry and Secret Keys

To make use of AWS CLI, we have to present authentication credentials. This requires an AWS Entry Key ID and AWS Secret Entry Key.

The place to Discover Your AWS Entry and Secret Key?

  • Log in to your AWS Administration Console.
  • Click on in your Profile Identify (top-right nook).
  • Choose “Safety Credentials” from the dropdown menu.
  • Scroll all the way down to the “Entry Keys” part.
  • Click on “Create Entry Key” → A brand new key pair (Entry Key ID & Secret Entry Key) might be generated.
  • Copy and retailer these keys securely (as AWS won’t present them once more).

Necessary: AWS doesn’t suggest creating entry keys for the basis consumer attributable to safety dangers. Ideally, it is best to make an IAM consumer with particular permissions. Nevertheless, since this information is concentrated on AWS Lambda deployment, we’ll cowl IAM roles & greatest practices individually in a future lesson.

Safety Be aware:

  • Don’t share your AWS credentials publicly or commit them to GitHub.
  • In the event you ever suspect your credentials are compromised, delete the entry key instantly from the AWS Safety Credentials web page.

Step 3: Configure AWS CLI with Your Credentials

After putting in AWS CLI, we have to configure it with the mandatory credentials to entry AWS companies.

Run the next command to start out the configuration course of:

aws configure

You can be prompted to enter the next particulars:

AWS Entry Key ID [None]: XXXXXXXXXXXXXXXXXXXX
AWS Secret Entry Key [None]: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Default area title [None]: ap-south-1
Default output format [None]: json

AWS Entry Key ID and Secret Entry Key might be obtained from the AWS IAM console below “My Safety Credentials”.

Set the Default area title to the AWS area the place you propose to deploy (e.g., ap-south-1) and select the Default output format as json, desk, or textual content (default: json).

Tip: You’ll be able to at all times replace credentials later by operating the command under, however guarantee they match those within the AWS Console.

aws configure set aws_access_key_id NEW_ACCESS_KEY
aws configure set aws_secret_access_key NEW_SECRET_KEY

Step 4: Confirm AWS CLI Entry

To substantiate AWS CLI is appropriately arrange, run the next instructions:

Test AWS Id

aws sts get-caller-identity

Anticipated output:

{
    "UserId": "AIDXXXXXXXXXXX",
    "Account": "123456789012",
    "Arn": "arn:aws:iam::123456789012:consumer/root"
}

If this command fails, be certain that your AWS credentials are appropriately configured.

Test Current AWS Lambda Features

aws lambda list-functions

Since we haven’t created any Lambda features but, the response must be:

{
    "Features": []
}

Test AWS ECR Repositories

aws ecr describe-repositories

If no repositories exist but, you’ll see an empty record:

{
    "repositories": []
}

This confirms that AWS CLI is correctly configured and able to work together with AWS companies.

Now that AWS CLI is ready up, we’ll construct our FastAPI Docker picture regionally and push the container picture to AWS ECR for Lambda deployment.


Constructing and Pushing the Docker Picture to AWS ECR

Now that we have now AWS CLI configured, it’s time to construct our FastAPI Docker picture and push it to AWS Elastic Container Registry (ECR). AWS ECR is a totally managed container registry that enables us to retailer, handle, and deploy Docker container photographs. Since AWS Lambda helps container-based deployments, we’ll use ECR to retailer our mannequin’s container picture earlier than linking it to Lambda.


Step 1: Create an AWS ECR Repository

Earlier than we will push our Docker picture, we have to create a non-public ECR repository to retailer the container.

Run the next command to create a brand new ECR repository:

aws ecr create-repository --repository-name pis-fastapi-ai-inference --region ap-south-1

If the repository is created efficiently, you will note output just like the next:

{
    "repository": {
        "repositoryArn": "arn:aws:ecr:ap-south-1:123456789012:repository/pis-fastapi-ai-inference",
        "registryId": "123456789012",
        "repositoryName": "pis-fastapi-ai-inference",
        "repositoryUri": "123456789012.dkr.ecr.ap-south-1.amazonaws.com/pis-fastapi-ai-inference",
        "createdAt": "2025-03-14T04:47:157000+05:30",
        "imageTagMutability": "MUTABLE",
        "imageScanningConfiguration": { "scanOnPush": false }
    }
}

Now you can view the newly created repository within the AWS console below the Personal Registry part of ECR, as proven in Determine 5.

Determine 5: Viewing the newly created Amazon ECR non-public repository within the AWS Administration Console (supply: picture by the writer)

Note the repositoryUri (e.g., 123456789012.dkr.ecr.ap-south-1.amazonaws.com/pis-fastapi-ai-inference). We are going to use this URI to tag and push our Docker picture.

In the event you ever must record your ECR repositories, run:

aws ecr describe-repositories

Step 2: Authenticate Docker with AWS ECR

To push photographs to AWS ECR, we have to authenticate Docker with AWS CLI. Run the next command:

aws ecr get-login-password --region ap-south-1 | docker login --username AWS --password-stdin 123456789012.dkr.ecr.ap-south-1.amazonaws.com

If profitable, it is best to see:

Login Succeeded

Step 3: Construct the FastAPI Docker Picture

Now, let’s construct the Docker picture for our FastAPI AI inference mannequin.

Navigate to your venture root listing (the place your Dockerfile is positioned) and run:

docker construct -t fastapi-ai-inference .

The above command does the next:

  • Makes use of the Dockerfile within the present listing (.) to construct the picture.
  • Tags the picture as fastapi-ai-inference.
  • Installs all required dependencies and units up the FastAPI app.

As soon as full, confirm that the picture was constructed efficiently:

docker photographs

Anticipated output:

REPOSITORY               TAG       IMAGE ID       CREATED         SIZE
fastapi-ai-inference     newest    2d3a3f27c1a1   2 minutes in the past   450MB

Step 4: Tag the Docker Picture for AWS ECR

Earlier than pushing the Docker picture to Amazon ECR, it have to be tagged with the complete ECR repository URI in order that Docker is aware of which distant registry to add it to.

Run:

docker tag fastapi-ai-inference:newest 123456789012.dkr.ecr.ap-south-1.amazonaws.com/pis-fastapi-ai-inference:newest

You’ll be able to confirm the tag utilizing:

docker photographs

It is best to now see two tagged references to the identical picture — one native tag and one ECR tag, as proven in Determine 6.

Determine 6: Itemizing regionally constructed Docker photographs earlier than pushing to Amazon ECR (supply: by the writer)

Step 5: Push the Docker Picture to AWS ECR

Now, let’s push the tagged picture to AWS ECR in order that AWS Lambda can pull it later.

docker push 123456789012.dkr.ecr.ap-south-1.amazonaws.com/pis-fastapi-ai-inference:newest

This course of would possibly take a couple of minutes relying in your web velocity, and as soon as full, it is best to see output like:

The push refers to repository [123456789012.dkr.ecr.ap-south-1.amazonaws.com/pis-fastapi-ai-inference]
newest: Pushed

Step 6: Confirm the Picture in AWS ECR

To substantiate that the picture is efficiently saved in AWS ECR, run:

aws ecr list-images --repository-name pis-fastapi-ai-inference

Anticipated output:

{
    "imageIds": [
        {
            "imageTag": "latest",
            "imageDigest": "sha256:3a4d6b..."
        }
    ]
}

Alternatively, you’ll be able to verify manually within the AWS Console by opening the AWS Administration Console, navigating to ECR (Elastic Container Registry), and clicking the pis-fastapi-ai-inference repository. It is best to see your Docker picture listed, as proven in Determine 7.

By way of AWS Console:

Determine 7: Viewing Docker photographs contained in the Amazon ECR repository console (supply: picture by the writer)

By way of AWS CLI:

Determine 8: Itemizing ECR photographs utilizing the AWS CLI with aws ecr list-images (supply: by the writer)

In case your photographs belong to totally different tasks or serve numerous functions, it’s greatest to create a brand new repository for every.


What’s subsequent? We suggest PyImageSearch College.

Course data:
86+ whole courses • 115+ hours hours of on-demand code walkthrough movies • Final up to date: November 2025
★★★★★ 4.84 (128 Scores) • 16,000+ College students Enrolled

I strongly imagine that for those who had the precise trainer you may grasp pc imaginative and prescient and deep studying.

Do you assume studying pc imaginative and prescient and deep studying needs to be time-consuming, overwhelming, and sophisticated? Or has to contain advanced arithmetic and equations? Or requires a level in pc science?

That’s not the case.

All it is advisable to grasp pc imaginative and prescient and deep studying is for somebody to elucidate issues to you in easy, intuitive phrases. And that’s precisely what I do. My mission is to alter schooling and the way advanced Synthetic Intelligence matters are taught.

In the event you’re severe about studying pc imaginative and prescient, your subsequent cease must be PyImageSearch College, essentially the most complete pc imaginative and prescient, deep studying, and OpenCV course on-line immediately. Right here you’ll discover ways to efficiently and confidently apply pc imaginative and prescient to your work, analysis, and tasks. Be a part of me in pc imaginative and prescient mastery.

Inside PyImageSearch College you will discover:

  • &verify; 86+ programs on important pc imaginative and prescient, deep studying, and OpenCV matters
  • &verify; 86 Certificates of Completion
  • &verify; 115+ hours hours of on-demand video
  • &verify; Model new programs launched usually, guaranteeing you’ll be able to sustain with state-of-the-art methods
  • &verify; Pre-configured Jupyter Notebooks in Google Colab
  • &verify; Run all code examples in your net browser — works on Home windows, macOS, and Linux (no dev setting configuration required!)
  • &verify; Entry to centralized code repos for all 540+ tutorials on PyImageSearch
  • &verify; Simple one-click downloads for code, datasets, pre-trained fashions, and many others.
  • &verify; Entry on cellular, laptop computer, desktop, and many others.

Click on right here to hitch PyImageSearch College


Abstract

On this lesson, we explored the basics of the AWS CLI and its position in effectively managing AWS companies from the terminal. We additionally lined AWS Elastic Container Registry (ECR), a managed service for storing container photographs, and the important thing variations between private and non-private ECR repositories, highlighting why a personal repository is the only option for safe AI mannequin deployment.

With this foundational information, we proceeded to arrange AWS CLI, configure credentials, and confirm entry. We then created a personal AWS ECR repository, constructed a Docker picture for our FastAPI AI inference app, and efficiently pushed it to AWS ECR.

At this stage, our containerized AI utility is securely saved in AWS ECR and able to be deployed to AWS Lambda. Within the subsequent lesson, we’ll arrange AWS Lambda, hyperlink it to our ECR picture, and check our deployed FastAPI AI mannequin.


Quotation Data

Singh, V. “Pushing Docker App to AWS ECR for Lambda Deployment Utilizing AWS CLI,” PyImageSearch, P. Chugh, S. Huot, A. Sharma, and P. Thakur, eds., 2025, https://pyimg.co/mzxbn

@incollection{Singh_2025_Pushing-Docker-App-AWS-ECR-Lambda-Deployment-Utilizing-AWS-CLI,
  writer = {Vikram Singh},
  title = {{Pushing Docker App to AWS ECR for Lambda Deployment Utilizing AWS CLI}},
  booktitle = {PyImageSearch},
  editor = {Puneet Chugh and Susan Huot and Aditya Sharma and Piyush Thakur},
  12 months = {2025},
  url = {https://pyimg.co/mzxbn},
}

To obtain the supply code to this submit (and be notified when future tutorials are revealed right here on PyImageSearch), merely enter your e-mail deal with within the kind under!

Obtain the Supply Code and FREE 17-page Useful resource Information

Enter your e-mail deal with under to get a .zip of the code and a FREE 17-page Useful resource Information on Laptop Imaginative and prescient, OpenCV, and Deep Studying. Inside you will discover my hand-picked tutorials, books, programs, and libraries that can assist you grasp CV and DL!

The submit Pushing Docker App to AWS ECR for Lambda Deployment Utilizing AWS CLI appeared first on PyImageSearch.


Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles