Issue with New-AzStorageContext – The Specified Resource Does Not Exist – Status : 404 – ErrorCoad : ResourceNotFound
Hope you all are doing good !!!
During my journey with Azure, when I was trying to create a Stored Access Policy using following script snippet for my blob container using PowerShell one Error occur and the Error Coad is ResourceNotFound and the status is 404. Following is the details of the error.
New-AzStorageContainerStoredAccessPolicy: The specified resource does not exist.
Status: 404 (The specified resource does not exist.)
Date: Fri, 28 May 2021 07:24:43 GMT
I tried to find the root cause of this issue. Initially I thought , may be I have given some wrong parameters or due to any typo but when I check thoroughly found there is no such mistake. Then I google for some time and found one article (https://github.com/Azure/azure-powershell/issues/10391), where it stated that, the way I have created the Azure Storage Context object is not supporting Get/New-AzStorageContainerStoredAccessPolicy because the context was created using Oauth authentication. The problem appears when OAuth is used and If the storage account context created by using ” -UseConnectedAccount”.
we can find all operations supported by Oauth in this doc, and we can see Get/New Container Stored Access Policy is not in the list, so it’s not supported by Oauth. So the failure is by design.
Here the solution is to use different overloaded method to create StorageContext object. Initially we ware using following script.
$ctx4 = -StorageAccountName kj21storageacount -UseConnectedAccount
Instead of the above I have used the following script by passing the connection string.
$ctx4 = New-AzStorageContext -ConnectionString “DefaultEndpointsProtocol=https;AccountName=kj21storageacount;AccountKey=S4bSWdL345345@$@@$S821gjNj24oqdzaFpR2ePVd7ApfWJEadsfdfSDF453$k9NpHV/BDxbF8Emjg2g==;EndpointSuffix=core.windows.net”
In this way we have resolved the above issue and move one step further towards our Stored Access Policy creation 🙂 .
After resolving the above issue I faced the next issue regarding type casting. I will discuss this in my next article.
I hope this is informative to you. Please let me know if I missed anything important or if my understanding is not up to the mark.
Keep reading, share your thoughts, experiences. Feel free to contact us to discuss more.
If you have any suggestion / feedback / doubt, you are most welcome. Stay tuned on Knowledge-Junction, will come up with more such articles.
Thanks for reading 🙂 .