简体   繁体   English

如何允许 Cognito 用户池用户删除 S3 中的对象?

[英]How to allow Cognito user pool users to delete objects in S3?

My mobile app uses AWS Amplify and i have a Cognito user pool and an S3 bucket in the project.我的移动应用程序使用 AWS Amplify,我在项目中有一个 Cognito 用户池和一个 S3 存储桶。 Users are able to put objects into the bucket no problem, but they cant delete.用户可以将对象放入桶中没问题,但不能删除。 What i want to do is for each logged in user to be able to delete an file in the bucket.我想要做的是让每个登录用户都能够删除存储桶中的文件。

The path to the files is for example: my_bucket_name/protected/eu-west-2:de55c2rf-8f1e-836d-88f9-82da662aau6dt/videos/video1文件路径例如: my_bucket_name/protected/eu-west-2:de55c2rf-8f1e-836d-88f9-82da662aau6dt/videos/video1

To delete, i call this:要删除,我称之为:

import { Storage } from 'aws-amplify'; 
import Amplify, { Auth } from 'aws-amplify';

. . . . . .

delFromS3 = async () => {
      Storage.remove('protected/eu-west-2:de55c2rf-8f1e-836d-88f9-82da662aau6dt/videos/video1')  
         .then(result => console.log('Deleted Video from S3'))
         .catch(err => console.log('Deleting video from S3 error: ', err));
  }

So i either need a way to allow users in the cognito user pool to be authorised to delete an object.所以我要么需要一种方法来允许认知用户池中的用户被授权删除一个对象。 Or because i manually know the path to the file in each users sub-bucket (eg /protected/eu-west-2:de55c2rf-8f1e-836d-88f9-82da662aau6dt/videos/video1 ) just pass that in my delFromS3() function.或者因为我手动知道每个用户子存储桶中文件的路径(例如/protected/eu-west-2:de55c2rf-8f1e-836d-88f9-82da662aau6dt/videos/video1 )只需在我的delFromS3()函数中传递它. I don't think this is a bucket policy issue.我不认为这是存储桶策略问题。

OR if i need to use an Identity pool, how do I allow all the users in my existing user pool to work with the automatically generated Identity pool to enable them to delete in S3?或者,如果我需要使用身份池,我如何允许现有用户池中的所有用户使用自动生成的身份池来使他们能够在 S3 中删除? At the moment users use Cognito to get into the user pool using Auth.signIn()目前用户使用 Cognito 使用Auth.signIn()进入用户池

I'd call an API and in your Lambda check security / who it is and if they have access to remove file.. You may be able to check amplify user characteristics from policy, haven't tried..我会调用一个 API 并在您的 Lambda 中检查安全性/它是谁以及他们是否有权删除文件。

But the extra api gives you another layer for security if desired in future但是如果将来需要,额外的 api 会为您提供另一层安全性

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

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