Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

How to use a single base URL for multiple services in big serverless applications — SAM, API gateway

Posted on Sep 23 • Originally published at Medium When you are working on a big application, you may have to use multiple backend services like authentication, payment, access management, and so on. If your architectural design is based on microservices, then all these services will have their own URL link to connect. But think, what happens when you use those separate links in your frontend code? Then if you want to add one more service to your application, you have to change your frontend routing again. It will complicate your system and add extra hassle.To solve this problem, you can add an Amazon Api Gateway proxy which helps you to connect all separate URLs using a single base URL.Lets think you decide to make an e-commerce application where you will have product service, authentication service, cart management, payment service.Backend Services:Product service: https://product-service-urlAuthentication service: https://auth-service-urlCart management: https://cart-service-urlPayment service: https://payment-service-urlNow, you do not need to know or manage multiple URLs. API gateway will create a single base URL like https://single-base-url/prod and it will route other services with proxy. Create methods and resources for each services and create path like /product, /auth, /cart, /payment. When you use /product after base URL, it will route you to product service, same as for other services.I created a github repo for this. Follow the steps in README section to see how functionality in product services can be used through a single base URL. You can create other services like product service.Here I describe what does mean each section of template.yaml. To create a proxy for each service you need four section:i) Serverless application: To check all syntax and properties of AWS::Serverless::Application, please check this link.Here in this section,ii) API gateway resource for path: To check all syntax and properties of AWS::ApiGateway::Resource, check this link.Here in this section,iii) API gateway resource for proxy: It is same as previous section. Just use proxy as PathPart.Here in this section,iv) API gateway method: To check all syntax and property details, check this link.Here in this section,I have added my git link in this post and README describes how you can run this project. Hope you enjoy it. If you have any question, ask me.If you find this post helpful, please follow me to get more tutorials like this.Templates let you quickly answer FAQs or store snippets for re-use. Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink. Hide child comments as well Confirm For further actions, you may consider blocking this person and/or reporting abuse Zahraa Jawad - Sep 22 Osama B.Sassi - Sep 22 Luca Butler - Sep 22 Andres Court - Sep 22 Would you like to become an AWS Community Builder? Learn more about the program and apply to join when applications are open next. Once suspended, aws-builders will not be able to comment or publish posts until their suspension is removed. Once unsuspended, aws-builders will be able to comment and publish posts again. Once unpublished, all posts by aws-builders will become hidden and only accessible to themselves. If aws-builders is not suspended, they can still re-publish their posts from their dashboard. Note: Once unpublished, this post will become invisible to the public and only accessible to farzana-juthi. They can still re-publish the post if they are not suspended. Thanks for keeping DEV Community safe. Here is what you can do to flag aws-builders: aws-builders consistently posts content that violates DEV Community's code of conduct because it is harassing, offensive or spammy. Unflagging aws-builders will restore default visibility to their posts. DEV Community — A constructive and inclusive social network for software developers. With you every step of your journey. Built on Forem — the open source software that powers DEV and other inclusive communities.Made with love and Ruby on Rails. DEV Community © 2016 - 2023. We're a place where coders share, stay up-to-date and grow their careers.



This post first appeared on VedVyas Articles, please read the originial post: here

Share the post

How to use a single base URL for multiple services in big serverless applications — SAM, API gateway

×

Subscribe to Vedvyas Articles

Get updates delivered right to your inbox!

Thank you for your subscription

×