Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/url/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js AWS S3 ListBucket返回所有存储桶_Node.js_Typescript_Amazon Web Services_Amazon S3 - Fatal编程技术网

Node.js AWS S3 ListBucket返回所有存储桶

Node.js AWS S3 ListBucket返回所有存储桶,node.js,typescript,amazon-web-services,amazon-s3,Node.js,Typescript,Amazon Web Services,Amazon S3,我有一个来自aws-s3的TypeScript应用程序。问题是,我拥有的凭据只允许我与特定的凭据进行读/写交互 下面是一个例子: ListBucket返回['bucket-1','bucket-2','bucket-3','bucket-4'] 但是,我的凭证/ACL只允许我使用['bucket-2'、'bucket-4'进行读/写操作 那么,如何只列出允许读/写的存储桶 以下是我的代码: const localS3Object = new AWS.S3(); // ... the localS

我有一个来自aws-s3的TypeScript应用程序。问题是,我拥有的凭据只允许我与特定的凭据进行读/写交互

下面是一个例子:

ListBucket返回['bucket-1','bucket-2','bucket-3','bucket-4']

但是,我的凭证/ACL只允许我使用['bucket-2'、'bucket-4'进行读/写操作

那么,如何只列出允许读/写的存储桶

以下是我的代码:

const localS3Object = new AWS.S3();
// ... the localS3Object is initialized with the secrets in here

localS3Object.listBuckets(function(err: AWS.AWSError, data) {
                if (err) {
                    resolve({
                        connected: false,
                        resources: undefined
                    });
                } else {
                    resolve({
                        connected: true,
                        resources: data.Buckets
                    });
                }
            });


不幸的是,没有一个真正好的方法来做你想做的事情。ListBucket操作ListAllMyBucket权限是“全部”或“无”操作。您所能做的最好的事情就是自己过滤掉bucket,可能是尝试采取一些操作listObjects maybe,并查看是否出现权限错误。无论如何都不优雅。

您的凭证允许他们列出所有存储桶(如果他们能够做到的话)。如果这不是你想要的,你可能不应该允许。