From 100b7cf502a3d23cdf630f6d18bda4025b7f0473 Mon Sep 17 00:00:00 2001 From: Jesse Decker Date: Fri, 22 Mar 2019 20:23:30 -0700 Subject: [PATCH] add timeouts to protect against cross-region latency --- cloudformation.yaml | 2 +- src/parsers/cloudwatch/chart.js | 9 +++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/cloudformation.yaml b/cloudformation.yaml index 743e971..c9fd6bf 100644 --- a/cloudformation.yaml +++ b/cloudformation.yaml @@ -50,7 +50,7 @@ Resources: Role: !GetAtt FunctionRole.Arn Runtime: nodejs8.10 MemorySize: 256 - Timeout: 10 + Timeout: 15 # Cross-region metrics lookup requires at least 10s Code: S3Bucket: !Sub 'aws-to-slack-${AWS::Region}' S3Key: release.zip diff --git a/src/parsers/cloudwatch/chart.js b/src/parsers/cloudwatch/chart.js index 02976b8..092c1c8 100644 --- a/src/parsers/cloudwatch/chart.js +++ b/src/parsers/cloudwatch/chart.js @@ -149,7 +149,10 @@ class AwsCloudWatchChart { this.height = _.get(config, "height", 250); this.metrics = []; - const clientOpt = {}; + const clientOpt = { + // Cross-region lookups requires at least 10s + httpOptions: { timeout: 10000 }, + }; if (this.region) { clientOpt.region = this.region; } @@ -225,7 +228,9 @@ class AwsCloudWatchChart { metricNamespace: query.Namespace, limit: 1, }; - const clientOpt = {}; + const clientOpt = { + httpOptions: { timeout: 10000 }, + }; if (this.region) { clientOpt.region = this.region; }