7

I have created an API Gateway and created an API config as well associated with it which lists a set of APIs. Now I want to add/modify a set of APIs. How do I update the same API config of this gateway?

Saurabh
  • 81
  • 1
  • 6

3 Answers3

11

I did it using gcloud CLI.

First create a new config using your updated open api spec file:

gcloud api-gateway api-configs create NEW_CONFIG_ID --api=MY_API --openapi-spec=openapi2-functions.yaml 

Then update your api gateway with new config:

gcloud api-gateway gateways update MY-GATEWAY --api=MY-API --api-config=NEW_CONFIG_ID --location=YOUR_LOCATION
Lucas Marinzeck
  • 313
  • 4
  • 11
  • 1
    Thanks for your response. Yeah, I achieved this using the same approach a few days ago. I should have mentioned here. But I was really interested in was modifying the same config. Looks like that is not a possibility. What do you think? – Saurabh Feb 13 '22 at 05:47
  • I dont think this is possible, i read the command with the help flag: gcloud api-gateway api-configs update --help Output: DESCRIPTION Update an API Gateway API config. NOTE: Only the name and labels may be updated on an API config. – Lucas Marinzeck Feb 14 '22 at 07:04
  • 1
    yeah, I think the same. Thanks. – Saurabh Feb 19 '22 at 12:31
5

The GCP documentation mentions you cannot update an existing API config, only its display name and labels, and you cannot delete an existing API config that is in use by a gateway; meaning you need to create a new API config altogether if your config file has changed.

A workaround I found for this was to:

  1. Create new API config, point to gateway:
gcloud api-gateway api-configs create NEW_CONFIG_ID --api=MY_API --openapi-spec=openapi2-functions.yaml 
gcloud api-gateway gateways update MY-GATEWAY --api=MY-API --api-config=NEW_CONFIG_ID --location=YOUR_LOCATION
  1. Delete original config:
gcloud api-gateway api-configs delete OLD_CONFIG_ID --api=MY_API
  1. Redeploy new API config with name of original config, using your updated config file, point to gateway:
gcloud api-gateway api-configs create OLD_CONFIG_ID --api=MY_API --openapi-spec=openapi2-functions.yaml 
gcloud api-gateway gateways update MY-GATEWAY --api=MY-API --api-config=OLD_CONFIG_ID --location=YOUR_LOCATION
  1. Delete new config:
gcloud api-gateway api-configs delete NEW_CONFIG_ID --api=MY_API

An awkward workaround but it allows for an automated redeployment of a similarly named API config file in a gateway.

user20042787
  • 71
  • 1
  • 3
3

Referencing the official documentation, it states that:

NOTE: Only the name and labels may be updated on an API config.

Therefore, you would need to create a new API config if you want to add/modify a set of APIs.

Mabel A.
  • 1,775
  • 4
  • 14