r/serverless • • Feb 13 '21

AWS Lessons Learned from being DDOS'd

I never thought my small site would get DDOS’d, but I guess anything that is public is ripe for abuse. Last week, I had launched 24hourwebhook.com, which provides a free webhook URL that then shares the event data by email or in a Google Sheet. I had set up an SNS topic attached to my email address to let me know when people had signed up.

I was super excited when I received an email about a new signup. The next thing I knew, my email address started getting flooded with hundreds of emails. I quickly noticed that it was just the same request coming in over and over. It was very clear that some funny business was going on.

Thank goodness for CloudWatch metrics. It became pretty clear from CloudWatch that I was receiving 60K+ requests per minute.

24hourwebhook.com is built using 100% serverless technologies: Lambda, DynamoDB, and API Gateway, and it was clear that these services had no problem keeping up with the demand. At first there was a small amount of throttling of requests by DynamoDB, but when going from 0 traffic to 60K+, a little bit of throttling is understandable. I had read about serverless scaling, but I had never experienced it first hand. It is impressive!

But every request technically costs money, so how do I make it stop? All requests were coming through API Gateway. API Gateway only has one way to throttle traffic, through Burst/Rate limit. I ended up setting up a very low limit. This seemed to make the DDOS’er think they had accomplished the tasks of taking down the site and the requests stopped.

So what were the lessons learned?

  1. API Gateway - if your endpoint doesn’t have any authentication, make sure you set a Throttling Burst/Rate limit that is reasonable for your use case.

  2. While API Gateway doesn’t support WAF, you can put CloudFront in front of API Gateway and add WAF there. That way, you can easily restrict the amount of traffic from a single IP without restricting traffic to all users.

  3. While Lambda, DynamoDB, and API Gateway scale amazingly well, email does not. Email through SNS is rate limited, so I was still receiving emails for about a day afterwards. SNS seems to have a fail-safe if too many email requests are sent, as my SNS confirmation was turned off. I learned to be careful when setting up email triggers on user actions. Switching this to CloudWatch Metrics / Alerts is a much better system to use.

  4. Billing - I found the bill quite interesting. Since I caught the abuse quite early on, it ended up being around $10, with 80% of that being DynamoDB. I don’t know why, but seeing DynamoDB take so much of the cost surprised me. I guess any database is always the most expensive part.

Hopefully these lessons will help other to avoid the mistakes that I made.

161 Upvotes

34 comments sorted by

11

u/kackstifterich Feb 13 '21

You don't have to use Cloudfront. API Gateway has been supporting WAF since late 2018: https://aws.amazon.com/about-aws/whats-new/2018/10/amazon-api-gateway-adds-support-for-aws-waf/?nc1=h_ls

5

u/formkiqmike Feb 13 '21

Sorry I forgot to add I'm using HTTP API Gateway, not REST API Gateway. I do not believe HTTP API Gateway supports it, but you are right REST API Gateway does support WAF.

4

u/smcarre Feb 13 '21

Directly from AWS' whitepaper on DDoS

When you use Amazon API Gateway, you can choose from two types of API endpoints. The first is the default option: edge optimized API endpoints that are accessed through an Amazon CloudFront distribution. The distribution is created and managed by API Gateway, however, so you don’t have control over it. The second option is to use a regional API endpoint that is accessed from the same AWS region in which your REST API is deployed. We recommend that you use the second type of endpoint, and then associate it with your own Amazon CloudFront distribution. By doing this, you have control over the Amazon CloudFront distribution and the ability to use AWS WAF for application layer protection.

3

u/formkiqmike Feb 13 '21

he distribution is created and managed by API Gateway, however, so you don’t have control over it.

YES! The 2nd option is what I ended up doing.

3

u/techmavengeospatial Feb 13 '21

Did you track down the person

3

u/formkiqmike Feb 13 '21

No, they signed up using a free mailer service. I'm kinda curious if it caused the free mailer service any issues, as 100K+ emails got sent to that temporary email account. I wasn't able to get the IP address that was sending the requests either.

3

u/maxgalbu Feb 13 '21

you can avoid signup from disposable emails, look at https://github.com/disposable/disposable-email-domains

3

u/formkiqmike Feb 13 '21

Ah great link. I was thinking about that but I didn't want to make it harder for someone to try it out for 24 hours. Something definitely to consider.

3

u/yesman_85 Feb 13 '21

You sure it was a deliberate attack and not just a runaway api?

2

u/formkiqmike Feb 13 '21

Could have been a runaway api. Either way it was definitely an abuse of the API. It seemed once the API stopped returning 200, they went away and didn't come back. Either way it was causing DDOS issues.

2

u/[deleted] Feb 14 '21

What's a runaway API?

1

u/drcforbin Feb 14 '21

An accident, a bug that causes it to go out of control. I imagine something like a crawler with logic meant in general to retry after a couple seconds if it doesn't get a 200...but with some odd bug unique to when it's crawling certain sites, causing it to retry without delay when it DOES get a 200.

2

u/temisola1 Feb 13 '21

WAF WAF WAF!!!

1

u/formkiqmike Feb 13 '21

DEFINITELY!

2

u/[deleted] Feb 14 '21

What’s waf

2

u/temisola1 Feb 14 '21

AWS Web Application Firewall.

7

u/WGU_DevOps Feb 13 '21

Wow. Kinda cool experience but very shitty of humanity.

I don't see why anyone would randomly DDOS websites in their free time. If you know enough to DDOS, you can be doing something productive.

3

u/coldflame563 Feb 13 '21

Kinda. The loic is pretty point and click

1

u/WGU_DevOps Feb 14 '21

Yeah but just knowing of it and knowing what DDOSing is.

You'd think they'd have more respect than hitting a random project.

2

u/mikebailey Feb 14 '21

Half of them are like 15 so idk about that

1

u/[deleted] Feb 14 '21

Script kiddies

1

u/TechToSpeech Feb 13 '21

Interesting - what kind of concurrency settings did you have set up on the lambda and what level of failure did you see before you configured the throttling?

1

u/formkiqmike Feb 13 '21

No concurrency set, I actually never saw any lambda failures. My concern was mainly around cost (which I'm sure AWS support would have helped with). The only thing I saw was DynamoDB throttling at the beginning.

1

u/TechToSpeech Feb 13 '21

haha, my next question then, what was the dynamo throughput set to, fixed, autoscaling, OD?

1

u/formkiqmike Feb 13 '21

Site is new and traffic is all over the place, so it's set to OnDemand right now.

1

u/TechToSpeech Feb 13 '21

Nice idea, might be tricky to monetize or break even on. You might be better off open-sourcing it and asking for donations. All of the usefulness, none of the potential liability :) Hope you've got budget alerts/actions set up!

1

u/formkiqmike Feb 13 '21

Nice idea, might

haha. Now that WAF is configured I'm hoping I won't have that problem. Definitely have alerts setup now.

With the "No-Code" movement gaining in popularity, this fits perfectly into that paradigm. Especially, now that we've added support for Google Sheets. Being able to send JSON request (like a Strip webhook) and have it update a Google Sheet is without writing any code is really powerful.

1

u/fhidas161803 Feb 13 '21

Reduce DDoS Risks Using Amazon Route 53 and AWS Shield

2

u/formkiqmike Feb 13 '21

I'm not sure how Route 53 DDOS protection could have help. It wasn't a DNS DDOS, it was a layer 7 issue. AWS Shield is pretty pricing. I have added CloudFront + WAF with Rate limiting by IP, so that hopefully is enough for now.

1

u/natefoxreddit Feb 13 '21

How long did it last? I want to know what that $10 was spent on (time wise) at 60k req/min.

1

u/formkiqmike Feb 13 '21

It lasted about 20 minutes. Looking at the bill all the DynamoDB costs were all related to WriteRequestUnits. I can't figure out the exact number, but the WriteRequestUnit peaked at about 250,000. DynamoDB was about 80% of the total cost.

2

u/TomRiha Feb 14 '21

I think you will enjoy this read https://usefathom.com/blog/ddos-attack

1

u/george_watsons1967 Feb 13 '21

had a similar thing on my own, only without SNS. it was a cheap lesson in how difficult it is to avoid your public API endpoint being DDOS'd. I wish AWS would create something against this that doesn't invole a full-on WAF setup. all in all, still amazing how well these services work and scale.

0

u/[deleted] Feb 14 '21

[deleted]

1

u/formkiqmike Feb 14 '21

I'm using HTTP not REST API Gateway which doesn't support policies as far as I'm aware.