I am learning AWS , and came across hosting static websites using Amazon S3 and distributing to edge locations using Cloud Front and Route53.
I know that for Cloud front we pay for what we use. So my monthly bill will reflect the number of requests I get once the free tier is over.
My question is what if a hacker or someone sends a lots of requests like spamming, then will I be charged higher?
How to prevent this and does AWS has any security measures like limiting the number of requests to serve per minute or something for this ?
Pardon me if my question is very basic. I am just learning . Thanks
My question is what if a hacker or someone sends a lots of requests like spamming, then will I be charged higher?
Yes. You are charged a per-request price, as well as data transfer charges. The per-request charges are relatively low, but if they find a large file to download they can quickly run up the bandwidth charge.
does AWS has any security measures like limiting the number of requests to serve per minute or something for this ?
Yes, you want WAF, the Web Application Firewall. With it you can configure a rate-limited rule that will block an IP address after N requests within a five-minute period.
As I know you pay for Caches Invalidations on AWS but not for a number of requests done to your CloudFront distributions.
Related
I created a new (not even a week old) public S3-bucket to access some files remotely (it has to be public - that is the crux). Things like logging and versioning are deactivated, and pretty much all the standard options were kept.
However, I have a huge amount of requests per day (over 3000requests per day and maybe even increasing) that is not connected at all to my assessing of the files. Where does such a traffic come from? Does amazon access the files itself by default? Something like a tracking of the files? Can this be deactivated?
You can activate Amazon S3 server access logging to obtain this information. The logs will show the requests and their origin.
FYI, requests are charged at $0.0004 per 1000, therefore your 3000 requests per day are costing 1.2c per day.
I'm hosting a static website in Amazon S3 with CloudFront. Is there a way to set a limit for how many reads (for example per month) will be allowed for my Amazon S3 bucket in order to make sure I don't go above my allocated budget?
If you are concerned about going over a budget, I would recommend Creating a Billing Alarm to Monitor Your Estimated AWS Charges.
AWS is designed for large-scale organizations that care more about providing a reliable service to customers than staying within a particular budget. For example, if their allocated budget was fully consumed, they would not want to stop providing services to their customers. They might, however, want to tweak their infrastructure to reduce costs in future, such as changing the Price Class for a CloudFront Distribution or using AWS WAF to prevent bots from consuming too much traffic.
Your static website will be rather low-cost. The biggest factor will likely be Data Transfer rather than charges for Requests. Changing the Price Class should assist with this. However, the only true way to stop accumulating Data Transfer charges is to stop serving content.
You could activate CloudTrail data read events for the bucket, create a CloudWatch Event Rule to trigger an AWS Lambda Function that increments the number of reads per object in an Amazon DynamoDB table and restrict access to the objects once a certain number of reads has been reached.
What you're asking for is a very typical question in AWS. Unfortunately with near infinite scale, comes near infinite spend.
While you can put a WAF, that is actually meant for security rather than scale restrictions. From a cost-perspective, I'd be more worried about the bandwidth charges than I would be able S3 requests cost.
Plus once you put things like Cloudfront or Lambda, it gets hard to limit all this down.
The best way to limit, is to put Billing Alerts on your account -- and you can tier them, so you get a $10, $20, $100 alerts, up until the point you're uncomfortable with. And then either manually disable the website -- or setup a lambda function to disable it for you.
How can I prevent Denial of Wallet attacks against AWS Cloudfront?
Here's my specific situation: I have a Cloudfront distribution where Lambda#Edge functions serve web pages and API requests for my application. I need to rate-limit requests made to Cloudfront based on the IP address of the user. Without any kind of rate-limiting in place, it's possible for a malicious user to make millions of slow requests to the distribution that wouldn't be blocked by AWS's DDOS protections and which would lead to significant charges. This is especially important here since Lambda#Edge functions cost 3x as much as ordinary Lambda functions and don't come with a free tier.
It seemed practical to use AWS WAF in order to accomplish this. However, I recently found out that WAF charges for all incoming requests, regardless of if they are blocked or not. So a Denial of Wallet attack would still be possible here.
Is there a method or a general strategy that I can implement here that doesn't involve AWS WAF?
The limits need to be very tight. Even paying $50 per month for malicious requests would be considered too high.
AWS Shield Standard is free when you use Cloudfront and it automatically protects against common DDoS attacks. Source
If you want to use WAF to tighten the requests to your Lambda, you can setup caching for HTTP 403 responses in Cloudfront, so the attacker won't get their request past the Cloudfront cache.
You have to decide which one is on priority for you, your service being down or your bill going above your budget? If it's the first one, you can use WAF and AWS Shield Advanced.
If it's the second one, you can implement a request throttling method. For example, you can make use of incoming requests to EC2 instances are free. So you can implement a queue in a free tier EC2 instance that forwards the requests to your Lambda but drops the requests when the rate is higher than a defined threshold. Keep in mind that you get charged for outgoing requests from EC2 to your Lambda Edge.
OR you can implement another Lambda function before your Lambda Edge to keep track of which IP address sent how many requests. If it's past the threshold, respond with HTTP 403 and have that cached in Cloudfront. Then the next request from that IP address won't reach your Lambda. But again, keep in mind that you'll get charged for this additional Lambda.
The last resort is creating a billing alarm that notifies you when monthly charges reach $50 so that you can stop the costs before it goes high.
AWS Shield Advanced includes DDoS cost protection, a safeguard from scaling charges as a result of a DDoS attack that causes usage spikes on protected Amazon EC2, Elastic Load Balancing (ELB), Amazon CloudFront, AWS Global Accelerator, or Amazon Route 53. If any of the AWS Shield Advanced protected resources scale up in response to a DDoS attack, you can request credits via the regular AWS Support channel.
Please note that, at the time of writing, this service involves a monthly fee of $3,000 per account, plus data transfer fees starting at $0.050 per GB.
I have been using the AmazonS3 service to store some files.
I have uploaded 4 videos and they are public. I'm using a third party video player for those videos (JW Player). As a new user on the AWS Free Tier, my free PUT, POST and LIST requests are almost used up from 2000 allowed requests, and for four videos that seems ridiculous.
Am I missing something or shouldn't one upload be one PUT request, I don't understand how I've hit that limit already.
The AWS Free Tier for Amazon S3 includes:
5GB of standard storage (normally $0.023 per GB)
20,000 GET requests (normally $0.0004 per 1,000 requests)
2,000 PUT requests (normally $0.005 per 1,000 requests)
In total, it is worth up to 13.3 cents every month!
So, don't be too worried about your current level of usage, but do keep an eye on charges so you don't get too many surprises. You can always Create a Billing Alarm to Monitor Your Estimated AWS Charges.
The AWS Free Tier is provided to explore AWS services. It is not intended for production usage.
It would be very hard to find out the reason for this without debugging a bit. So I would suggest you try the following debugging :
See if you have cloudtrail enabled. If yes, then you can track the API calls to S3 to see if anything is wrong there.
If you have cloudtrail enabled then it itself put data into the S3 bucket that might also take up some of the requests.
See if you have logging enabled at the bucket level, that might give you more insight on what all requests are reaching your bucket.
Your vides are public and that is the biggest concern here as you don't know who all can access it.
Setup cloudwatch alarms to avoid any surprises and try to look at logs to find out the issue.
I'm interested in hosting a website for a small business (< 100 users / month) and I wanted to try going 'serverless'. I've read that using Amazon S3, Lambda and DynamoDB is a way to set this up, by hosting the front-end on S3, using Lambda functions to access the back-end, and storing data in DynamoDB. I'll need to run a script on page load to get data to display, save user profiles/allow logins, and acccept payments using Stripe or Braintree.
Is this a good situation to use this setup, or am I better off just using EC2 with a LAMP stack? Which is better in terms of cost?
It is a perfectly good solution, and will probably cost you nothing at all to host on AWS - literally pennies a month. I host several low traffic sites this way and it works well.
The only caveat would be, since your traffic is so slow, almost every time someone hits a page, if it needs to make any back-end calls, those lambda functions will likely need a 'cold-start', which may introduce a delay and cause the page to load a bit slower than if it had more traffic that tended to keep the lambda cache 'warm'.