With high scalability, fault tolerance infrastructure, and pay-per-value services pricing model, AWS Lambda, with its latest support — AWS Lambda Docker Image — now caters to a broader audience of developers, helping them build serverless apps for on-demand image processing and much more.

Altogether there are benefits of using AWS Lambda Docker Image as Lambda administers container-based functions as unchangeable entities. When called-upon, the deployed functions as container images are run as-is. As for developers who work with a larger workload — more specifically, with more than 10 GB — the process unwinds new possibilities for data-heavy or dependency-heavy applications.

That said, in this article, we will discuss AWS Lambda Docker Image in detail. Let’s begin.

What is AWS Lambda Project?

Lambda Docker Image | lambda logo
AWS Lambda

Lambda — a functions-as-a-service offering — is a serverless compute service provided by AWS that lets you run code without the immediate need to administer compute resources. In short, the need to provision or manage servers does not exist. Lambda ultimately removes the need to build teams that capacities and/or are included in server and operating system maintenance, automatic scaling or capacity provisioning, logging, and code monitoring.

Moreover, Lambda’s functioning is quite simpler, too. You decide upon how to organize code (which Lambda supports) into the Lambda functions then Lambda automates the process to scale up or down the function run process. Lambda’s billing system is based on industry-standard, i.e., pay-as-you-go basis; hence you do not get charged if your code is not running.

Now, it’s also worth mentioning that Lambda’s use is recommended in only specific application scenarios. AWS’s documentation suggests utilizing Lambda for times when you run code using Lambda’s standard run-time environment or the resources it provides. The documentation also insists on Lambda’s best utilization for relevantly shorter and event-driven workloads — the reason being Lambda functions’ run-time which is set for 15 minutes per invocation.

That said, let’s list out some developers’ friendly features of Lambda that will help you build scalable, secure, and definitive applications that are easily extensible.

  • Concurrency and scaling controls: Concurrency and scaling controls, such as concurrency limits and provisioned concurrency, allow you to fine-tune the scalability and reactivity of your production applications.
  • Functions Defined as Container Images: To develop, test, and deploy your Lambda functions, it lets you use your favorite container image tooling, processes, and dependencies.
  • Code Signing: Code signing for Lambda offers trust and integrity controls, allowing you to ensure that only unmodified code published by authorized developers is deployed in your Lambda services.
  • Lambda Extensions: Lambda extensions may be used to enhance your Lambda functions. Use extensions, for example, to make it easier to combine Lambda with your chosen tools for monitoring, observability, security, and governance.
  • Blueprints of Function: A function blueprint contains sample code that demonstrates how to utilize Lambda in conjunction with other AWS services or third-party applications. Sample code and function setup settings for the Node.js and Python run-times are included in the blueprints.
  • Database Accessibility: A database proxy controls a pool of database connections and transmits function queries. This allows a function to attain large levels of concurrency without draining database connections.
  • Access to File Systems: A function can be configured to mount an Amazon Elastic File System (Amazon EFS) file system to a local directory. With Amazon EFS, your function code may securely and concurrently access and alter shared resources.

What is Docker?

Lambda Docker Image | docker logo
docker

Docker is a free and open platform for creating, delivering, and operating applications. Docker allows you to decouple your apps from the existing infrastructure, allowing you to deploy software swiftly. Docker allows you to manage your infrastructure in the same manner that you control your apps. You can drastically minimize the time between developing code and executing it in production by employing Docker’s methodology for fast shipping, testing, and deploying code.

Docker allows you to bundle and execute a program in a container, which is a loosely separated environment. Because of the isolation and security, you can run several containers on a single host at the same time. Containers are lightweight and include everything needed to run the program, eliminating the need to rely on what is already installed on the host. It’s possible to simply share containers while working and then ensure that everyone with whom you share receives the same container that functions in a similar manner.

Here’s how Docker ensures fast and consistent deployment of applications.

  • Responsive Deployment & Scaling: The container-based Docker technology enables highly portable workloads. Docker containers can operate on a developer’s laptop, physical or virtual computers in a data center, cloud providers, or a combination of these settings. Docker’s mobility and compact features make managing workloads and scaling up or down apps and services simpler in near real-time as your business demands dictate.
  • Run More Workloads On the Same Hardware: Docker is a compact and powerful application. It offers a realistic, cost-effective alternative to hypervisor-based virtual machines, allowing you to make better use of your computing power to fulfill your business objectives. Docker is ideal for high-density situations as well as small and medium-sized deployments where you need to accomplish more with fewer resources.

AWS Lambda Docker Image: How to Create?

In this following section of the blog post, we will discuss in detail the hows of creating AWS Lambda Docker Image — using your Lambda function as a Docker image. Using the AWS Lambda Docker Image developers have more control over the run-time aspects when working with AWS Lambda by choosing custom run-times like .NET 5.0. 

Now, let’s begin by first creating a Visual Studio .NET Core Lambda Project.

Create a Visual Studio .NET Core Lambda Project

A pre-installed Lambda Visual Studio blueprints offer speedy project creation. And, a blueprint is a pre-packaged set of files and functions that is used to rapidly show the functionality and serve as a useful starting point for future changes.

Steps to create a Visual Studio .NET Core Lambda project for the AWS Lambda Docker Image:

Step 1: Open Visual Studio. Navigate through the ‘File’ menu to choose ‘New’ then ‘Project.’

Step 2: It’s expected you to do the following:

  1. In the New Project dialogue box for Visual Studio 2017, choose Installed, expand Visual C#, select AWS Lambda, select the AWS Lambda Project (.NET Core – C#) template, and then click OK.
  2. In Visual Studio 2019, in the New Project dialogue box, set the Language, Platform, and Project type drop-down boxes to “All” and put AWS lambda into the Search area. Then select the AWS Lambda Project (.NET Core – C#) template and press the Next button.

Step 3: Do one of the following:

  1. For Visual Studio 2017: Enter AWSLambdaDocker for the Name field, the appropriate file location for the File Location field, and then click OK.
  2. For Visual Studio 2019: Enter AWSLambdaDocker for the Name field, the appropriate file location for the File Location field, and then click Create.

Step 4: Choose the.NET 5 (Container Image) blueprint on the Select Blueprint screen, and then finish building the Visual Studio project. You may now examine the structure and code of the project.

Review the Project Files

The three project files to review are as follows: Dockerfile, aws-lambda-tools-defaults.json, and function.cs.

The following code exhibits the Dockerfile, created by using the blueprint selected well before.

FROM: It determines the base picture to be used for this image. This basic image includes the.NET Run-time, the Lambda run-time, and a shell script that acts as an entry point for the Lambda.NET process.

WORKDIR: The image’s internal work directory is set to /var/task.

COPY: Will transfer the files created by the build process from their current location into the image’s work directory.

FROM ecr.aws/lambda/dotnet:5.0

WORKDIR /var/task

# This COPY command copies the .NET Lambda project's build artifacts from the host machine into the image. 
# The source of the COPY should match where the .NET Lambda project publishes its build artifacts. If the Lambda function is being built 
# with the AWS .NET Lambda Tooling, the `--docker-host-build-output-dir` switch controls where the .NET Lambda project
# will be built. The .NET Lambda project templates default to having `--docker-host-build-output-dir`
# set in the aws-lambda-tools-defaults.json file to "bin/Release/net5.0/linux-x64/publish".
#
# Alternatively Docker multi-stage build could be used to build the .NET Lambda project inside the image.
# For more information on this approach checkout the project's README.md file.
COPY "bin/Release/net5.0/linux-x64/publish"  .         

Utilize the below-given to customize your Dockerfile:

  1. ENTRYPOINT: The basic image already has an ENTRYPOINT, which is the starting process that is run when the image is launched. If you specify your own, you are overriding the default entry point.
  2. CMD: CMD directs AWS on which custom code to execute. It wants your custom method to have a properly qualified name. This line must be inserted directly in the Dockerfile or supplied during the publishing process.
# Example of alternative way to specify the Lambda target method rather than during the publish process.
CMD [ "AWSLambdaDocker::AWSLambdaDocker.Function::FunctionHandler"]

Examine the aws-lambda-tools-defaults.json file.

  1. The field docker-host-build-output-dir specifies the output directory of the build process, which corresponds to the Dockerfile instructions.
  2. The field image command is a fully-qualified name for your method, which is the code you want the AWS Lambda Docker Image function to execute. The syntax is as follows: {Assembly}::{Namespace}. {ClassName}::{MethodName}. See Handler signatures for additional details. Setting the image command here will pre-populate this value in the Publish wizard in Visual Studio later on.
{
  "Information": [
    "This file provides default values for the deployment wizard inside Visual Studio and the AWS Lambda commands added to the .NET Core CLI.",
    "To learn more about the Lambda commands with the .NET Core CLI execute the following command at the command line in the project root directory.",
    "dotnet lambda help",
    "All the command line options for the Lambda command can be specified in this file."
  ],
  "profile": "default",
  "region": "us-east-2",
  "configuration": "Release",
  "package-type": "image",
  "function-memory-size": 256,
  "function-timeout": 30,
  "image-command": "AWSLambdaDocker::AWSLambdaDocker.Function::FunctionHandler",
  "docker-host-build-output-dir": "./bin/Release/net5.0/linux-x64/publish"
}      

Examine the file Function.cs. Function.cs specifies the c# functions that will be exposed as AWS Lambda Docker Image functions. The AWS Lambda Docker Image functionality that executes when the Lambda function runs is the FunctionHandler. There is only one function specified in this project: FunctionHandler, which calls ToUpper() on the input text.

Your project is now ready for Lambda publication! Let’s see what’s next in the AWS Lambda Docker Image Function process.

Publish to Lambda

The build process generates Docker images, which are then published to Amazon Elastic Container Registry (Amazon ECR). Amazon ECR is a Docker container registry that allows you to store, manage, and deploy Docker container images. When triggered, Lambda refers to the image hosted by Amazon ECR to offer the programmed AWS Lambda Docker Image functionality.

Steps to publish functions to Lambda using the AWS Lambda Docker Image:

Step 1: Open the context (right-click) menu for the project in Solution Explorer, and then select Publish to AWS Lambda.

Step 2: Now in the next step for AWS Lambda Docker Image Function, do the following on the Upload Lambda Function page:

Lambda Docker Image | publish to lambda
AWS Documentation
  • Because the publishing process recognized a Dockerfile in your project, the image was automatically picked as your Package Type.
  • Enter a display name for your AWS Lambda Docker Image instance in the Function Name field. This is the reference name that appears in the AWS Explorer in Visual Studio as well as the AWS Management Console.
  • Enter content for your instance’s description in the AWS Management Console.
  • Enter a fully-qualified path to the method you want the AWS Lambda Docker Image function to run for Image Command: AWSLambdaDocker::AWSLambdaDocker. Function::FunctionHandler
  • Enter the name of a new or existing Amazon Elastic Container Registry for Image Repo. The Docker image generated by the build process is posted to this registry. The released AWS Lambda Docker Image definition will make use of the Amazon ECR image.
  • Enter a Docker tag to associate with your image in the repository for Image Tag.
  • Select Next.

Step 3: Choose a role connected with your account under Role Name on the Advanced Function Details page. The role is used to supply temporary credentials for any Amazon Web Services calls performed by the function’s code. If you don’t already have a role, choose New Role-based on AWS Managed Microsoft AD Policy, then AWSLambdaBasicExecutionRole.

Step 4: Choose Upload. The Uploading Function page displays while the function is uploading. The publish process then builds the image based on the configuration parameters, creates the Amazon ECR repository if necessary, uploads the image into the repository, and creates the Lambda referencing that repo with that image. After the function is uploaded, the Function page opens and displays your new Lambda function’s configuration.

Step 5: On the Test Function tab, type hello picture-based lambda into the request free-text input area and then pick Call to manually invoke the Lambda function. Your content, which has been changed to uppercase, will show in Response.

Lambda Docker Image | publish to lambda
AWS Documentation

Step 6: To access the repository, navigate to AWS Explorer and choose Repositories under Amazon Elastic Container Service. You may return to the function: view at any moment by double-clicking on your deployed instance in the AWS Explorer, which is situated under the AWS Lambda node.

Step 7: On the Setup tab, take note of the extra image-specific Configuration tab. This page allows you to alter the ENTRYPOINT, CMD, and WORKDIR parameters supplied in the Dockerfile. The Description is the text you submitted (if any) during the upload/publish process.

Clean-up

If you are not going to continue development with this example, remember to remove the deployed function and ECR image so that you are not invoiced for idle resources in your account.

  • Functions may be removed by right-clicking your deployed instance in the AWS Explorer beneath the AWS Lambda node and selecting Delete Function.
  • Repositories may be removed using the AWS Explorer‘s Amazon Elastic Container Service -> Repositories menu.

Conclusion

In this blog post, we discussed about AWS Lambda Docker Image through which you can have good control over your runtime or choose to have custom runtimes like .NET 5.0. But, if you want to learn more about AWS Lambda Docker Image and understand more about the subject, either of the two below-given articles can help:

For setting up the AWS Toolkit for Visual Studio the below-given article can help. This article will also help you a better understanding of AWS Lambda Docker Image.

Visit our Website to Explore Hevo

Hevo Data will automate your data transfer process, hence allowing you to focus on other aspects of your business like Analytics, Customer Management, etc. This platform allows you to transfer data from 100+ multiple sources to Cloud-based Data Warehouses like Snowflake, Google BigQuery, Amazon Redshift, etc. It will provide you with a hassle-free experience and make your work life much easier.

Want to take Hevo for a spin? Sign Up for a 14-day free trial and experience the feature-rich Hevo suite first hand.

You can also have a look at our unbeatable pricing which will help you choose the right plan for your business needs. Also, let’s know about your learning experience with the AWS Lambda Docker Image blog in the comments section below!

Yash Arora
Content Manager, Hevo Data

Yash is a Content Marketing professional with over three years of experience in data-driven marketing campaigns. He has expertise in strategic thinking, integrated marketing, and customer acquisition. Through comprehensive marketing communications and innovative digital strategies, he has driven growth for startups and established brands.

No-code Data Pipeline for Redshift