๐Ÿ“š AWS 1x1 - ๐—Ÿ๐—ฎ๐—บ๐—ฏ๐—ฑ๐—ฎ ฦ›

The Heart of your Serverless Love Story ๐Ÿงก

All my learnings & (almost) everything you need to know โ†“
๐—ง๐—ต๐—ฟ๐—ฒ๐—ฎ๐—ฑ ๐—ข๐˜ƒ๐—ฒ๐—ฟ๐˜ƒ๐—ถ๐—ฒ๐˜„

โ€ข Introduction
โ€ข Cold Starts
โ€ข Handler Method
โ€ข Runtimes
โ€ข Layers
โ€ข Security
โ€ข Versioning & Aliases
โ€ข Provisioned & Reserved Concurrency
โ€ข Lambda@Edge
โ€ข Pros & Cons
โ€ข Observability
โ€ข Considerations to make

{ 1/31 }
๐—œ๐—ป๐˜๐—ฟ๐—ผ๐—ฑ๐˜‚๐—ฐ๐˜๐—ถ๐—ผ๐—ป

AWS released Lambda in late 2014, spreading the buzzword serverless.

With EC2 you didn't have to think about physical servers anymore, but only virtual machines.

With Lambda, there's not even that anymore to maintain.
Just bring your code.

{ 2/31 }
AWS will take care of provisioning the underlying infrastructure and container.

Besides not having to think about operation overhead like you'd have when managing virtual machines or containers, you'll be only billed when your function is actually executed.

{ 3/31 }
What does that mean?

If you're building a spike or an MVP for a business idea that's solely featuring serverless services like Lambda, you won't induce costs when your service is idle.

That's a huge plus in comparison to using ECS or EC2.

{ 4/31 }
What's probably not obvious and I've found that there's often confusion amongst beginners:
A single Lambda instance will only process a single request at a time

If two requests are reaching your Lambda at the exact same time, there's a need for two dedicated instances

{ 5/31 }
Why's that important?

AWS doesn't want to block computation resources for idle functions, so it will regularly de-provision your function.

Even if they are continuously invoked, ๐˜๐—ต๐—ฒ๐˜† ๐˜„๐—ถ๐—น๐—น ๐—ฏ๐—ฒ ๐—ฑ๐—ฒ-๐—ฝ๐—ฟ๐—ผ๐˜ƒ๐—ถ๐˜€๐—ถ๐—ผ๐—ป๐—ฒ๐—ฑ ๐—ฎ๐˜ ๐˜€๐—ผ๐—บ๐—ฒ ๐˜๐—ถ๐—บ๐—ฒ.

{ 6/31 }
This results in having the feared ๐—–๐—ผ๐—น๐—ฑ ๐—ฆ๐˜๐—ฎ๐—ฟ๐˜๐˜€

If your request triggers a new Lambda instance, you'll have a significantly longer delay until your function code is executed.
If you're not using a lightweight framework, the bootstrap will even take more time.

{ 7/31 }
You can work against that by regularly invoking your functions with health checks, but as said, it won't protect you from having cold starts from time to time.

That's why it's important to not run code that needs a lot of spin-up time.

{ 8/31 }
๐—›๐—ฎ๐—ป๐—ฑ๐—น๐—ฒ๐—ฟ ๐— ๐—ฒ๐˜๐—ต๐—ผ๐—ฑ

That's always the entry point of your Lambda function.

Everything that's outside this function will be executed first when your function receives a cold start and ๐˜„๐—ผ๐—ป'๐˜ ๐—ฑ๐—ถ๐˜€๐—ฎ๐—ฝ๐—ฝ๐—ฒ๐—ฎ๐—ฟ from memory until it's de-provisioned.

{ 9/31 }
Another ๐—ด๐—ถ๐—ณ๐˜ we receive from AWS:

the execution of the global code outside of your handler method will be executed with high memory & CPU settings and ๐—ถ๐˜€๐—ป'๐˜ ๐—ฏ๐—ถ๐—น๐—น๐—ฒ๐—ฑ for the first 10s.

Make use of this by bootstrapping your core framework outside.

{ 10/31 }
๐—ฅ๐˜‚๐—ป๐˜๐—ถ๐—บ๐—ฒ๐˜€

Lambda supports everything you can think of, ranging from Node.js, over Ruby & Python to Java.

Not finding your preference?
You can bring your ๐—ผ๐˜„๐—ป ๐—ฟ๐˜‚๐—ป๐˜๐—ถ๐—บ๐—ฒ.

docs.aws.amazon.com/lambda/latest/โ€ฆ

{ 11/31 }
๐—Ÿ๐—ฎ๐˜†๐—ฒ๐—ฟ๐˜€

When your function is executed, all the dependencies it needs have to be bundled into your deployment unit.

If you're using for example Node.js, your node_modules can easily reach 100MB.

You don't want to package & deploy this every time.

{ 12/31 }
This is surely true, as dependencies in comparison to your business logic code rarely change or get updated

With Layers, you can bundle your dependencies separately and then attach them to ๐—ผ๐—ป๐—ฒ or ๐˜€๐—ฒ๐˜ƒ๐—ฒ๐—ฟ๐—ฎ๐—น ๐—ณ๐˜‚๐—ป๐—ฐ๐˜๐—ถ๐—ผ๐—ป๐˜€

Next time, only deploy your code!

{ 13/31 }
๐—ฆ๐—ฒ๐—ฐ๐˜‚๐—ฟ๐—ถ๐˜๐˜†

As with other services, your function is protected via IAM
By default, there's no ingress traffic possible to your function, but all egress to the internet

You can assign your function to a VPC to access other services there, but you don't have to

{ 14/31 }
๐—ฉ๐—ฒ๐—ฟ๐˜€๐—ถ๐—ผ๐—ป๐—ถ๐—ป๐—ด & ๐—”๐—น๐—ถ๐—ฎ๐˜€๐—ฒ๐˜€

You can use aliases when updating your functions, to have your Lambdas versioned.

This enables you to do things like canary deployments by using weighted aliases, e.g. only sending 20% of traffic to your updated function.

{ 15/31 }
๐—ฃ๐—ฟ๐—ผ๐˜ƒ๐—ถ๐˜€๐—ถ๐—ผ๐—ป๐—ฒ๐—ฑ ๐—–๐—ผ๐—ป๐—ฐ๐˜‚๐—ฟ๐—ฟ๐—ฒ๐—ป๐—ฐ๐˜†

Reduce your latency fluctuations by keeping instances provisioned.
This introduces significantly higher pricing though.

Also, deployments of your function will take more time as your version needs publishing.

{ 16/31 }
๐—ฅ๐—ฒ๐˜€๐—ฒ๐—ฟ๐˜ƒ๐—ฒ๐—ฑ ๐—–๐—ผ๐—ป๐—ฐ๐˜‚๐—ฟ๐—ฟ๐—ฒ๐—ป๐—ฐ๐˜†

Assign dedicated reservations of parallel executions for your function.
This means this number will be subtracted from your default account soft limit of 1000 parallel executions (can be increased via the support)

{ 17/31 }
It guarantees that this concurrency level is always possible for your function.

What it also ensures: ๐˜๐—ต๐—ถ๐˜€ ๐—ฐ๐—ผ๐—ป๐—ฐ๐˜‚๐—ฟ๐—ฟ๐—ฒ๐—ป๐—ฐ๐˜† ๐—น๐—ฒ๐˜ƒ๐—ฒ๐—น ๐—ฐ๐—ฎ๐—ป'๐˜ ๐—ฏ๐—ฒ ๐—ฒ๐˜…๐—ฐ๐—ฒ๐—ฒ๐—ฑ๐—ฒ๐—ฑ!

The wording's not the best, as reserved and provisioned concurrency are often confused.

{ 18/31 }
๐—Ÿ๐—ฎ๐—บ๐—ฏ๐—ฑ๐—ฎ@๐—˜๐—ฑ๐—ด๐—ฒ

Lambda's not only good for computation workloads or REST backends.
You can also use them with CloudFront.

It enables you to execute code at different times when your CloudFront distribution is called.

{ 19/31 }
By that you can for example easily implement authorization rules or change destinations for your origin.

Generally, you can do a lot as you're also able to use the AWS-SDK and invoke other services.

Another tip: CloudFront functions - the lightweight alternative!

{ 20/31 }
๐—•๐—ฒ๐—ป๐—ฒ๐—ณ๐—ถ๐˜๐˜€ of using Lambda

โ€ข reduce operations: package & run your code
โ€ข out-of-the-box scalability: โšก๏ธ-fast horizontal scaling
โ€ข pay-as-you-go: only pay for what you're using
โ€ข agility & development speed: reducing burdens & increasing productivity

{ 21/31 }
๐——๐—ผ๐˜„๐˜€๐—ถ๐—ฑ๐—ฒ๐˜€

โ€ข cold-starts
โ€ข higher abstraction but lower predictability
โ€ข pricing: depending on your workload & traffic, Lambda can be a cost pitfall
โ€ข vendor-lock: compared to container-based apps, it's more difficult to migrate to another provider

{ 22/31 }
๐—ข๐—ฏ๐˜€๐—ฒ๐—ฟ๐˜ƒ๐—ฎ๐—ฏ๐—ถ๐—น๐—ถ๐˜๐˜†

Still, a goliath task is having in-depth observability for your lambda-powered architecture.
Mostly, you'll design event-driven, async architectures that involve a lot of other services like SQS.

So there's not just an HTTP 500 to find.

{ 23/31 }
CloudWatch helps you a lot in the first place with Metrics & Alerts.
A lot of them are predefined, like:

โ€ข Lambda Errors: your function did not finish with exit code 0
โ€ข Throttles: concurrency limit was exceeded

Familiarize yourself with CloudWatch possibilities!

{ 24/31 }
CloudWatch has its limitations and the Console Interface is still painfully to use for certain tasks like log browsing and having a complete solution needs a lot of work.

Third-party tools which are mostly easy to set up are helping a lot.

{ 25/31 }
My biased proposal:

Try out @thedashbird for free - an all-embracing monitoring and debugging tool for serverless applications powered by Lambda.

If you've got questions, feedback or you're missing a feature: send me a DM ๐Ÿ“จ
We can work something out ๐Ÿง‘โ€๐Ÿ’ป

{ 26/31 }
๐—–๐—ผ๐—ป๐˜€๐—ถ๐—ฑ๐—ฒ๐—ฟ๐—ฎ๐˜๐—ถ๐—ผ๐—ป๐˜€ ๐˜๐—ผ ๐—บ๐—ฎ๐—ธ๐—ฒ

Don't just blindly build a new service with Lambda.
Do an in-depth requirements analysis before and think about your use-cases.

Understand what you want & make sure ๐˜๐—ต๐—ฒ ๐˜€๐—ฒ๐—ฟ๐˜ƒ๐—ฒ๐—ฟ๐—น๐—ฒ๐˜€๐˜€ ๐—ฎ๐—ฝ๐—ฝ๐—ฟ๐—ผ๐—ฎ๐—ฐ๐—ต ๐—ณ๐—ถ๐˜๐˜€!

{ 27/31 }
Answer these questions:

1. Does the service need to maintain a ๐—ฐ๐—ฒ๐—ป๐˜๐—ฟ๐—ฎ๐—น ๐˜€๐˜๐—ฎ๐˜๐—ฒ?
2. Does the service need to serve requests ๐˜ƒ๐—ฒ๐—ฟ๐˜† ๐—ณ๐—ฟ๐—ฒ๐—พ๐˜‚๐—ฒ๐—ป๐˜๐—น๐˜†?
3. Is the architecture rather ๐—บ๐—ผ๐—ป๐—ผ๐—น๐—ถ๐˜๐—ต๐—ถ๐—ฐ instead built of small, loosely coupled parts?

{ 28/31 }
4. Is it ๐˜„๐—ฒ๐—น๐—น ๐—ธ๐—ป๐—ผ๐˜„๐—ป how the service needs to ๐˜€๐—ฐ๐—ฎ๐—น๐—ฒ ๐—ผ๐˜‚๐˜ on a daily or weekly basis and as well the expected traffic in the future?
5. Are processes mostly revolving around ๐˜€๐˜†๐—ป๐—ฐ๐—ต๐—ฟ๐—ผ๐—ป๐—ผ๐˜‚๐˜€ ๐—ผ๐—ฝ๐—ฒ๐—ฟ๐—ฎ๐˜๐—ถ๐—ผ๐—ป๐˜€?

The more ๐—ก๐—ผ๐˜€, the better!

{ 29/31 }
If you've answered one or more questions with yes, likely a "classical" containerized approach with ECS can be a better solution.

I love Lambda and taking a serverless approach, but ๐—ถ๐˜ ๐—ป๐—ฒ๐—ฒ๐—ฑ๐˜€ ๐˜๐—ผ ๐—ณ๐—ถ๐˜ ๐˜†๐—ผ๐˜‚๐—ฟ ๐—ด๐—ผ๐—ฎ๐—น๐˜€.

{ 30/31 }
Lambda is continuously ๐—ถ๐—บ๐—ฝ๐—ฟ๐—ผ๐˜ƒ๐—ฒ๐—ฑ!

Since I've started with Lambda in 2018, AWS introduced among other things:

โ€ข AWS Hyperplane for running Lambda smoothly attached to VPCs
โ€ข fine-grained billing in 1ms periods
โ€ข running Lambda on Gravity ARM processors

{ 31/31 }
๐—™๐—ถ๐—ป๐—ฎ๐—น ๐˜๐—ต๐—ผ๐˜‚๐—ด๐—ต๐˜๐˜€

There's no way to think about the cloud world without Lambda - it's here to stay
Take time to explore it and start building!

Drop me a message for advice on your cloud journey! โœ๏ธ

As Always: Happy about a โ™ป๏ธ &โค๏ธ of the initial post!

Thank you! ๐Ÿ™Œ

โ€ข โ€ข โ€ข

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

Keep Current with Tobias Schmidt

Tobias Schmidt 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 @tpschmidt_

13 Oct
๐Ÿ“š AWS 1x1 - ๐——๐˜†๐—ป๐—ฎ๐—บ๐—ผ๐——๐—• ๐Ÿ’พ

My personal holy grail of database solutions & one of AWS' flagship services

An all-embracing mega-thread ๐Ÿงตโ†“
๐—ง๐—ต๐—ฟ๐—ฒ๐—ฎ๐—ฑ ๐—ข๐˜ƒ๐—ฒ๐—ฟ๐˜ƒ๐—ถ๐—ฒ๐˜„

โ€ข Introduction
โ€ข Provisioned vs On-Demand Capacity
โ€ข Basic Concepts
โ€ข Keys & Attributes
โ€ข Retrieving Items
โ€ข Race Conditions
โ€ข Expressions
โ€ข Indexes
โ€ข Streams
โ€ข Security
โ€ข Backups
โ€ข Global Tables
โ€ข Observability

{ 1/38 }
๐—œ๐—ป๐˜๐—ฟ๐—ผ๐—ฑ๐˜‚๐—ฐ๐˜๐—ถ๐—ผ๐—ป

Why should you care about DynamoDB?

It's managed, highly available & scales on-demand with low latencies.

For getting you hooked, at Prime Days 2021 DynamoDB served ๐Ÿด๐Ÿต.๐Ÿฎ ๐—บ๐—ถ๐—น๐—น๐—ถ๐—ผ๐—ป ๐—ฟ๐—ฒ๐—พ๐˜‚๐—ฒ๐˜€๐˜๐˜€/๐˜€๐—ฒ๐—ฐ๐—ผ๐—ป๐—ฑ at its peak.

{ 2/38 }
Read 40 tweets
12 Oct
Unpopular opinion: building a successful SaaS product is ๐—ต๐—ฎ๐—ฟ๐—ฑ

Yes, Twitter feels like everybody launches something & immediately goes to $10k MRR

๐—ฅ๐—ฒ๐—ฎ๐—น๐—ถ๐˜๐˜† ๐—ถ๐˜€ ๐—ฑ๐—ถ๐—ณ๐—ณ๐—ฒ๐—ฟ๐—ฒ๐—ป๐˜

I'm still in the early stages & already got a lot of lessons learned โ†“
๐—Ÿ๐—ฎ๐˜‚๐—ป๐—ฐ๐—ต ๐—ฒ๐—ฎ๐—ฟ๐—น๐˜†

Maybe you've got another dozen ideas for features you think are needed for your MVP.
But until you've launched and you've got actual (paying) users, you've got no guarantee that your business case is even valid.

Keep your scope as small as possible.
๐—ฃ๐—ฒ๐—ฟ๐—ณ๐—ฒ๐—ฐ๐˜๐—ถ๐—ผ๐—ป๐—ถ๐˜€๐—บ ๐—ถ๐˜€ ๐—ฏ๐—ฎ๐—ฑ

Intersects with the previous point: don't make the shinest code, with 100% code coverage and the perfect architecture, as it requires way too much effort.

Don't over or underdo it.
Make it work & manageable.
Read 9 tweets
11 Oct
๐—œ๐˜'๐˜€ ๐—ฒ๐—ฎ๐˜€๐˜† & ๐—ฐ๐—ผ๐—บ๐—ณ๐—ผ๐—ฟ๐˜๐—ฎ๐—ฏ๐—น๐—ฒ ๐˜๐—ผ ๐˜€๐˜๐—ฎ๐˜† ๐˜„๐—ต๐—ฒ๐—ฟ๐—ฒ ๐˜†๐—ผ๐˜‚ ๐—ฎ๐—ฟ๐—ฒ

Working at the same company for years.
In the same project.
In the same team.
At the same product.

No need to prove yourself anymore.

Maybe that's exactly why you should think about leaving โ†“
๐—˜๐˜ƒ๐—ฎ๐—น๐˜‚๐—ฎ๐˜๐—ถ๐—ป๐—ด ๐˜†๐—ผ๐˜‚๐—ฟ ๐˜€๐—ถ๐˜๐˜‚๐—ฎ๐˜๐—ถ๐—ผ๐—ป

You've gained respect & trust in your current position.
Maybe you've got promoted.
You know your craft.

Life's good.

Why should you leave into some uncertainty?
Why taking risks?

Because there's a lot to ๐—ด๐—ฎ๐—ถ๐—ป!

{ 1/8 }
๐€๐๐š๐ฉ๐ญ๐ข๐ง๐  & ๐ฌ๐ญ๐ซ๐ž๐ง๐ ๐ญ๐ก๐ž๐ง๐ข๐ง๐  ๐ฒ๐จ๐ฎ๐ซ ๐š๐ญ๐ญ๐ข๐ญ๐ฎ๐๐ž

Everything is under constant change โšก๏ธ

The new technology you've read about will probably be the standard next year.
What you're working on is probably obsolete tomorrow.

{ 2/8 }
Read 10 tweets
10 Oct
Have a look at AWS' growth of services...

Counting namespaces, the past decade is just mind-boggling ๐Ÿ™€

โ€ข 2013: 25
โ€ข 2015: 46
โ€ข 2017: 78
โ€ข 2019: 182

๐—›๐—ผ๐˜„ ๐˜๐—ผ ๐—ธ๐—ฒ๐—ฒ๐—ฝ ๐˜‚๐—ฝ ๐˜„๐—ถ๐˜๐—ต ๐˜„๐—ต๐—ฎ๐˜'๐˜€ ๐—ป๐—ฒ๐˜„? โ†“
๐—”๐—ช๐—ฆ ๐—ก๐—ฒ๐˜„๐˜€ ๐—•๐—น๐—ผ๐—ด

Guarantees to not miss out on new features or services, but also contains interesting statistics and other insights from AWS itself.
Gets updated very regularly, sometimes several times a day.

aws.amazon.com/blogs/aws/

{ 1/4 }
๐—ช๐—ต๐—ฎ๐˜'๐˜€ ๐—ก๐—ฒ๐˜„ ๐˜„๐—ถ๐˜๐—ต ๐—”๐—ช๐—ฆ?

If you're focusing on keeping up with the new capabilities AWS provides, that's your major source.
You'll learn about improvements to existing services, introductions of new ones as well as region expansions.

aws.amazon.com/new/

{ 2/4 }
Read 5 tweets
5 Oct
๐Ÿ“š ๐—–๐—น๐—ผ๐˜‚๐—ฑ ๐—–๐—ผ๐—ป๐—ฐ๐—ฒ๐—ฝ๐˜๐˜€ ๐Ÿญ๐˜…๐Ÿญ

How do dedicated servers, virtual machines, containers & functions differ? ๐Ÿค–

An overview of the different compute models โ†“
๐——๐—ฒ๐—ฑ๐—ถ๐—ฐ๐—ฎ๐˜๐—ฒ๐—ฑ ๐—ฆ๐—ฒ๐—ฟ๐˜ƒ๐—ฒ๐—ฟ๐˜€ (1/2) ๐Ÿ› 

A physical server, only utilized by you
โ€ข you have to know or guess the CPU & memory capacities you need
โ€ข high risk of overpaying (underutilized server) or under-provisioning (too much load)
๐——๐—ฒ๐—ฑ๐—ถ๐—ฐ๐—ฎ๐˜๐—ฒ๐—ฑ ๐—ฆ๐—ฒ๐—ฟ๐˜ƒ๐—ฒ๐—ฟ๐˜€ (2/2) ๐Ÿ› 

โ€ข you're able to run multiple apps, but need to make sure that you're not causing conflicts by resource sharing
โ€ข you're solely responsible for the security
โ€ข up- or downscaling is tedious & not quickly possible
Read 7 tweets
28 Sep
๐Ÿ“š AWS 1x1

ษชแด…แด‡ษดแด›ษชแด›ส- & แด€แด„แด„แด‡๊œฑ๊œฑ แดแด€ษดแด€ษขแด‡แดแด‡ษดแด› (ษชแด€แด) ๐Ÿ”‘

The concepts are crucial & being confident in them is a necessity.

From basics to advanced concepts ๐Ÿงตโ†“
For seriously working with AWS, there's no way around IAM.
Skipping to understand its core principles will bite you again and again in the future๏ธ ๐Ÿ”ฅ

Take the time to do a deep dive, so you won't be frustrated later.

{ 1/35 }
Thread Overview ๐Ÿงต

โ€ข IAMs Capabilities
โ€ข Key Terms
โ€ข Identity- & Resource-based Policies
โ€ข Securing your AWS Account
โ€ข Basics: Credentials & AWS CLI
โ€ข Dealing with "Access Denied"
โ€ข Least Privilege
โ€ข Permission Boundaries
โ€ข Tooling

{ 2/35 }
Read 37 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!

:(