I have a CRA (Create React App) front-end app which uses .env files to get its backend URLs. When I deploy services using Serverless, it prints my API URL on the console, which I need to manually copy to the config files. This sounds like a bad practice and prone to error. I also don’t know if the URLs always stay the same or may change after a new deploy. My question is, what are some of the best practices for automating a case like this ?
Th URL will stay the same unless you sls remove then sls deploy. That’s when API Gateway will generate the API ID which is the part that changes.
But…
You would be better served to use a Custom Domain so it never changes.
You can learn more about Custom Domains here.
Or in the AWS API Gateway Docs if you want the manual/non-serverless way of setting it up.