3

What is the right syntax for doing this via the aws cli?

aws apigateway update-stage --rest-api-id $api_id --stage-name 'test_stage' --patch-operations op="add",path=/variables,value="{server:8.8.8.8}"

I can't get the last part value=".." right. The documentation isn't very helpful to me.

maafk
  • 6,176
  • 5
  • 35
  • 58
zeus1234
  • 453
  • 1
  • 5
  • 15

2 Answers2

7

I got it working after numerous trial and error:

aws apigateway update-stage --rest-api-id $api_id --stage-name 'test_stage' --patch-operations op="replace",path=/variables/server,value="8.8.8.8"

op="replace" works instead of "add" (odd for me as i am trying to add a variable). The variable name is in the path and the value after that. AWS return me the following response after executing the command this way:

{
    "stageName": "test_stage", 
    "variables": {
        "server": "8.8.8.8"
    }, 
    "cacheClusterEnabled": false, 
    "cacheClusterStatus": "NOT_AVAILABLE", 
    "deploymentId": "kg39574", 
    "lastUpdatedDate": 1512838534, 
    "createdDate": 1512705498, 
    "methodSettings": {}
}
Kannaiyan
  • 12,554
  • 3
  • 44
  • 83
zeus1234
  • 453
  • 1
  • 5
  • 15
  • For future reference this is document in our API reference https://docs.aws.amazon.com/apigateway/api-reference/link-relation/stage-update/ – jackko Dec 10 '17 at 17:46
  • It complained for me when I added the single quotes around the stage-name. You may need to remove it. – Michael Jan 11 '20 at 18:39
  • how can we add multiple values at a single stretch? I have a hell a lot of stage variables and finding it hard when I want to re-create them, is there an option to copy from another API Gateway?. – harishanth raveendren Mar 15 '22 at 15:17
0

Two things to try

Replace the double quotes with single quotes

aws apigateway update-stage \
--rest-api-id $api_id \
--stage-name 'test_stage' \
--patch-operations op='add',path=/variables,value='{server:8.8.8.8}'

Escape the {} characters

aws apigateway update-stage \
--rest-api-id $api_id \
--stage-name 'test_stage' \
--patch-operations op="add",path=/variables,value="\{server:8.8.8.8\}"

Reference for parameters in cli

maafk
  • 6,176
  • 5
  • 35
  • 58