{"id":837,"date":"2022-08-08T06:30:45","date_gmt":"2022-08-08T06:30:45","guid":{"rendered":"http:\/\/oqtacore-blog-473533498.us-east-1.elb.amazonaws.com\/?p=837"},"modified":"2025-05-22T10:32:28","modified_gmt":"2025-05-22T10:32:28","slug":"how-to-find-all-lambdas-in-aws","status":"publish","type":"post","link":"https:\/\/oqtacore.com\/blog\/how-to-find-all-lambdas-in-aws\/","title":{"rendered":"How to find all lambdas with provisioned concurrency in AWS"},"content":{"rendered":"<p><span data-preserver-spaces=\"true\">AWS lambdas are great for many various use cases. They are cheap (if used correctly), fast and easy to maintain. A lambda once written can easily be launched again, unlike most other code that you have on your local disk.<\/span><\/p>\n<p><span data-preserver-spaces=\"true\">But there are some downfalls in lambdas &#8211; one is that they need some warm-up time if they are not used often. By default, your lambda code is not loaded into the memory of the worker that runs this lambda. And when an unused lambda is invoked, it first needs to be loaded into a container and started. Such a situation is called a cold start, and a cold start takes 700ms to 3 seconds from our experience. <\/span><\/p>\n<p><span data-preserver-spaces=\"true\">After a cold start, a container stays warm for about 30-40 minutes, and then a cold start will happen again.<\/span><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-838 size-full\" src=\"http:\/\/blog.oqtacore.com\/wp-content\/uploads\/2022\/08\/aws.png\" alt=\"The function lifecycle logo\" width=\"1920\" height=\"1080\" \/><\/p>\n<p style=\"text-align: center;\"><span style=\"font-size: 10pt;\">Source: <a href=\"https:\/\/www.slideshare.net\/AmazonWebServices\/become-a-serverless-black-belt-optimizing-your-serverless-applications-aws-online-tech-talks\/14\" target=\"_blank\" rel=\"nofollow noopener\">AWS<\/a>\u00a0<\/span><\/p>\n<p><span data-preserver-spaces=\"true\">But what if you need your lambda to be used rarely, but each response should be very quick? For example, it might be your newly developed startup project with a marketplace page for which some lambda processes user requests. Until you get enough users to keep your lambdas always warm, you might need to keep them warm yourself so that users do not experience multi-second load times while accessing the marketplace. Otherwise, your conversion rates will be a disaster.<\/span><\/p>\n<p><span style=\"font-size: 10pt;\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-839 size-full\" src=\"http:\/\/blog.oqtacore.com\/wp-content\/uploads\/2022\/08\/aws2.png\" alt=\"lambda processes\" width=\"1920\" height=\"1080\" \/><\/span><\/p>\n<p style=\"text-align: center;\"><span style=\"font-size: 10pt;\">Source: <a href=\"https:\/\/www.cloudflare.com\/learning\/performance\/more\/website-performance-conversion-rates\/\" target=\"_blank\" rel=\"nofollow noopener\">Cloudflare<\/a> \u00a0<\/span><\/p>\n<p><span data-preserver-spaces=\"true\">And AWS thought of that &#8211; they allow you to keep your lambdas warm. It is called\u00a0<\/span><strong><span data-preserver-spaces=\"true\">provisioned concurrency<\/span><\/strong><span data-preserver-spaces=\"true\">\u00a0(do not mistake it with\u00a0<\/span><strong><span data-preserver-spaces=\"true\">reserved concurrency<\/span><\/strong><span data-preserver-spaces=\"true\">\u00a0which is absolutely different).<\/span><\/p>\n<p><span data-preserver-spaces=\"true\">Provisioned concurrency keeps containers with your lambda warm, and it will take just a few tens of milliseconds to start the lambda.<\/span><\/p>\n<p><span data-preserver-spaces=\"true\">However, take note: the provisioned concurrency\u00a0<\/span><strong><span data-preserver-spaces=\"true\">is not free<\/span><\/strong><span data-preserver-spaces=\"true\">. And oftentimes you just forget which lambdas have it enabled, and checking each lambda can take 30 seconds even if you know where to check &#8211; that\u2019s because provisioned concurrency settings are just buried too deep in the lambda settings and also require checking each version of lambda separately\u2026 Extremely bad UX.<\/span><\/p>\n<p><span data-preserver-spaces=\"true\">So when we at OQTACORE faced an issue of needing to check where we have provisioned concurrency enabled, there was no better way than to write a simple lambda to fight provisioned concurrency of other lambdas \ud83d\ude42<\/span><\/p>\n<p>Here is the code:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">const AWS = require('aws-sdk');\r\n\r\nconst lambda = new AWS.Lambda();\r\n\r\nexports.handler = async (event) =&gt; {\r\n\r\nlet promises = [];\r\n\r\nconst allLambdas = await getAllLambdas();\r\n\r\nconst resultArr = [];\r\n\r\nfor (let i = 0; i &lt; allLambdas.length; i++) {\r\n\r\n\u00a0\u00a0\u00a0\u00a0 promises.push(checkConfig(allLambdas[i].FunctionName, resultArr));\r\n\r\n}\r\n\r\nawait Promise.all(promises);\r\n\r\nreturn resultArr;\r\n\r\n}\r\n\r\nasync function getAllLambdas() {\r\n\r\nlet nextMarker;\r\n\r\nlet allLambdas = [];\r\n\r\ndo {\r\n\r\n\u00a0\u00a0\u00a0\u00a0 var params = {\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Marker: nextMarker,\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 MaxItems: 10\r\n\r\n\u00a0\u00a0\u00a0\u00a0 };\r\n\r\n\u00a0\u00a0\u00a0\u00a0 let result = await lambda.listFunctions(params).promise();\r\n\r\n\u00a0\u00a0\u00a0\u00a0 allLambdas = [...allLambdas, ...result.Functions];\r\n\r\n\u00a0\u00a0\u00a0\u00a0 nextMarker = result.NextMarker;\r\n\r\n} while (nextMarker != null);\r\n\r\nreturn allLambdas;\r\n\r\n}\r\n\r\nasync function checkConfig(funcName, resultArr) {\r\n\r\nlet retries = 5; \/\/sometimes listProvisionedConcurrencyConfigs() crashes\r\n\r\nwhile (retries-- &gt; 0) {\r\n\r\n\u00a0\u00a0\u00a0\u00a0 try {\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 var params = {\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 FunctionName: funcName\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 };\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 const conf = await lambda.listProvisionedConcurrencyConfigs(params).promise();\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 if (conf.ProvisionedConcurrencyConfigs.length &gt; 0) {\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 resultArr.push(conf);\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 }\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 break;\r\n\r\n\u00a0\u00a0\u00a0\u00a0 }\r\n\r\n\u00a0\u00a0\u00a0\u00a0 catch (ex) {\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 console.log(ex)\r\n\r\n\u00a0\u00a0\u00a0\u00a0 }\r\n\r\n}\r\n\r\n}<\/pre>\n<p><span data-preserver-spaces=\"true\">This code will return you an array of lambdas that have provisioned concurrency enabled.<\/span><strong><span data-preserver-spaces=\"true\">\u00a0Please note that this works only in the same region of the lambda<\/span><\/strong><span data-preserver-spaces=\"true\">! You can modify the code yourself to process all regions that you need, or just deploy this code in every region where you have lambdas.<\/span><\/p>\n<p><span data-preserver-spaces=\"true\">If you are looking for software developers who know cloud and blockchain, make sure to check <a href=\"https:\/\/oqtacore.com\">OQTACORE<\/a>.\u00a0<\/span><\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>AWS lambdas are great for many various use cases. They are cheap (if used correctly), fast and easy to maintain. A lambda once written can easily be launched again, unlike most other code that you have on your local disk. But there are some downfalls in lambdas &#8211; one is that they need some warm-up [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"_mo_disable_npp":"","yasr_overall_rating":0,"yasr_post_is_review":"","yasr_auto_insert_disabled":"","yasr_review_type":"","footnotes":""},"categories":[1],"tags":[18,17,16,26],"class_list":["post-837","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-it","tag-it-consulting","tag-system-integration","tag-tech-stuff"],"acf":{"image":842},"yasr_visitor_votes":{"number_of_votes":0,"sum_votes":0,"stars_attributes":{"read_only":false,"span_bottom":false}},"_links":{"self":[{"href":"https:\/\/oqtacore.com\/blog\/wp-json\/wp\/v2\/posts\/837","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/oqtacore.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/oqtacore.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/oqtacore.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/oqtacore.com\/blog\/wp-json\/wp\/v2\/comments?post=837"}],"version-history":[{"count":9,"href":"https:\/\/oqtacore.com\/blog\/wp-json\/wp\/v2\/posts\/837\/revisions"}],"predecessor-version":[{"id":1909,"href":"https:\/\/oqtacore.com\/blog\/wp-json\/wp\/v2\/posts\/837\/revisions\/1909"}],"wp:attachment":[{"href":"https:\/\/oqtacore.com\/blog\/wp-json\/wp\/v2\/media?parent=837"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/oqtacore.com\/blog\/wp-json\/wp\/v2\/categories?post=837"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/oqtacore.com\/blog\/wp-json\/wp\/v2\/tags?post=837"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}