简体   繁体   English

仅允许小写文件的 AWS S3 存储桶策略

[英]AWS S3 Bucket Policy to allow only lowercase files

Is it possible to limit s3 bucket to lowercase files/directories only?是否可以将 s3 存储桶限制为仅小写文件/目录?

Some downstream systems are case insensitive so I want to prevent any issues.一些下游系统不区分大小写,所以我想防止出现任何问题。

There's a Lambda workaround, but is it possible to specify this requirement as a bucket policy?有一个 Lambda 解决方法,但是否可以将此要求指定为存储桶策略?

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "Enforce lower-case",
            "Effect": "Deny",
            "Principal":"*",
            "Action": "s3:PutObject",
            "Resource": "arn:aws:s3:::mybucket/*",
            "Condition": {
                "StringNotEquals": {
                    "s3:KeyName": "lower(s3:KeyName)"
                }
            }
        }
    ]
}

No, that is not possible because:不,那是不可能的,因为:

  • String manipulation isn't allowed in IAM policy IAM 策略中不允许进行字符串操作
  • IAM string condition operators do not support regular expressions IAM 字符串条件运算符不支持正则表达式

An alternative approach would be to have the S3 bucket trigger an AWS Lambda function, which could:另一种方法是让 S3 存储桶触发 AWS Lambda function,这可以:

  • Examine the object Key检查 object Key
  • If the Key is not strictly lowercase, then Copy the object to a new lowercase Key and delete the original object如果Key不是严格小写,则将object Copy为新的小写Key,并删除原来的object

However, it would mean that Foo would rename to foo and a later FOO would overwrite foo .但是,这意味着Foo将重命名为foo并且稍后的FOO将覆盖foo

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM