1. Storing Video and Image Data for Cognitive Services on Azure Blob


    Storing video and image data in Azure Blob Storage is a common scenario when working with Azure Cognitive Services. Azure Blob Storage provides a scalable and secure place to house large amounts of unstructured data, such as video and image files, which can then be processed by various Cognitive Services for tasks like image recognition, video indexing, and more.

    In this guide, we will set up an Azure Blob Storage container for storing our video and image data, and then we will create an Azure Cognitive Services account that we can use to access and process this data.

    Azure Blob Storage

    Azure Blob Storage is optimized for storing massive amounts of unstructured data, such as text or binary data. Azure Blob Storage is made up of containers and blobs. Containers serve as the top-level directory, and blobs are the individual files within those containers.

    We'll be creating a storage account and a container within that account to store our data.

    Azure Cognitive Services Account

    Azure Cognitive Services offers a variety of AI services and cognitive APIs to build intelligent apps. Once we have our data stored in Blob Storage, we would need a Cognitive Services Account to access Azure’s AI processing capabilities.

    Below is a Pulumi program written in Python that will create the necessary Azure infrastructure:

    1. A Resource Group: A container that holds related resources for an Azure solution.
    2. A Storage Account: To store our images and videos in Azure Blob Storage.
    3. A Blob Container: A specific container within our storage account where blobs will be uploaded.
    4. A Cognitive Services Account: To access AI processing capabilities provided by Azure.

    Let's begin by defining our Pulumi program:

    import pulumi import pulumi_azure_native as azure_native # Create an Azure Resource Group resource_group = azure_native.resources.ResourceGroup("resource_group") # Create an Azure Storage Account storage_account = azure_native.storage.StorageAccount("storageAccount", resource_group_name=resource_group.name, sku=azure_native.storage.SkuArgs(name=azure_native.storage.SkuName.STANDARD_LRS), kind=azure_native.storage.Kind.STORAGE_V2, location=resource_group.location ) # Create a Blob Container blob_container = azure_native.storage.BlobContainer("blobContainer", account_name=storage_account.name, resource_group_name=resource_group.name, public_access=azure_native.storage.PublicAccess.NONE ) # Create an Azure Cognitive Services Account cognitive_services_account = azure_native.cognitiveservices.Account("cognitiveServicesAccount", resource_group_name=resource_group.name, sku=azure_native.cognitiveservices.SkuArgs( name="S1" # Pricing tier, please adjust according to your needs ), kind="CognitiveServices", # The type of cognitive services account location=resource_group.location, properties={} ) # Export the primary connection string for the Storage Account primary_connection_string = storage_account.primary_connection_string.apply( lambda connection_string: connection_string ) # Export the endpoint of the Cognitive Services Account cognitive_services_endpoint = pulumi.Output.all(cognitive_services_account.endpoint).apply( lambda endpoint: endpoint[0] ) # Export the storage account name and blob container name so they can be accessed easily pulumi.export('storage_account_name', storage_account.name) pulumi.export('blob_container_name', blob_container.name) pulumi.export('primary_connection_string', primary_connection_string) pulumi.export('cognitive_services_endpoint', cognitive_services_endpoint)

    In the above program:

    • We first create a resource group, which is a logical container for our resources.
    • We then create a storage account within the resource group. This account is of type STORAGE_V2 (general-purpose v2) with a storage kind BlobStorage. We're using the STANDARD_LRS SKU for locally-redundant storage.
    • Next, we create a blob container in the storage account that we've set to have no public access (PublicAccess.NONE), which means the blobs can only be accessed privately.
    • Finally, we create an Azure Cognitive Services account in the resource_group we defined earlier. We specify the SKU for the pricing and capabilities level, and in this case, we use "S1" which you can change based on your application needs.

    Once this program is executed with Pulumi, it will provision the necessary infrastructure in your Azure subscription, and it will output the connection strings and endpoint URLs that can be used to interact with the Blob Storage and Cognitive Services resources programmatically.

    To run this program, you will need to have the Pulumi CLI installed, as well as Python 3. You'll need to log in to your Pulumi account and set up the Azure provider with appropriate credentials. Once setup is complete, you can execute pulumi up to create the resources.