Blue Green Deployment of Rest API using Amazon API Gateway Custom Domain Names

Debadatta Panda
4 min readMar 17, 2023

--

External customer access the Rest API using specific url, the developer and product team required to update the API without minimal interruption and not release a new url for the updated API . Using Amazon API Gateway stage deployment you can publish API changes, but this gives a new url for the stage. In the below blog I will show how to carryout API deployment with a blue green approach using the Amazon API Gateway Custom Domain , API Stage where the new changes will be deployed to a new stage and the previous api will be in the previous stage . With this approach the external customer need not to change any url at their side due to any update in the API stage and gives felxibility to product team to test new changes in the new stage and roll back to previous deployment in case of any issue.

Blue Green Deployment of API using Amazon API Gateway Stages and Custom Domain

Amazon API Gateway Custom Domain name : This provides intuitive URLs that you can provide to your users to invoke the API. Once the api is deployed to a stage, the deployed api can be invoked by the default base URL of the following format:

https://api-id.execute-api.region.amazonaws.com/stage

api-id : id generated by API Gateway

region : AWS region where the API deployed

stage: stage details where the API deployed

Using custom domain name, you can set up your API’s hostname and choose a base path to map the alternative URL to your API. For example, a more user-friendly API base URL can become:

https://customdomainname.com/blueservice

customdomainname.com: this is the url being configured

blueservice: is path name configured in the custom domain

Steps for Adding a custom domain name to the API Gateway :

In the API Gateway console, Under the Custom domain names section click Create and fills the values as mentioned below:

For Domain name, enter the domain name.
For ACM certificate either you can import your certificate or use ACM request certificate to get the certificate for the domain .

the below screen show the details of the custom after the values are configured .

Now the Domain name can be mapped to to stage of an api .

Mapping a Api Stage to a Domain name : In the API Gateway APIs section click the API and then select the Deploy API from Resource option:

Lets deploy the API into the Blue stage :

Configure the API Mapping in the custom Domain section with the blue stage details :

Once this is saved , the external customer can access the api using the format of customdomainname.com/blue . In the below sample I have a lambda function which return a message “blue test” to show that its been called from the blue stage

Update of Api : The new api changes will be deployed to new stage called Green :

Once the API new stage is deployed then create a Green Api stage mapping in the domain , this will give the opportunity to test the API in the live environment with the limited set of evaluate user

This will give the url customdomainname/green to access the updated api

Once the relevant testing completed the API mapping will be reversed to Blue / Green stages , so that the external customer will get the updated API on the existing url

The mapping changed as below :

Now the API changes of Green stage gets reflected with the existing url of the customer

Now Green stage becomes the new blue and the previous blue stage can be deletes or you can roll back the previous stage in case of any issue.

Conclusion:

With the above solution we have seen how to release new version of API to the customer with no interruption and making sure that new features can be tested on the API on the live environment with a easy of roll back option of the API to the previous one.

--

--

Debadatta Panda
Debadatta Panda

No responses yet