There are other ways, but here we will notify you by the user's API Token and ROOM ID.
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.
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