问题
I'm trying to list the paths within a file system in Azure datalake using this code :
I'm able to retrieve ${fileSystem.name} but getting permissions denied with .listPaths()
node:15660) UnhandledPromiseRejectionWarning: RestError: This request is not authorized to perform this operation using this permission.
i'm not sure what permissions I need to provide, the service principle has owner access over the datalake storage account and also has the api permissions
the code:
const { DataLakeServiceClient } = require('@azure/storage-file-datalake');
require('dotenv').config();
const account = 'xxx';
const defaultAzureCredential = new DefaultAzureCredential();
const datalakeServiceClient = new DataLakeServiceClient(
`https://${account}.dfs.core.windows.net`,
defaultAzureCredential
);
async function main() {
let i = 1;
let iter = await datalakeServiceClient.listFileSystems();
for await (const fileSystem of iter) {
console.log(`File system ${i++}: ${fileSystem.name} `);
const fileSystemClient = datalakeServiceClient.getFileSystemClient(fileSystem.name);
let iter = await fileSystemClient.listPaths();
for await (const path of iter) {
console.log(`Path ${i}: ${path.name}, is directory: ${path.isDirectory}`);
}
}
}
main();
回答1:
To fix the issue, navigate to your data lake gen2 storage account in the portal -> Access control (IAM)
-> assign a Storage Blob Data Owner
role to your service principal.
Then the code works fine:
来源:https://stackoverflow.com/questions/61662089/cant-list-file-system-of-azure-datalake-with-javascript