Skip to content

Commit cd0a7b6

Browse files
author
Matten Mätlik
authored
Merge pull request #87 from Testlio/bugfix/larger-lambda-deploys-fail/OPS-98
OPS-98: Fix TooManyRequestsException deployment failures for larger services
2 parents a8b7863 + 56ace12 commit cd0a7b6

File tree

2 files changed

+21
-15
lines changed

2 files changed

+21
-15
lines changed

lib/cf-resources/lambda-version-resource/index.js

+20-14
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ function getRandomInt(max) {
1919
* @return {Promise} which resolves into the function configuration
2020
*/
2121
function getFunction(name) {
22+
console.log('Function name: ', name);
2223
return new Promise((resolve, reject) => {
2324
lambda.getFunctionConfiguration({
2425
FunctionName: name
@@ -36,6 +37,7 @@ function getFunction(name) {
3637
*/
3738
function getFunctionVersions(name, marker) {
3839
// Grab functions
40+
console.log('Function versions: ', name);
3941
return new Promise((resolve, reject) => {
4042
lambda.listVersionsByFunction({
4143
FunctionName: name,
@@ -61,6 +63,7 @@ function getFunctionVersions(name, marker) {
6163
* @return {Promise} which resolves into the newly published version
6264
*/
6365
function functionPublishVersion(name, description, hash) {
66+
console.log('Publishing function version: ', name);
6467
return new Promise((resolve, reject) => {
6568
lambda.publishVersion({
6669
FunctionName: name,
@@ -100,21 +103,24 @@ exports.handler = function(event, context) {
100103
return response.send(event, context, response.SUCCESS, {});
101104
}
102105

103-
// Grab the function first
104-
getFunction(properties.FunctionName).then(function(fn) {
105-
// Then grab all versions
106-
return getFunctionVersions(fn.FunctionName).then((versions) => {
107-
// Try to find one that matches the function configuration
108-
versions = versions.filter((version) => {
109-
// Ignore the latest pseudo-version
110-
return version.Version !== '$LATEST';
111-
});
106+
// Artificial delay to prevent deploys from hitting internal AWS API limits
107+
delay(getRandomInt(15000)).then(() => {
108+
// Grab the function first
109+
return getFunction(properties.FunctionName).then(function(fn) {
110+
// Then grab all versions
111+
return getFunctionVersions(fn.FunctionName).then((versions) => {
112+
// Try to find one that matches the function configuration
113+
versions = versions.filter((version) => {
114+
// Ignore the latest pseudo-version
115+
return version.Version !== '$LATEST';
116+
});
112117

113-
const trimmedFn = _.pick(fn, 'LastModified');
114-
return {
115-
fn: fn,
116-
version: _.find(versions, trimmedFn)
117-
};
118+
const trimmedFn = _.pick(fn, 'LastModified');
119+
return {
120+
fn: fn,
121+
version: _.find(versions, trimmedFn)
122+
};
123+
});
118124
});
119125
}).then((results) => {
120126
return delay(getRandomInt(5000)).then(function() {

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "lambda-tools",
3-
"version": "3.5.5",
3+
"version": "3.5.7",
44
"description": "Scripts for working with AWS Lambda backed microservices",
55
"main": "",
66
"scripts": {

0 commit comments

Comments
 (0)