Understanding API Gateway with Custom Domains in Serverless: A beginner's guide to leveraging API Gateway's capabilities within serverless architectures, optimizing your development process.
In the age of micro-services, developers create a lot of apis which are often scattered all over the place. We had a similar problem, our number of APIs grew fast with time. Just a better way to manage these APIs is to organize them under a custom domain and have them served in a more readable manner. This blog will walk you through the same process, specific to the serverless framework.
We will be using the Serverless Domain Manager plugin to achieve this.
You can achieve this by-
serverless plugin install --name serverless-domain-manager
If you own a domain name, you need to decide on a sub-domain to host your APIs base URL, it could be something like api.example.com
Add the plugin declaration, as follows -
Now is the time to add configuration -
Now is the time to take a pause, you will realise that you have setup the configuration that you need but the sub-domain still doesn't exist in Route53.
I will not list down any complicated set of instructions here, all you need to do is run serverless create_domain
You just need to do this once, when publishing any of your APIs for the first time.
This will create your sub-domain given that your aws credentials have enough access to do it in Route53 and you have the hosted zone setup in Route53
All done, you just have to do a sls deploy now.
You can add this configuration for all your APIs.
In case you have more than one types of APIs in your Serverless Application, use the below example to deploy to custom domains -
Visit Gushwork.ai to delegate your tasks now!