Can you restrict the maximum file size which can be uploaded to a public S3 bucket?
amazon-iam, amazon-s3, amazon-web-services
Solution
You can set minimum and maximum file size in the s3Policy you create when setting up the signed upload URK for direct browser to S3 upload.
Here is an example (JavaScript from a node.js app) - see the 'content-length-range' part at the bottom:
var s3Policy = {
'expiration': expiration,
'conditions': [{
'bucket': aws.bucket
},
['starts-with', '$key', path],
{
'acl': readType
},
{
'success_action_status': '201'
},
['starts-with', '$Content-Type', request.type],
['content-length-range', 2048, 124857600], //min and max
]
};
If the user uploads a file that exceeds S3 returns a 400 bad request with a body including a message saying that the maximum file size limit has been exceeded.
Problem
I'm building a Web App which can upload files directly to a public S3 bucket using the AWS for Browsers SDK. I would like to restrict the maximum file size which can be uploaded, and although I can do a client-side validation on the file-size, a pure client-side solution is not very robust and I would like to add a server-side validation as well. Is it possible to do this using IAM roles for the "S3:PutObject" action?