AWS Lambda added container support some time ago.

We're going to look into what this offer actually includes and how we could build a containerized Lambda function ourselves. πŸ‘¨πŸ»β€πŸ«

Start your IDEs and open your AWS consoles because we're going in!

πŸ§΅πŸ‘‡πŸ»
1️⃣ AWS Lambda Previous To Container Image Support

Until recently, AWS Lambda only allowed you to write some code and upload a zip archive containing all files necessary to run your function.

Some frameworks eased up this process, but that's how it went.
Lambda also imposed some pretty strict limits, especially the 50MB default deployment size limit.

You could technically circumvent this limit by pulling more deployment dependencies from S3 or issuing an AWS Service Limits support request. But this wasn't the most...
...intuitive or clear thing to do.

This could make it pretty difficult sometimes to create Lambda functions out of a larger deployment. Especially when using data science dependencies like NumPy, pandas, or larger JS libraries, you could easily hit that limit.
2️⃣ What Container Image Support Includes

Container Image Support includes, well...containers.

This means that you can now build an image with your favorite tool (Docker anyone?), using a base image supplied by AWS, and then upload it to the ...
... Amazon Elastic Container Registry (ECR).

And do you know what's even more awesome? Those images can have a size of up to 10GB! You no longer have to worry about the deployment size constraints. It'll be pretty difficult to hit that limit fast.
After you push your image to ECR, you can create your Lambda function as you usually would and point Lambda to it. Nothing more to do.

A bonus:
If you use AWS' base images, which all contain the AWS Lambda Runtime Interface Emulator ...
... you can even test your containers locally by using curl or your favorite REST endpoint testing tool of choice (Postman/Postwoman, anyone?).

You can find out more about it here:
β›“ github.com/aws/aws-lambda…
3️⃣ What Container Image Support Means

Container image support is a pretty huge thing.

Many organizations have invested heavily in containerization, but the paradigm Lambda until recently, stood for was a pretty huge shift.
It was simply a lot of new stuff to learn for all developers involved in creating services and remote endpoints.
And it required a whole other range of tools than those previously used.

Now, developers can use the same tools they are already comfortable with.
The deployment to AWS could be something a little different, but CI pipelines for containers can be reused.

The company-internal container registry? Can be reused.

Locally testing your containers? Stays as it is!

I hope you see where this is going! 😊
4️⃣ Building A Containerized Lambda Function

We're now going to walk through the process of building your first containerized Lambda function.

I'm pretty sure that you will notice that it's not much different from how you did it before, with only a few additional steps.
First of all, set up the folder and initialize a new npm project.

You could add a lot more dependencies now, but we're only going to build a pretty basic Lambda, so that's unnecessary at this point. Image
Now you need some code. It's not much, but enough to return a response from your handler.

Create a file "index.js" and put the basic handler code into it, as shown below.

If you worked with Lambda before, you'd notice that the handler has the same signature as it always had. Image
'npm install' once to create your package-lock.json.

It's not really necessary at this stage as there are no dependencies at all, but it helps to prevent further warnings when later building your container image. Image
Then create a Dockerfile and fill it as shown below.

This is the file you will let Docker build your image from. Image
Before you go on, here is a gist containing all the contents of the files as they should now be:

β›“ gist.github.com/excelbrium/6db…
One of the last things to do is to build the container, for example, with Docker.

It shouldn't take too much time, as your project is very simple and small at this point.

After building the container, you're nearly done. Image
You could now start the container locally, and even issue requests to it, simply to test if everything is working as expected.

You can also use curl to issue a request, and as you hopefully see, it works! Image
5️⃣ Deploying The Container to AWS Lambda

You now need to upload your container image to ECR to deploy it to Lambda later.

I'd recommend you to have the AWS CLI installed for this task.

β›“ aws.amazon.com/cli/?nc1=h_ls
The following steps are then necessary to upload your image to ECR:

1. Create an ECR repository (skip if you already have one)
2. Tag your image
3. Log in to ECR
4. Push the image Image
Next, go to the Lambda console here:

β›“ console.aws.amazon.com/lambda/home

Click on "Create function", and then choose "Container image". Image
Within the "Basic information" block, give your function a name, and then paste the image URL you used to push your image to ECR.

And that's it. Click on "Create function" in the bottom right corner, and your function will be deployed! Image
You can now do everything you'd do with a "normal" Lambda function. Maybe you want to use API Gateway to redirect incoming traffic to your Lambda function or set up a few events.

That's all up to you now!
5️⃣ Some Words Of Advice

Be advised that AWS tries to make money from all this, of course.

There is a generous free tier for Lambda and ECR, but keep in mind that only a certain amount of traffic and storage is free each month or for a year.
If you followed this tutorial, try to keep in mind that you used up some of that free tier.

You shouldn't forget your lambda and container, as you might be pleasantly surprised that you have to pay money if you go back to AWS at some point and deploy more stuff!
6️⃣ Conclusion

Container image support has made Lambda even better than it was before.

The paradigm shift has always been a problem for quite a few companies that took some good effort to train their engineers/devs in newer concepts like microservices and containerization.
And especially a lot of the tools that were introduced into organizations to ease up the development process were more and more tailored to containers in recent times.

All that knowledge and all those tools can now also be used with AWS Lambda, which is indeed ...
... a game-changer. Adoption of serverless FaaS is now easier than ever before, even for larger organizations.

Companies can still use their old-school Jenkinses or newer CI tools to build their code and then containerize it afterward.

Maybe those organizations also ...
... push their images to ECR already. The change is marginal then: Deploy the container as a Lambda function instead of deploying it to EKS or Fargate.

Deployments that were previously difficult to achieve or impossible, due to the size constraints, are now possible, ...
... which could open up a lot of opportunities for organizations to deploy machine learning models as Lambda functions or generally larger projects.

I personally like those changes. Due to the nature of my job, I've been more focused on containers.
All our tools are tailored towards containers. Now I can also use them with Lambda functions.

In the end, I'm pretty happy with the recent development of Lambda.

However, I hope that you enjoyed reading this, and maybe take it as an inspiration to try it out yourself! 😊

β€’ β€’ β€’

Missing some Tweet in this thread? You can try to force a refresh
γ€€

Keep Current with Oliver Jumpertz

Oliver Jumpertz Profile picture

Stay in touch and get notified when new unrolls are available from this author!

Read all threads

This Thread may be Removed Anytime!

PDF

Twitter may remove this content at anytime! Save it as PDF for later use!

Try unrolling a thread yourself!

how to unroll video
  1. Follow @ThreadReaderApp to mention us!

  2. From a Twitter thread mention us with a keyword "unroll"
@threadreaderapp unroll

Practice here first or read more on our help page!

More from @oliverjumpertz

30 May
Okay, I'll give away another 30 copies of Pratham's cheat sheet collection.

If you can't afford or buy for some reason and still want to support @Prathkum, DM me your mail.

❗️ First come, first served ❗️

Answering and sending out might take some time!
I already have way more than 30 DMs. I will process them in the order I received them. πŸ™πŸ»

Give me some time, I'll notify anyone who managed to get one. ☺️
This is your lucky day. Thanks to @Prathkum, I'll give away 20 additional ones!
Read 7 tweets
29 May
I love AWS Lambda. It's so easy to get a function up and running while AWS handles everything other than the code for you.

But where is your code actually executed? How does AWS do it?

Well, I took a deeper look and this is what Lambda's foundation is!

πŸ§΅πŸ‘‡πŸ»
1️⃣ Thinking about Lambda

We know that we can write a script that looks like below and then upload it to AWS while they take care of everything else.

And from simply looking at the code, it doesn't look like the usual API method we'd implement in Express. Image
We're exporting a function, so something else must take our code, import it, and handle everything else. πŸ€”

Conclusion number one:
Something must run our code.
Read 28 tweets
26 May
There are alternatives out there but Git is by far the most used version control management tool which makes it essential for most software developers.

This justifies taking a look at _some_ of the most essential git operations you will need as a developer!

πŸ§΅πŸ‘‡πŸ»
1️⃣ Create A New Repository

This is the most basic command you'll need. When you start a repository locally, your start with git init. git init
2️⃣ Clone A Repository

You can clone a remote repository to get a local copy of it. Your local repository is connected to the remote one, so you can pull in changes and push yours to it git clone <remoteUrl/>
Read 15 tweets
25 May
I wanted to quickly share my perspective as an interviewer when it comes to portfolio projects.

I see many people thinking way too long about what to build, which quickly becomes an issue for them.

They spend way longer thinking than actually building.

πŸ‘‡πŸ»
I'd rather see the same ToDo app over and over again, well-executed with everything I'd like such a project to have, than twenty exotic apps that you could well have started your own company with.

I don't know whether I'm a minority here, but as a developer, you are not ...
...a product designer. Your day job won't be to come up with new ideas. It's, of course, highly appreciated if you supply your ideas for the product we might be working on, but never mandatory.

So, what I try to say is: Spend more time executing and building.
Read 4 tweets
23 May
If you want to become a Web 3.0 developer, a structured approach can leverage your learning by a lot.

Let me give you a roadmap that will definitely lead you towards your goal!

πŸ§΅πŸ‘‡πŸ»
0️⃣ Prerequisites

You should know JavaScript and web development in general.

If you don't, you should take a step back at this point and learn about web development first.

There are so many awesome courses and tutorials out there. You won't have a hard time finding good ones.
1️⃣ Learn The Basics Of Blockchain

You need to know what you work with. Blockchains are an incredible piece of technology, but they also aren't trivial to learn.

You'll have to put some time into it to understand what you will later build on.
Read 22 tweets
22 May
If you want to get hired, become an expert in one thing first before you try to learn everything across the board.

There must be a reason someone wants to work with you or you to work for them. Someone needs to have a demand for your expertise.

1/4
The thing is that "expertise" or "being an expert" is often misunderstood.

It doesn't mean knowing everything in and out. It means that you have a level of knowledge in something that helps you to solve problems.

2/4
People need those problems solved, and they will happily pay you to do it for them.

If you can do this with some HTML and CSS knowledge and build what they need, you are indeed an expert.

3/4
Read 4 tweets

Did Thread Reader help you today?

Support us! We are indie developers!


This site is made by just two indie developers on a laptop doing marketing, support and development! Read more about the story.

Become a Premium Member ($3/month or $30/year) and get exclusive features!

Become Premium

Too expensive? Make a small donation by buying us coffee ($5) or help with server cost ($10)

Donate via Paypal Become our Patreon

Thank you for your support!

Follow Us on Twitter!

:(