Not able to generate SAS in Azure APIM using Microsoft sample

560 views Asked by At

Has anyone succeeded to generate a SAS for the Blob Storage in Azure APIM following the sample below?

https://learn.microsoft.com/en-us/azure/api-management/policies/generate-shared-access-signature

Have substituted the storage access keys from the portal (used key1 and key 2), but got the same results. Also tried to generate the new key, but it did not work either.

"Expression evaluation failed. The given key was not present in the dictionary.\r\n at System.Collections.Generic.Dictionary`2.get_Item(TKey key)", "The given key was not present in the dictionary."

What added more confusion to azure-apim starter like me is <set-variable name="resourcePath" value="TableName()" />, what does TableName() do?

2

There are 2 answers

3
max3d On BEST ANSWER

Thank you all who have tried to help: Anton and Doris.

Operation that was failing was this block:

<set-variable name="StringToSign" value="@{
            return string.Format(
            "GET\n\n\n\n\n{0}\n\n\n\n\n\n\n{1}\n{2}\n{3}",
            (string)context.Variables["Content-Type"],
            (string)context.Variables["x-ms-date"],
            (string)context.Variables["x-ms-version"],
            (string)context.Variables["CanonicalizedResource"]);
        }" />

But, in the beginning of the sample, when context variables were set, x-ms-version was missing. I added operation <set-variable name="x-ms-version" value="2020-02-10" /> and SAS is now being generated.

Maybe it will help someone else who wants to use azure :)

2
Doris Lv On

This sample generates SAS token for a table in Azure Storage account. You could modify it to the resources you want to access, like this:

<set-variable name="resourcePath" value="containername/blobname" />

Don't forget to change the rewrite-uri block, too.