Skip to content

Commit

Permalink
race with lambda time out
Browse files Browse the repository at this point in the history
  • Loading branch information
Lou1415926 committed Nov 22, 2021
1 parent 8b3ae5c commit 554c7a6
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
11 changes: 10 additions & 1 deletion cf-custom-resources/lib/nlb-cert-validator-updater.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ exports.handler = async function (event, context) {
};

try {
await handler();
await Promise.race([exports.deadlineExpired(), handler(),]);
await report(event, context, "SUCCESS", physicalResourceID);
} catch (err) {
console.log(`Caught error for service ${serviceName}: ${err.message}`);
Expand Down Expand Up @@ -311,6 +311,15 @@ async function activateOption(option, loadBalancerDNS, loadBalancerHostedZone) {
}).promise();
}

exports.deadlineExpired = function () {
return new Promise(function (resolve, reject) {
setTimeout(
reject,
14 * 60 * 1000 + 30 * 1000 /* 14.5 minutes*/,
new Error(`Lambda took longer than 14.5 minutes to update custom domain`)
);
});
};

exports.withSleep = function (s) {
sleep = s;
Expand Down
24 changes: 24 additions & 0 deletions cf-custom-resources/test/nlb-cert-validator-uptater-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -307,5 +307,29 @@ describe("DNS Certificate Validation And Custom Domains for NLB", () => {
sinon.assert.callCount(mockWaitForCertificateValidation, 1);
});
});

test("lambda time out", () => {
withDeadlineExpired(_ => {
return new Promise(function (_, reject) {
reject(new Error("lambda time out error"));
});
});
AWS.mock("Route53", "listResourceRecordSets", mockListResourceRecordSets);
AWS.mock("ACM", "requestCertificate", mockRequestCertificate);
AWS.mock("ACM", "describeCertificate", mockDescribeCertificate);
AWS.mock("Route53", "changeResourceRecordSets", mockChangeResourceRecordSets);
AWS.mock("Route53", "waitFor", sinon.fake.resolves());
AWS.mock("ACM", "waitFor", sinon.fake.resolves());



let request = mockFailedRequest(/^lambda time out error \(Log: .*\)$/);
return LambdaTester(handler)
.event(mockRequest)
.expectResolve(() => {
expect(request.isDone()).toBe(true);
});
});

})
});

0 comments on commit 554c7a6

Please sign in to comment.