DejanS
DejanS

Reputation: 116

Azure CLI - unable to create Azure Synapse linked service - quoting issue with JSON file

I am trying to create linked service on Azure Synapse using Azure CLI. I have a json file with code of linked service:

{
    "name": "LS_dakeyvault",
    "properties": {
        "annotations": [],
        "type": "AzureKeyVault",
        "typeProperties": {
            "baseUrl": "https://edap-d-kv.vault.azure.net/"
        }
    }
}

I would run following in Windows shell:

az synapse linked-service create --name LS_dakeyvault --file "C:\Project\SynGitTest0\linkedService\LS_dakeyvault.json" --workspace-name edap-d-syn

I would get this error:

Failed to parse JSON: C:\Project\SynGitTest0\linkedService\LS_dakeyvault.json
Error detail: Expecting value: line 1 column 1 (char 0)
The JSON may have been parsed by the shell. See https://learn.microsoft.com/cli/azure/use-cli-effectively#quoting-issues

I have the same problem with other shells (powershell, bash).

I tried following instructions from links that MS provided.I am not sure that I understand what should I do. I tried putting name of the file in single quotes:

az synapse linked-service create --name LS_dakeyvault --file "'C:\Project\SynGitTest0\linkedService\LS_dakeyvault.json'" --workspace-name edap-d-syn

(I am not sure that this is a right solution for quoting issue.) In that case I would get a different error:

string indices must be integers
Traceback (most recent call last):
  File "D:\a\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\knack/cli.py", line 231, in invoke
  File "D:\a\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/commands/__init__.py", line 658, in execute
  File "D:\a\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/commands/__init__.py", line 721, in _run_jobs_serially   
  File "D:\a\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/commands/__init__.py", line 692, in _run_job
  File "D:\a\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/commands/__init__.py", line 328, in __call__
  File "D:\a\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/commands/command_operation.py", line 121, in handler     
  File "D:\a\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/command_modules/synapse/manual/operations/artifacts.py", line 
36, in create_or_update_linked_service
TypeError: string indices must be integers

Upvotes: 2

Views: 1111

Answers (1)

SauravDas-MT
SauravDas-MT

Reputation: 1440

If you check this Azure Key Vault linked service section of the Microsoft document then you will find that the JSON file for your linked service is correct there is no issue with it as shown below.

{
    "name": "AzureKeyVaultLinkedService",
    "properties": {
        "type": "AzureKeyVault",
        "typeProperties": {
            "baseUrl": "https://<azureKeyVaultName>.vault.azure.net"
        }
    }
}

So the problem must be with the file path in your az command. Could you check whether the file path is right in your command. If you check the Required Parameters of the az synapse linked-service create CLI command then you will find that -

- -file Properties may be supplied from a JSON file using the @{path} syntax or a json string.

If you enter the right path and add @ at the beginning of the path, then the linked service create cmdlet can work well. If you are still facing issue try moving to the directory where the file is stored and run the command.

I would suggest to read the az synapse linked-service and Store credential in Azure Key Vault documents for more information.

Upvotes: 1

Related Questions