Notify HipChat with AWS Lambda (Python)

What you want to do

HipChat API Token and ROOM ID

There are other ways, but here we will notify you by the user's API Token and ROOM ID.

apiaccess.png

You can check the ROOM ID from the Menu at the top right of the screen with ↓. That's the API ID (probably a 7 digit number).

API Token is issued by ↓.

Label can be anything. Scopes chose Send Notification. When you press Create, an alphanumeric Token of about 41 characters will be issued.

token.png

Write a script and upload

Normally, the script you wrote is pasted in the AWS Console, but this time we will use requests(external module), so upload it as .zip that includes the external module.

$ mkdir {your-project-dir}

Install requests with pip. Specify the installation destination with the -t Option.

$ pip install requests -t {your-project-dir}

Save the script body with the file name {your-project-dir} /lambda_function.py.

#!/usr/bin/env python
# encoding: utf-8

import json
import requests

def lambda_handler(event, context):
    # HipChat IDs.
    hipchat_token = u'{41-digit alphanumeric Token here}'
    hipchat_roomid = u'{7 digit ROOM ID here}'
    
    # :see: https://developer.atlassian.com/hipchat/guide/sending-messages
    def _payload(message):
        return json.dumps({
            u'from': u'FROM',
            u'message_format': u'text',
            u'color': u'random',
            u'message': message
        })
    
    # :see: https://developer.atlassian.com/hipchat/guide/hipchat-rest-api?_ga=1.190068904.2037217368.1478496904
    headers = { u'Content-Type': u'application/json', u'Authorization': u'Bearer %s' % (hipchat_token) }
    
    # send a message to HipChat.
    res = requests.post(u'https://api.hipchat.com/v2/room/%s/notification' % (hipchat_roomid), data=_payload('hello world !'), headers=headers)
    
    return res.status_code

Zip the script and external modules to .zip.

$ zip -r lambda.zip {your-project-dir}/*

After that, you can upload this lambda.zip from the AWS Console.

Recommended Posts

Notify HipChat with AWS Lambda (Python)
[AWS] Using ini files with Lambda [Python]
Connect to s3 with AWS Lambda Python
Python + Selenium + Headless Chromium with aws lambda
AWS CDK with Python
LINE BOT with Python + AWS Lambda + API Gateway
Serverless application with AWS SAM! (APIGATEWAY + Lambda (Python))
Operate TwitterBot with Lambda, Python
[Python] Scraping in AWS Lambda
AWS Lambda with PyTorch [Lambda import]
With skype, notify with skype from python!
Dynamic HTML pages made with AWS Lambda and Python
Deploy Python3 function with Serverless Framework on AWS Lambda
Create a Layer for AWS Lambda Python with Docker
I want to AWS Lambda with Python on Mac!
Make ordinary tweets fleet-like with AWS Lambda and Python
Summary if using AWS Lambda (Python)
[AWS] Create API with API Gateway + Lambda
Face detection with Lambda (Python) + Rekognition
[AWS] Try adding Python library to Layer with SAM + Lambda (Python)
Write AWS Lambda function in Python
Run Python on Schedule on AWS Lambda
Using Lambda with AWS Amplify with Go
Create API with Python, lambda, API Gateway quickly using AWS SAM
Use PostgreSQL with Lambda (Python + psycopg2)
Site monitoring and alert notification with AWS Lambda + Python + Slack
[Python] Convert CSV file uploaded to S3 to JSON file with AWS Lambda
Manipulating kintone data with Python & C Data ODBC Driver from AWS Lambda
Install pip in Serverless Framework and AWS Lambda with Python environment
Manipulate DynamoDB data with Lambda (Node & Python)
I want to play with aws with python
[AWS] Link Lambda and S3 with boto3
[Python] Run Headless Chrome on AWS Lambda
Stream redmine updates to hipchat with python
[AWS] Do SSI-like things with S3 / Lambda
Touch AWS with Serverless Framework and Python
Try assigning or switching with Python: lambda
I just did FizzBuzz with AWS Lambda
ImportError when trying to use gcloud package with AWS Lambda Python version
FizzBuzz with Python3
Scraping with Python
Statistics with python
[AWS] Create a Python Lambda environment with CodeStar and do Hello World
Scraping with Python
Python with Go
Twilio with Python
Integrate with Python
Play with 2016-Python
AES256 with python
Easy server monitoring with AWS Lambda (Python) and result notification in Slack
Tested with Python
python starts with ()
with syntax (Python)
Bingo with python
Zundokokiyoshi with python
Upload what you got in request to S3 with AWS Lambda Python
Let Python notify
Excel with Python
Microcomputer with Python
Cast with python
AWS-Perform web scraping regularly with Lambda + Python + Cron