@@ -7,6 +7,7 @@ const { checkVersion } = require("../lib/version-check");
77const Lambda = require ( "../lib/lambda" ) ;
88const Retry = require ( "async-retry" ) ;
99const { track } = require ( "../lib/analytics" ) ;
10+ const { RateLimit } = require ( "async-sema" ) ;
1011require ( "colors" ) ;
1112
1213const ONE_MIN_IN_MILLIS = 60 * 1000 ;
@@ -106,6 +107,7 @@ class AnalyzeLambdaColdStartsCommand extends Command {
106107
107108 const AWS = getAWSSDK ( ) ;
108109 const Lambda = new AWS . Lambda ( { region } ) ;
110+ const rateLimit = RateLimit ( 10 ) ; // rps
109111
110112 this . log (
111113 `${ region } : analyzing Provisioned Concurrency for ${ functionNames . length } functions`
@@ -117,6 +119,7 @@ class AnalyzeLambdaColdStartsCommand extends Command {
117119 qualifiers = [ ] ,
118120 marker
119121 ) => {
122+ await rateLimit ( ) ;
120123 const resp = await Lambda . listProvisionedConcurrencyConfigs ( {
121124 FunctionName : functionName ,
122125 Marker : marker
@@ -171,7 +174,7 @@ class AnalyzeLambdaColdStartsCommand extends Command {
171174 return _ . fromPairs ( pairs ) ;
172175 }
173176
174- async utilizationMetric ( functionName , qualifier ) {
177+ utilizationMetric ( functionName , qualifier ) {
175178 return {
176179 Id :
177180 functionName . toLowerCase ( ) . replace ( / \W / g, "" ) +
@@ -202,12 +205,12 @@ class AnalyzeLambdaColdStartsCommand extends Command {
202205 async getProvisionedConcurrencyUtilization ( region , functions ) {
203206 const AWS = getAWSSDK ( ) ;
204207 const CloudWatch = new AWS . CloudWatch ( { region } ) ;
205-
208+
206209 const startTime = new Date ( Date . now ( ) - global . minutes * ONE_MIN_IN_MILLIS ) ;
207210 const queries = _ . flatMap ( functions , ( { functionName, qualifiers } ) =>
208211 qualifiers . map ( qualifier => this . utilizationMetric ( functionName , qualifier ) )
209212 ) ;
210-
213+
211214 // CloudWatch only allows 100 queries per request
212215 const promises = _ . chunk ( queries , 100 ) . map ( async chunk => {
213216 const resp = await CloudWatch . getMetricData ( {
0 commit comments