[英]how do you create s3 subdirectories using aws cdk?
if I wanted to create a bucket with a layout like this:如果我想创建一个布局如下的桶:
bucket/
├─ subdir-1/
│ ├─ subsubdir-1/
├─ subdir-2/
├─ subdir-3/
how could I do this using the cdk?我怎么能用 cdk 做到这一点? Or even a yml cf template?
甚至是 yml cf 模板?
As mentioned in the comment, you do not need to create directories/template.如评论中所述,您不需要创建目录/模板。 When you use SDK/CLI to upload an object, it will automatically create the folder/structure matching the key used when uploading the object. You may be able to create empty directories through CLI/SDK but I don't think aws-cdk would do that as it is not supposed to managed the content of S3.
当您使用 SDK/CLI 上传 object 时,它会自动创建与上传 object 时使用的密钥匹配的文件夹/结构。您可以通过 CLI/SDK 创建空目录,但我认为 aws-cdk 不会这样做是因为它不应该管理 S3 的内容。
If you really want to maintain a certain layout for the bucket, you could use bucket policy to only allow certain directory when the SDK/CLI put your object to S3.如果您真的想为存储桶维护特定布局,您可以使用存储桶策略在 SDK/CLI 将您的 object 放入 S3 时仅允许特定目录。 This policy could be added on the aws-cdk (Ref: aws-cdk-s3-docs-addPolicy ).
可以在 aws-cdk 上添加此策略(参考: aws-cdk-s3-docs-addPolicy )。 Policy example as follows.
策略示例如下。
{
"Sid": "Layout",
"Effect": "Deny",
"Principal": "*",
"Action": "s3:PutObject*",
"NotResource": [
"arn:aws:s3:::{BUCKET_NAME}/subdir-1/*",
"arn:aws:s3:::{BUCKET_NAME}/subdir-1/subdir-1/*",
"arn:aws:s3:::{BUCKET_NAME}/subdir-2/*",
"arn:aws:s3:::{BUCKET_NAME}/subdir-3/*",
]
}
More detail on s3 bucket policy: https://docs.aws.amazon.com/AmazonS3/latest/userguide/example-bucket-policies.html有关 s3 存储桶策略的更多详细信息: https://docs.aws.amazon.com/AmazonS3/latest/userguide/example-bucket-policies.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.