Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ariel prueba #33

Open
wants to merge 7 commits into
base: debug
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
4 changes: 3 additions & 1 deletion deployment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,13 @@ Resources:
Type: AWS::Serverless::Function
Properties:
Handler: main.handler
Runtime: python3.6
Runtime: python3.8
Timeout: 120
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
Expand Down
21 changes: 6 additions & 15 deletions lambda/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -208,15 +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]