Home > Back-end >  Azure: The specified container does not exist, Dapr with ContainerApps
Azure: The specified container does not exist, Dapr with ContainerApps

Time:01-22

I'm using Dapr Azure Blob Storage binding to set up a file store

here are the biceps

storage-account.bicep

@description('The location in which the Azure Storage resources should be deployed.')
param location string

@description('The name of the blob container.')
var containerName = 'ifms-filestore'

resource storageAccount 'Microsoft.Storage/storageAccounts@2022-05-01' = {
  name: 'ifmsstorageaccount'
  location: location
  sku: {
    name: 'Standard_LRS'
  }
  kind: 'BlobStorage'
  properties: {
    accessTier: 'Hot'
  }
}

resource container 'Microsoft.Storage/storageAccounts/blobServices/containers@2022-05-01' = {
  name: '${storageAccount.name}/default/${containerName}'
}

output storageAccountId string = storageAccount.id
output storageAccountApiVersion string = storageAccount.apiVersion
output storageAccountName string = storageAccount.name
output storageAccountContainerName string = container.name

blobstorage.bicep

param containerAppsEnvironmentName string
param storageAccountId string
param storageAccountApiVersion string
param storageAccountName string
param storageAccountContainerName string

resource containerAppsEnvironment 'Microsoft.App/managedEnvironments@2022-06-01-preview' existing = {
  name: containerAppsEnvironmentName

  resource daprComponent 'daprComponents@2022-03-01' = {
    name: 'ifms-dapr-filestore'
    properties: {
      componentType: 'bindings.azure.blobstorage'
      version: 'v1'
      secrets: [
        {
          name: 'storage-account-account-key'
          value: listKeys(storageAccountId, storageAccountApiVersion).keys[0].value
        }
      ]
      metadata: [
        {
          name: 'accountName'
          value: storageAccountName
        }
        {
          name: 'accountKey'
          secretRef: 'storage-account-account-key'
        }
        {
          name: 'containerName'
          value: storageAccountContainerName
        }
        {
          name: 'decodeBase64'
          value: 'true'
        }
      ]
      scopes: [
        'vehicle-management-web-api'
      ]
    }
  }
}

output daprPubSubName string = containerAppsEnvironment::daprComponent.name

The AddFileAsync is a helper function that is used to add the file to the file store and uses a DaprtClinet to do so.

public async Task<FileReturnType> AddFileAsync(byte[] fileContent, string path, string fileName)
{
  var filepath = Path.Combine(path, fileName);

  string base64String = Convert.ToBase64String(fileContent, 0, fileContent.Length);
  Dictionary<string, string> metadata = new Dictionary<string, string>{ {"blobName",filePath}};

  await _daprClient.InvokeBindingAsync("ifms-dapr-filestore", "create", base64String, metadata);
  long fileSize = fileContent.Length;
  var extension = Path.GetExtension(fileName);

  return new FileReturnType(filepath, fileSize, extension);
}

When I add the file I get the following error message

Dapr.DaprException: Binding operation failed: the Dapr endpoint indicated a failure. See InnerException for details.
 ---> Grpc.Core.RpcException: Status(StatusCode="Internal", Detail="error when invoke output binding ifms-dapr-filestore: error uploading az blob: -> github.com/Azure/azure-storage-blob-go/azblob.newStorageError, /home/vsts/work/1/go/pkg/mod/github.com/!azure/[email protected]/azblob/zc_storage_error.go:42
===== RESPONSE ERROR (ServiceCode=ContainerNotFound) =====
Description=The specified container does not exist.
RequestId:d12aeaa8-301e-0019-71b3-2d46c2000000
Time:2023-01-21T16:12:42.7329062Z, Details: 
   Code: ContainerNotFound
   PUT https://ifmsstorageaccount.blob.core.windows.net/ifmsstorageaccount/default/ifms-filestore/RequestLetters/REQ-DIH-MUN-002/REQ-DIH-MUN-002 - Request Letter.pdf?timeout=61
   Authorization: REDACTED
   Content-Length: [958932]
   User-Agent: [dapr-1.9.5-msft-1 Azure-Storage/0.10 (go1.19; linux)]
   X-Ms-Blob-Cache-Control: []
   X-Ms-Blob-Content-Disposition: []
   X-Ms-Blob-Content-Encoding: []
   X-Ms-Blob-Content-Language: []
   X-Ms-Blob-Content-Type: []
   X-Ms-Blob-Type: [BlockBlob]
   X-Ms-Client-Request-Id: [184d2673-814b-45ea-7ad0-cfe8d1fca4b3]
   X-Ms-Date: [Sat, 21 Jan 2023 16:12:42 GMT]
   X-Ms-Meta-Contenttype: [application/grpc]
   X-Ms-Meta-Daprauthority: [127.0.0.1:50001]
   X-Ms-Meta-Daprgrpcacceptencoding: [identity,gzip,deflate]
   X-Ms-Meta-Traceparent: [00-cbed618718a728703a987fd1f50b6b25-c3d612101f033c57-00]
   X-Ms-Meta-Useragent: [grpc-dotnet/2.47.0 (.NET 7.0.2; CLR 7.0.2; net6.0; linux; x64) dapr-sdk-dotnet/v1.9.0 3224579c3e136020bbf713528965854ebbd4eefe]
   X-Ms-Version: [2019-02-02]
   --------------------------------------------------------------------------------
   RESPONSE Status: 404 The specified container does not exist.
   Content-Length: [225]
   Content-Type: [application/xml]
   Date: [Sat, 21 Jan 2023 16:12:42 GMT]
   Server: [Windows-Azure-Blob/1.0 Microsoft-HTTPAPI/2.0]
   X-Ms-Client-Request-Id: [184d2673-814b-45ea-7ad0-cfe8d1fca4b3]
   X-Ms-Error-Code: [ContainerNotFound]
   X-Ms-Request-Id: [d12aeaa8-301e-0019-71b3-2d46c2000000]
   X-Ms-Version: [2019-02-02]

Both the azure storage and the container a configured on azure as per the image below axure portal

CodePudding user response:

I think the issue is in your storageAccountContainerName which, looking at the error response seems to be in the format of {storageaccountName}/default/{actualContainerName}.

The URL in the PUT request in your output begins with https://ifmsstorageaccount.blob.core.windows.net/ifmsstorageaccount/default/ifms-filestore/ which is in the format https://{storageAccountName}.blob.core.windows.net/{storageAccountName}/default/{containerName}/{blobName} while it should be https://{storageAccountName}.blob.core.windows.net/{containerName}/{blobName}

Try changing the output in storageaccount.bicep to:

output storageAccountContainerName string = last(split(container.name, '/'))
  • Related