azure - 通过Azure数据工厂创建blob存储容器

标签 azure powershell blob azure-data-factory

我正在开发一个使用 Azure 数据工厂和 Blob 存储的项目。我有一个需求,但不知道如何实现。

要求:

#1 检查 blob 存储容器是否存在。 #2 通过 power shell 脚本在数据工厂中创建新容器。基本上,容器只会在管道第一次运行时创建。 #3 调用API。

#1==> 我找到了检查 if blob exists, 的方法但没有找到容器。

#2==> 通过 Power shell 脚本从 Azure 数据工厂创建容器的最佳方法是什么:通过批处理?还是通过函数来​​完成更好?

非常感谢您提前提供的帮助

最佳答案

作为post也就是说,我们可以使用 GetMetadata 事件和 If Condition 事件来检查 blob 是否存在。如果blob不存在,我们可以使用Azure函数创建容器并通过http get请求指定容器的名称。我觉得使用Azure功能更方便。

例如,这里我在Azure函数中使用nodejs。根据 Azure function javascriptManage blobs with JavaScript v12 SDK in Node.js 。我们可以开始一个项目。

向 Nodejs 演示添加依赖项。 enter image description here

然后修改一些代码index.js,以便我们可以管理blob容器(创建一个容器)。

const { BlobServiceClient } = require('@azure/storage-blob');


module.exports = async function (context, req) {

    const AZURE_STORAGE_CONNECTION_STRING = "<your_connect_string>";
    const blobServiceClient = BlobServiceClient.fromConnectionString(AZURE_STORAGE_CONNECTION_STRING);

    const name = (req.query.name || (req.body && req.body.name));

    const containerClient = blobServiceClient.getContainerClient(name);

    // Create the container
    const createContainerResponse = await containerClient.create();

    const responseMessage = name
        ? "Container:" + name + " has been created!"
        : "...";

    context.res = {
        // status: 200, /* Defaults to 200 */
        body: responseMessage
    };
}

部署到Azure功能后,我测试了代码,运行良好。 enter image description here 容器已创建。 enter image description here

关于azure - 通过Azure数据工厂创建blob存储容器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65190284/

相关文章:

azure - 通过graph api或graph sdk为整个B2C实例创建用户自定义属性

azure - 我们可以使用 blob 绑定(bind)器将文件上传到 Azure 数据湖第 2 代吗

python - 在azure python函数中导入自定义模块

如果匹配,powershell 比较 2 个数组输出

powershell - 使用powershell,SharePoint和csom访问列表中的所有字段

powershell - 使用 PowerShell 配置 Ubuntu DSVM 时创建计划时出错

video - MediaRecorder - 如何在录制时播放视频 block / block ?

javascript - 表单数据和 Blob

caching - 设置 azure localcache isenabled 的影响

c# - 将 blob 字符串转换为 jpg 文件