5

I'm using Azurite and wish to create a container/upload a blob etc from the bash terminal!

I've tried using the Azure CLI like this::

az storage container create --account-name devstoreaccount1 --account-key Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw== --name mycontainer

But of course it doesn't work and complains of Authentication failure! By the way the correct account key and name are used in that example.

I believe it's not possible to talk to Azurite using the Azure CLI.

All I want to do is create a container and upload a file to it from the terminal.

Does anybody know if this is possible? Or will I have to use a Java client (for example) to do the job?

Thanks

Johnny Alpha
  • 758
  • 1
  • 8
  • 35

1 Answers1

8

According to my test, when we account key and account name with Azure CLI to create blob container, cli will use https protocol to connect Azurite. But, in default, Azurite just support http protocol. For more details, please refer to here
enter image description here

So I suggest you use connection string to connect Azurite with Azure CLI, the connection string will tell Azure CLI uses http protocol.

For example

  1. Create contanier
az storage container create -n test --connection-string "DefaultEndpointsProtocol=http;AccountName=devstoreaccount1;AccountKey=Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==;BlobEndpoint=http://127.0.0.1:10000/devstoreaccount1;QueueEndpoint=http://127.0.0.1:10001/devstoreaccount1;"

enter image description here

  1. Upload file
az storage blob upload -f D:\test.csv -c test -n test.csv --connection-string "DefaultEndpointsProtocol=http;AccountName=devstoreaccount1;AccountKey=Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==;BlobEndpoint=http://127.0.0.1:10000/devstoreaccount1;QueueEndpoint=http://127.0.0.1:10001/devstoreaccount1;"

enter image description here

Jim Xu
  • 21,610
  • 2
  • 19
  • 39
  • This works! I tried to do the same thing using Https, and it fails with this error: Max retries exceeded with url: /devstoreaccount1/identity?restype=container (Caused by SSLError(SSLError("bad handshake: Error([('SSL routines', 'tls_process_server_certificate', 'certificate verify failed')],)",),)). HTTPSConnectionPool(host='127.0.0.1', port=10000): Any pointers? – Ayushmati May 18 '21 at 09:12
  • @Ayushmati If you want to use HTTPS, please refer to https://github.com/Azure/Azurite#https-setup – Jim Xu May 18 '21 at 09:16
  • I have followed all the steps and I can view my storage account in AzureStorageExplorer. But when I try to add a blobcontainer using the commands above, it throws the error. – Ayushmati May 18 '21 at 11:38