Skip to content

Commit

Permalink
Merge pull request #4 from APPrise-Mobile/codepipelineSlackMessage
Browse files Browse the repository at this point in the history
Codepipeline slack message
  • Loading branch information
builtinnya authored Apr 3, 2018
2 parents 58e74fc + 3b0cc9f commit 2bd63a2
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,6 @@ virtualenv/
terraform.tfstate.backup
terraform.tfstate
secrets.tfvars

# Mac OS
.DS_Store
Binary file modified module/lambda/sns-to-slack.zip
Binary file not shown.
26 changes: 26 additions & 0 deletions sns-to-slack/lambda_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ def get_slack_emoji(event_src, topic_name, event_cond='default'):
'ok': ':ok:',
'alarm': ':fire:',
'insuffcient_data': ':question:'}},
'codepipeline': {
'notices': {
'STARTED': ':ok:',
'FAILED': ':fire:',
'SUCCEEDED': ':ok:'}},
'elasticache': {
'notices': {'default': ':stopwatch:'}},
'rds': {
Expand All @@ -83,6 +88,7 @@ def get_slack_username(event_src):
'cloudwatch': 'AWS CloudWatch',
'autoscaling': 'AWS AutoScaling',
'elasticache': 'AWS ElastiCache',
'codepipeline': 'AWS CodePipeline',
'rds': 'AWS RDS'}

try:
Expand Down Expand Up @@ -209,6 +215,26 @@ def lambda_handler(event, context):
"title": "Details",
"value": "<{0}|{1}>".format(title_str, title_lnk_str)
})
elif json_msg.get('source') == 'aws.codepipeline':
event_src = 'codepipeline'
message = json_msg.get('detail-type')
event_cond = json_msg.get('detail').get('state')
color_map = {
'STARTED': 'good',
'SUCCEEDED': 'good',
'FAILED': 'danger'
}
attachments = [{
'fallback': json_msg.get('detail-type'),
'color': color_map[event_cond],
"fields": [{
"title": "Pipeline",
"value": json_msg.get('detail').get('pipeline')
}, {
"title": "State",
"value": json_msg.get('detail').get('state')
}]
}]
else:
event_src = 'other'

Expand Down

0 comments on commit 2bd63a2

Please sign in to comment.