As partially mentioned by @duskwuff if you're allowing users to upload files directly to S3 then you can restrict the size of the uploaded object via S3 Bucket Policies.
S3 Bucket Policies
A good description of an S3 Bucket policy can be found here:
S3 bucket policies specify what actions are allowed or denied for
which principals on the bucket that the bucket policy is attached to
(e.g. allow user Alice to PUT but not DELETE objects in the bucket).
There's a good collection of sample bucket policies here. Taking one of these and modifying it, a policy that would allow anyone to upload a file to an S3 bucket, but restrict the file size to 1GB is:
{
"Version": "2012-10-17",
"Id": "S3PolicyId1",
"Statement": [
{
"Sid": "AllowPublicUpload",
"Effect": "Allow",
"Principal": "*",
"Action": "s3:PutObject",
"Resource": "arn:aws:s3:::examplebucket/*",
"Condition": {
['content-length-range', 1, 1073741824] //min and max
}
}
]
}
This uses the content-length-range condition which is described here as:
The minimum and maximum allowable size for the uploaded content.
This condition supports content-length-range condition match type.
Other Considerations
If you want to limit uploads to specific users, or force users to put uploads in a home folder (i.e. a folder with a name unique to them), then you should check-out Amazon Cognito. With Cognito you'd use IAM policies containing variables that represent a Cognito User Id etc.
The last thing to remember is that an s3:PutObject can overwrite files, so keep this in mind when deciding where to allow users to upload to.