{"id":42,"date":"2022-08-22T10:43:00","date_gmt":"2022-08-22T09:43:00","guid":{"rendered":"https:\/\/gerardvandenbosch.nl\/?p=42"},"modified":"2022-08-23T04:33:21","modified_gmt":"2022-08-23T02:33:21","slug":"multiple-serverless-offline-instances","status":"publish","type":"post","link":"https:\/\/gerardvandenbosch.nl\/?p=42","title":{"rendered":"Multiple Serverless Offline instances"},"content":{"rendered":"\n<p><a rel=\"noreferrer noopener\" href=\"https:\/\/www.serverless.com\/\" target=\"_blank\">Serverless framework<\/a> uses <em>AWS CloudFormation<\/em> to deploy the designed application. Cloudformation has a hard limit of 500 components in order to force the developer to design micro services and not creating a mega project.<\/p>\n\n\n\n<p>This leads to multiple serverless projects as backend in a large project. The frontend will call the backend project it needs.<\/p>\n\n\n\n<p>In order to test this on the developer&#8217;s computer, <a rel=\"noreferrer noopener\" href=\"https:\/\/www.npmjs.com\/package\/serverless-offline\" target=\"_blank\">Serverless Offline<\/a> can be used. This will simulate the lambda functions on the local computer and provides a local HTTP server interface for the frontend to interact with.<\/p>\n\n\n\n<p>When the frontend needs to interact with multipe backend projects we can start multiple Serverless Offline instances. However for this we will need to adjust the port numbers. <\/p>\n\n\n\n<!--more-->\n\n\n\n<p>By default the Serverless Offline HTTP server interface will run on <strong>port 3000<\/strong> and the lambda port will be on <strong>port 3002.<\/strong> We can alter this as following:<\/p>\n\n\n\n<pre class=\"wp-block-code has-dark-gray-background-color has-background\"><code lang=\"bash\" class=\"language-bash\">sls offline --httpPort [portnumber] --lambdaPort [lambdaportnumber]<\/code><\/pre>\n\n\n\n<p>The<em> [portnumber]<\/em> and<em> [lambdaportnumber]<\/em> can be replaced with the port of choice.<\/p>\n\n\n\n<p>In order to make it even easier, for each project a small shell script can be created with the port numbers embedded.<\/p>\n\n\n\n<pre class=\"wp-block-code has-dark-gray-background-color has-background\"><code class=\"\">#!\/bin\/sh\nsls offline --noAuth --httpPort 3020 --lambdaPort 3022<\/code><\/pre>\n\n\n\n<p>This can be saved as <strong>start-serverless-offline.sh<\/strong> in the serverless project folder and then simply call <strong>.\/start-serverless-offline.sh<\/strong> to start serverless offline, in this case on<strong> HTTP port 3020<\/strong> and <strong>lambda port 3022<\/strong>.<\/p>\n\n\n\n<p>For each project different port numbers need to be specified, by embedding them into the script for each project it will automatically start it for you on the correct ports without having to think about it.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Serverless framework uses AWS CloudFormation to deploy the designed application. Cloudformation has a hard limit of 500 components in order to force the developer to design micro services and not creating a mega project. This leads to multiple serverless projects as backend in a large project. The frontend will call the backend project it needs. [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3,12,5],"tags":[7,6],"class_list":["post-42","post","type-post","status-publish","format-standard","hentry","category-aws","category-networking","category-serverless","tag-aws","tag-serverless","post-preview"],"_links":{"self":[{"href":"https:\/\/gerardvandenbosch.nl\/index.php?rest_route=\/wp\/v2\/posts\/42","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/gerardvandenbosch.nl\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/gerardvandenbosch.nl\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/gerardvandenbosch.nl\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/gerardvandenbosch.nl\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=42"}],"version-history":[{"count":2,"href":"https:\/\/gerardvandenbosch.nl\/index.php?rest_route=\/wp\/v2\/posts\/42\/revisions"}],"predecessor-version":[{"id":44,"href":"https:\/\/gerardvandenbosch.nl\/index.php?rest_route=\/wp\/v2\/posts\/42\/revisions\/44"}],"wp:attachment":[{"href":"https:\/\/gerardvandenbosch.nl\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=42"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/gerardvandenbosch.nl\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=42"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/gerardvandenbosch.nl\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=42"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}