Patch operations for updating api resources with the AWS CLI
When updating API Gateway resources using the AWS CLI, some commands include a --patch-operations
argument.
For example, the update-base-path-mapping
allows an optional --patch-operations
. For more information about which resources are supported via patch operations, the AWS documentation is here.
How to use the --patch-operations
argument
In the case for updating a base path mapping, a user may need to supply a restapiId
and stage
value.
The JSON array:
1[
2 {
3 "op": "replace",
4 "path": "/restapiId",
5 "value": "id"
6 },
7 {
8 "op": "replace",
9 "path": "/stage",
10 "value": "prod"
11 }
12]
The aws apigateway update-base-path-mapping
allows for a stringified json
array value for the --patch-operations
argument:
1domain_name="example.com"
2base_path="some-path"
3api_id="id"
4stage="prod"
5aws apigateway update-base-path-mapping \
6 --domain-name $domain_name \
7 --base-path $base_path \
8 --patch-operations "[{\"op\":\"replace\",\"path\":\"/restapiId\",\"value\":\"$api_id\"},{\"op\":\"replace\",\"path\":\"/stage\",\"value\":\"$stage\"}]"
The same --patch-operations
argument format applies to the other API Gateway commands as well.