# I made an app that lets user stores images (I´m using S3 buckets for that), how can I prevent users to upload too many GB of photos so I don´t get charged a lot in my account?

**URL:** <https://awshq.com/t/i-made-an-app-that-lets-user-stores-images-i-m-using-s3-buckets-for-that-how-can-i-prevent-users-to-upload-too-many-gb-of-photos-so-i-don-t-get-charged-a-lot-in-my-account/10835>\
**Category:** AWS Compute Discussion\
**Tags:** s3\
**Created:** [May 13, 2020, 10:09pm UTC](https://awshq.com/t/i-made-an-app-that-lets-user-stores-images-i-m-using-s3-buckets-for-that-how-can-i-prevent-users-to-upload-too-many-gb-of-photos-so-i-don-t-get-charged-a-lot-in-my-account/10835 "2020-05-13T22:09:14Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![ObviousBudget6](https://awshq.com/letter_avatar_proxy/v4/letter/o/bc8723/32.png) [@ObviousBudget6](https://awshq.com/u/ObviousBudget6)\
**Post date:** [May 13, 2020, 10:09pm UTC](https://awshq.com/t/i-made-an-app-that-lets-user-stores-images-i-m-using-s3-buckets-for-that-how-can-i-prevent-users-to-upload-too-many-gb-of-photos-so-i-don-t-get-charged-a-lot-in-my-account/10835/1 "2020-05-13T22:09:14Z")

</div>

Is there any option to prevent this? My intent when doing the app was as a showcase for my portfolio (trying to get my first job as a dev) so the link will be “out there” in public for everyone to see and I would like to have some sort of control regarding how much my users write data in the AWS services I´m using (my particular concern is S3, since photos nowdays are so heavy).

* * *

**Related discussions:**

- [AWS reduced my $15k S3 bill to $10.5k after a DDoS. I still can’t pay this. What can I do?](https://awshq.com/t/aws-reduced-my-15k-s3-bill-to-10-5k-after-a-ddos-i-still-can-t-pay-this-what-can-i-do/21159)
- [DuckDB and the changing physics of analytics](https://awshq.com/t/duckdb-and-the-changing-physics-of-analytics/21548)
- [Safely giving AI access to AWS](https://awshq.com/t/safely-giving-ai-access-to-aws/21775)
- [Optimizing S3 Storage Classes?](https://awshq.com/t/optimizing-s3-storage-classes/21479)
- [[OSS, Apache-2.0] S4 Logs v1.1.1 — Rust tool for archiving or bypassing CloudWatch Logs ingest to S3](https://awshq.com/t/oss-apache-2-0-s4-logs-v1-1-1-rust-tool-for-archiving-or-bypassing-cloudwatch-logs-ingest-to-s3/21424)

---

<div class="post-metadata">

**Author:** ![Neu\_Ron](https://awshq.com/letter_avatar_proxy/v4/letter/n/eb9ed0/32.png) [@Neu\_Ron](https://awshq.com/u/Neu_Ron)\
**Post date:** [May 13, 2020, 10:13pm UTC](https://awshq.com/t/i-made-an-app-that-lets-user-stores-images-i-m-using-s3-buckets-for-that-how-can-i-prevent-users-to-upload-too-many-gb-of-photos-so-i-don-t-get-charged-a-lot-in-my-account/10835/2 "2020-05-13T22:13:44Z")

</div>

Well as an aside make sure your billing alarms are set to whatever is your budget.

When we designed an app we learned the hard way when the monthly bill was €300 which was a lot for us students.

---

<div class="post-metadata">

**Author:** ![jaridwade](https://awshq.com/letter_avatar_proxy/v4/letter/j/e9c0ed/32.png) [@jaridwade](https://awshq.com/u/jaridwade)\
**Post date:** [May 13, 2020, 10:19pm UTC](https://awshq.com/t/i-made-an-app-that-lets-user-stores-images-i-m-using-s3-buckets-for-that-how-can-i-prevent-users-to-upload-too-many-gb-of-photos-so-i-don-t-get-charged-a-lot-in-my-account/10835/3 "2020-05-13T22:19:40Z")

</div>

You could use DynamoDB to store the size of the bucket/keyspace per user and check that the size isn’t exceeded prior to uploading.

---

<div class="post-metadata">

**Author:** ![data\_addict](https://awshq.com/letter_avatar_proxy/v4/letter/d/82dd89/32.png) [@data\_addict](https://awshq.com/u/data_addict)\
**Post date:** [May 13, 2020, 10:36pm UTC](https://awshq.com/t/i-made-an-app-that-lets-user-stores-images-i-m-using-s3-buckets-for-that-how-can-i-prevent-users-to-upload-too-many-gb-of-photos-so-i-don-t-get-charged-a-lot-in-my-account/10835/4 "2020-05-13T22:36:38Z")

</div>

Lambda could be setup to read cloudwatch. I’m guessing all users are in the same bucket but under different prefixes. So if a certain prefix has more than the allowed volume of objects, the lambda reading from cloudwatch could trigger a second lambda to delete the oldest objects.

---

<div class="post-metadata">

**Author:** ![xinehp](https://awshq.com/letter_avatar_proxy/v4/letter/x/d2c977/32.png) [@xinehp](https://awshq.com/u/xinehp)\
**Post date:** [May 13, 2020, 10:38pm UTC](https://awshq.com/t/i-made-an-app-that-lets-user-stores-images-i-m-using-s3-buckets-for-that-how-can-i-prevent-users-to-upload-too-many-gb-of-photos-so-i-don-t-get-charged-a-lot-in-my-account/10835/5 "2020-05-13T22:38:16Z")

</div>

Limitations like that will need to be in the application logic.

Amazon does not set limits on how you scale your services other than account-wide service limits, which you can only increase via service ticket.

---

<div class="post-metadata">

**Author:** ![billymcnilly](https://awshq.com/letter_avatar_proxy/v4/letter/b/22d042/32.png) [@billymcnilly](https://awshq.com/u/billymcnilly)\
**Post date:** [May 13, 2020, 11:56pm UTC](https://awshq.com/t/i-made-an-app-that-lets-user-stores-images-i-m-using-s3-buckets-for-that-how-can-i-prevent-users-to-upload-too-many-gb-of-photos-so-i-don-t-get-charged-a-lot-in-my-account/10835/6 "2020-05-13T23:56:48Z")

</div>

> [@Neu\_Ron](#):
>
> Well as an aside make sure your billing alarms are set to whatever is your budget. When we designed an app we learned the hard way when the monthly bill was €300 which was a lot for us students.

This is probably the best suggestion in terms of simplicity. I wish AWS turned on a ~$20 billing alarm by default.

Do you know how long the delay is between service usage and billing accrual/alarm? I believe in the past it was 12h+, not sure if it’s less now.

---

<div class="post-metadata">

**Author:** ![LD2083](https://awshq.com/letter_avatar_proxy/v4/letter/l/ccd318/32.png) [@LD2083](https://awshq.com/u/LD2083)\
**Post date:** [May 14, 2020, 12:25am UTC](https://awshq.com/t/i-made-an-app-that-lets-user-stores-images-i-m-using-s3-buckets-for-that-how-can-i-prevent-users-to-upload-too-many-gb-of-photos-so-i-don-t-get-charged-a-lot-in-my-account/10835/7 "2020-05-14T00:25:04Z")

</div>

As mentioned previously, this should be handled by the application. Here’s a thought:

A user has one account. The account has a column that tracks total\_user\_data. When an image is uploaded/deleted by the user, add or subtract the photo size to/from the account’s total\_user\_data column:

account.total\_user\_data += image.size  
account.total\_user\_data -= image.size

The total user data can then be shown to the user and throttled by the application. If the threshold is met, deactivate your image upload form.

If you want to run reports, do a query on all accounts and just add the total\_user\_data column.

Edit: If a total application target threshold is met, disable signups.

---

<div class="post-metadata">

**Author:** ![chaospatterns](https://awshq.com/letter_avatar_proxy/v4/letter/c/d2c977/32.png) [@chaospatterns](https://awshq.com/u/chaospatterns)\
**Post date:** [May 14, 2020, 12:25am UTC](https://awshq.com/t/i-made-an-app-that-lets-user-stores-images-i-m-using-s3-buckets-for-that-how-can-i-prevent-users-to-upload-too-many-gb-of-photos-so-i-don-t-get-charged-a-lot-in-my-account/10835/8 "2020-05-14T00:25:41Z")

</div>

> [@data\_addict](#):
>
> Lambda could be setup to read cloudwatch. I’m guessing all users are in the same bucket but under different prefixes. So if a certain prefix has more than the allowed volume of objects, the lambda reading from …

This is going to be expensive. It’s either going require n S3 buckets which you shouldn’t do, the paid metrics for each prefix, or scanning the bucket each time.

Its better to calculate the size as you ingest new images.

---

<div class="post-metadata">

**Author:** ![kyerussell](https://awshq.com/letter_avatar_proxy/v4/letter/k/94ad74/32.png) [@kyerussell](https://awshq.com/u/kyerussell)\
**Post date:** [May 14, 2020, 12:25am UTC](https://awshq.com/t/i-made-an-app-that-lets-user-stores-images-i-m-using-s3-buckets-for-that-how-can-i-prevent-users-to-upload-too-many-gb-of-photos-so-i-don-t-get-charged-a-lot-in-my-account/10835/9 "2020-05-14T00:25:52Z")

</div>

> [@billymcnilly](#):
>
> This is probably the best suggestion in terms of simplicity. I wish AWS turned on a ~$20 billing alarm by default. Do you know how long the delay is between service usage and billing accrual/alarm? I believe in the …

It is my experience that it takes 12h+ for all charges to show up in Cost Explorer, so I imagine the alarms have the same limitations.

---

<div class="post-metadata">

**Author:** ![LogicalHurricane](https://awshq.com/letter_avatar_proxy/v4/letter/l/94ad74/32.png) [@LogicalHurricane](https://awshq.com/u/LogicalHurricane)\
**Post date:** [May 14, 2020, 12:29am UTC](https://awshq.com/t/i-made-an-app-that-lets-user-stores-images-i-m-using-s3-buckets-for-that-how-can-i-prevent-users-to-upload-too-many-gb-of-photos-so-i-don-t-get-charged-a-lot-in-my-account/10835/10 "2020-05-14T00:29:56Z")

</div>

First and foremost – how are users uploading images/objects to S3? Do they have to login? Do they upload directly to S3 from their browsers or are you using a proxy (e.g. Api Gateway, ALB) that triggers some backend code that process the file and saves it to S3?

---

<div class="post-metadata">

**Author:** ![wroteit](https://awshq.com/letter_avatar_proxy/v4/letter/w/dbc845/32.png) [@wroteit](https://awshq.com/u/wroteit)\
**Post date:** [May 14, 2020, 12:47am UTC](https://awshq.com/t/i-made-an-app-that-lets-user-stores-images-i-m-using-s3-buckets-for-that-how-can-i-prevent-users-to-upload-too-many-gb-of-photos-so-i-don-t-get-charged-a-lot-in-my-account/10835/11 "2020-05-14T00:47:28Z")

</div>

One way I can think of from top of my head at the moment is presigned url with separate lambda function to generate presigned url with custom policy and record stored meta data such as client IpAddress and request counter in DynamoDB.

Your application can invoke or callback to alb endpoint target group attached to labmda and pass request with predefined parameters so that helper function can query DynamoDB for client IpAddress and counter for number of request made so far from that IpAddress).

Another method is to use API Gateway instead of attaching the lambda function to ALB. API Gateway can be adjusted to limit throttle as well as lambda invocation rate.

it’s pretty crude idea based on rate limiting by number of presigned url generation, but you get the gist of it.

But at the end of the day, it would be either doing all in your stack or aws resource do it for you. Regardless it would all come down to which would be most cost effective. $0.023 per GB upload to S3 or $0.0225 per hour ALB with $0.20 per million lambda requests and however-much total data-ingress payload.

---

<div class="post-metadata">

**Author:** ![therico](https://awshq.com/letter_avatar_proxy/v4/letter/t/35a633/32.png) [@therico](https://awshq.com/u/therico)\
**Post date:** [May 14, 2020, 12:58am UTC](https://awshq.com/t/i-made-an-app-that-lets-user-stores-images-i-m-using-s3-buckets-for-that-how-can-i-prevent-users-to-upload-too-many-gb-of-photos-so-i-don-t-get-charged-a-lot-in-my-account/10835/12 "2020-05-14T00:58:29Z")

</div>

Use presigned URLs which can be rate limited and have custom limits on size.

---

<div class="post-metadata">

**Author:** ![InsufficientInterest](https://awshq.com/letter_avatar_proxy/v4/letter/i/b5e925/32.png) [@InsufficientInterest](https://awshq.com/u/InsufficientInterest)\
**Post date:** [May 14, 2020, 1:01am UTC](https://awshq.com/t/i-made-an-app-that-lets-user-stores-images-i-m-using-s3-buckets-for-that-how-can-i-prevent-users-to-upload-too-many-gb-of-photos-so-i-don-t-get-charged-a-lot-in-my-account/10835/13 "2020-05-14T01:01:35Z")

</div>

What are you trying to showcase in your portfolio with your app? Is it the uploader itself? The UX? You can set you bucket to delete objects after a certain amount of time. If it is not a production app then no need to keep them forever. And simply set limits on what you are allowed to upload.

---

<div class="post-metadata">

**Author:** ![Chef619](https://awshq.com/letter_avatar_proxy/v4/letter/c/eb8c5e/32.png) [@Chef619](https://awshq.com/u/Chef619)\
**Post date:** [May 14, 2020, 1:25am UTC](https://awshq.com/t/i-made-an-app-that-lets-user-stores-images-i-m-using-s3-buckets-for-that-how-can-i-prevent-users-to-upload-too-many-gb-of-photos-so-i-don-t-get-charged-a-lot-in-my-account/10835/14 "2020-05-14T01:25:45Z")

</div>

> [@xinehp](#):
>
> Limitations like that will need to be in the application logic. Amazon does not set limits on how you scale your services other than account-wide service limits, which you can only increase via service ticket.

I see lots of solutions to check if a large file was upload, but I think you’re spot on. Check before uploading, in the application.

---

<div class="post-metadata">

**Author:** ![mslesfs](https://awshq.com/letter_avatar_proxy/v4/letter/m/6bbea6/32.png) [@mslesfs](https://awshq.com/u/mslesfs)\
**Post date:** [May 14, 2020, 1:46am UTC](https://awshq.com/t/i-made-an-app-that-lets-user-stores-images-i-m-using-s3-buckets-for-that-how-can-i-prevent-users-to-upload-too-many-gb-of-photos-so-i-don-t-get-charged-a-lot-in-my-account/10835/15 "2020-05-14T01:46:55Z")

</div>

I’d recommend setting up a lifecycle policy on the bucket to delete objects after x days if you don’t need to store the object for long term. It’ll keep your cost down and simple to implement.

---

<div class="post-metadata">

**Author:** ![jwjody](https://awshq.com/letter_avatar_proxy/v4/letter/j/76d3ee/32.png) [@jwjody](https://awshq.com/u/jwjody)\
**Post date:** [May 14, 2020, 2:19am UTC](https://awshq.com/t/i-made-an-app-that-lets-user-stores-images-i-m-using-s3-buckets-for-that-how-can-i-prevent-users-to-upload-too-many-gb-of-photos-so-i-don-t-get-charged-a-lot-in-my-account/10835/16 "2020-05-14T02:19:48Z")

</div>

Is this a product you’re trying to make available to people? Or just a proof of concept to show off work?

If it’s just a PoC why not automatically delete all data in the buckets after a day or two?

---

<div class="post-metadata">

**Author:** ![CharlesStross](https://awshq.com/letter_avatar_proxy/v4/letter/c/ecae2f/32.png) [@CharlesStross](https://awshq.com/u/CharlesStross)\
**Post date:** [May 14, 2020, 2:48am UTC](https://awshq.com/t/i-made-an-app-that-lets-user-stores-images-i-m-using-s3-buckets-for-that-how-can-i-prevent-users-to-upload-too-many-gb-of-photos-so-i-don-t-get-charged-a-lot-in-my-account/10835/17 "2020-05-14T02:48:49Z")

</div>

> [@jaridwade](#):
>
> You could use DynamoDB to store the size of the bucket/keyspace per user and check that the size isn’t exceeded prior to uploading.

If you do this based on submitted upload size/decoupled from S3, you might get a little bit off sometimes but you’ll probably save some money by not needing to enable the deeper logging via cloudwatch etc. that will enable you to make decisions based of that. +/- a few megs per user is almost certainly cheaper than logging/infra to enable deeper S3 inspection.

---

<div class="post-metadata">

**Author:** ![so0k](https://awshq.com/letter_avatar_proxy/v4/letter/s/6f9a4e/32.png) [@so0k](https://awshq.com/u/so0k)\
**Post date:** [May 14, 2020, 3:14am UTC](https://awshq.com/t/i-made-an-app-that-lets-user-stores-images-i-m-using-s3-buckets-for-that-how-can-i-prevent-users-to-upload-too-many-gb-of-photos-so-i-don-t-get-charged-a-lot-in-my-account/10835/18 "2020-05-14T03:14:25Z")

</div>

> [@Chef619](#):
>
> I see lots of solutions to check if a large file was upload, but I think you’re spot on. Check before uploading, in the application.

The policy document signed to allow upload can limit it

---

<div class="post-metadata">

**Author:** ![x86\_64Ubuntu](https://awshq.com/letter_avatar_proxy/v4/letter/x/a9adbd/32.png) [@x86\_64Ubuntu](https://awshq.com/u/x86_64Ubuntu)\
**Post date:** [May 14, 2020, 4:01am UTC](https://awshq.com/t/i-made-an-app-that-lets-user-stores-images-i-m-using-s3-buckets-for-that-how-can-i-prevent-users-to-upload-too-many-gb-of-photos-so-i-don-t-get-charged-a-lot-in-my-account/10835/19 "2020-05-14T04:01:31Z")

</div>

> [@so0k](#):
>
> The policy document signed to allow upload can limit it

Limit size? Do you have a doc or source for this. Not coming after you, I’m genuinely interested.

---

<div class="post-metadata">

**Author:** ![so0k](https://awshq.com/letter_avatar_proxy/v4/letter/s/6f9a4e/32.png) [@so0k](https://awshq.com/u/so0k)\
**Post date:** [May 14, 2020, 4:06am UTC](https://awshq.com/t/i-made-an-app-that-lets-user-stores-images-i-m-using-s3-buckets-for-that-how-can-i-prevent-users-to-upload-too-many-gb-of-photos-so-i-don-t-get-charged-a-lot-in-my-account/10835/20 "2020-05-14T04:06:22Z")

</div>

> [@x86\_64Ubuntu](#):
>
> Limit size? Do you have a doc or source for this. Not coming after you, I’m genuinely interested.

In the past we did the signing in our back end

[https://docs.aws.amazon.com/AmazonS3/latest/API/sigv4-HTTPPOSTConstructPolicy.html](https://docs.aws.amazon.com/AmazonS3/latest/API/sigv4-HTTPPOSTConstructPolicy.html)

Today you’d do it like all the other comments in this thread and use a lambda

[Next page](https://awshq.com/t/i-made-an-app-that-lets-user-stores-images-i-m-using-s3-buckets-for-that-how-can-i-prevent-users-to-upload-too-many-gb-of-photos-so-i-don-t-get-charged-a-lot-in-my-account/10835.md?page=2)
