From ed37edf72e8f7dcc688509d420adb3e89674514c Mon Sep 17 00:00:00 2001 From: jessica-ritter <43350395+jessica-ritter@users.noreply.github.com> Date: Tue, 22 Oct 2019 11:43:29 -0700 Subject: [PATCH 1/5] =?UTF-8?q?add=20try/except=20around=20slack=20channel?= =?UTF-8?q?=20updates=20to=20handle=20keyerror=20when=20t=E2=80=A6=20(#16)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * add try/except around slack channel updates to handle keyerror when the bot is not allowed or channel is archived * move error handling to initial get channel call to catch errors where the channel id cannot be found * change payload[channel] to just channel cause its clear and less letters --- lambda/main.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/lambda/main.py b/lambda/main.py index 594a381..ae09f7b 100755 --- a/lambda/main.py +++ b/lambda/main.py @@ -87,9 +87,12 @@ def get_slack_topic(channel): Names=[os.environ['SLACK_API_KEY_NAME']], WithDecryption=True)['Parameters'][0]['Value'] payload['channel'] = channel - r = requests.post('https://slack.com/api/conversations.info', data=payload) - current = r.json()['channel']['topic']['value'] - logger.debug("Current Topic: '{}'".format(current)) + try: + r = requests.post('https://slack.com/api/conversations.info', data=payload) + current = r.json()['channel']['topic']['value'] + logger.debug("Current Topic: '{}'".format(current)) + except KeyError: + logger.critical("Could not find '{}' on slack, has the on-call bot been removed from this channel?".format(channel)) return current From d2b38c7948e0feb2f719142cc12f2b439d4559b3 Mon Sep 17 00:00:00 2001 From: "E. Dunham" Date: Fri, 8 Jan 2021 12:04:26 -0800 Subject: [PATCH 2/5] Requests deprecation: use unaffected runtime https://aws.amazon.com/blogs/compute/upcoming-changes-to-the-python-sdk-in-aws-lambda/ Vendored requests is being removed from the Python 3.6 runtime on Jan 31. The Python 3.8 runtime is unaffected. Other ways to address this deprecation would be to replace requests usage with urllib3 usage, or to add a dependency on a lambda layer which provides requests. --- deployment.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deployment.yml b/deployment.yml index 2ab9251..c2f79bc 100644 --- a/deployment.yml +++ b/deployment.yml @@ -90,7 +90,7 @@ Resources: Type: AWS::Serverless::Function Properties: Handler: main.handler - Runtime: python3.6 + Runtime: python3.8 Timeout: 120 CodeUri: Bucket: !Ref Bucket From 5f564186cbb02d8e90524041fb46cac110146ebe Mon Sep 17 00:00:00 2001 From: "E. Dunham" Date: Wed, 27 Jan 2021 15:54:37 -0800 Subject: [PATCH 3/5] add lambda layer for requests, + docs --- Makefile | 1 + deployment.yml | 2 ++ 2 files changed, 3 insertions(+) diff --git a/Makefile b/Makefile index 8a46e52..b2a637d 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,5 @@ STACKNAME_BASE=pagerduty-oncall-chat-topic +# if REGION is changed, use table in https://aws.amazon.com/blogs/compute/upcoming-changes-to-the-python-sdk-in-aws-lambda/ to update ChatTopicFunction lambda layer value REGION="ca-central-1" # Bucket in REGION that is used for deployment (`pd-oncall-chat-topic` is already used) BUCKET=$(STACKNAME_BASE) diff --git a/deployment.yml b/deployment.yml index c2f79bc..52a1fe0 100644 --- a/deployment.yml +++ b/deployment.yml @@ -95,6 +95,8 @@ Resources: CodeUri: Bucket: !Ref Bucket Key: !Ref md5 + Layers: + - arn:aws:lambda:ca-central-1:778625758767:layer:AWSLambda-Python-AWS-SDK:4 # for ca-central-1 region Environment: Variables: PD_API_KEY_NAME: !Ref PDSSMKeyName From 15c8ab3433eab96ee43403ccf606f8007123db13 Mon Sep 17 00:00:00 2001 From: bjtabo Date: Mon, 27 Mar 2023 20:38:01 -0600 Subject: [PATCH 4/5] prueba de ariel para uso de github --- lambda/main.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lambda/main.py b/lambda/main.py index ae09f7b..ea2e9ce 100755 --- a/lambda/main.py +++ b/lambda/main.py @@ -223,3 +223,9 @@ def handler(event, context): # Start threads and wait for all to finish [t.start() for t in threads] [t.join() for t in threads] + +#cambiar codifgo para prueba +def do_work( + ddb, table, schedule, slack, hipchat, sched_name, username, topic + ): + \ No newline at end of file From 4c9eb704da6afa1bf48e2532a88102394e6a86ad Mon Sep 17 00:00:00 2001 From: bjtabo Date: Mon, 27 Mar 2023 20:39:35 -0600 Subject: [PATCH 5/5] prueba de ariel para uso de github1 --- lambda/main.py | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/lambda/main.py b/lambda/main.py index ea2e9ce..4554575 100755 --- a/lambda/main.py +++ b/lambda/main.py @@ -211,21 +211,3 @@ def do_work(obj): logger.critical("HipChat is not supported yet. Ignoring this entry...") sema.release() - -def handler(event, context): - print(event) - ddb = boto3.client('dynamodb') - response = ddb.scan(TableName=os.environ['CONFIG_TABLE']) - threads = [] - for i in response['Items']: - thread = threading.Thread(target=do_work, args=(i,)) - threads.append(thread) - # Start threads and wait for all to finish - [t.start() for t in threads] - [t.join() for t in threads] - -#cambiar codifgo para prueba -def do_work( - ddb, table, schedule, slack, hipchat, sched_name, username, topic - ): - \ No newline at end of file