Notifier HipChat avec AWS Lambda (Python)

Que veux-tu faire

Jeton d'API HipChat et ID de salle

Il existe d'autres moyens, mais ici, nous vous informerons par le jeton API de l'utilisateur et son ID ROOM.

apiaccess.png

Vous pouvez vérifier le ROOM ID à partir du menu en haut à droite de l'écran avec ↓. C'est l'ID API (probablement un numéro à 7 chiffres).

Le jeton API est émis par ↓.

L'étiquette peut être n'importe quoi. Scopes a choisi `` Envoyer une notification ''. Lorsque vous appuyez sur Créer, un jeton d'environ 41 caractères alphanumériques sera émis.

token.png

Ecrire un script et télécharger

Normalement, le script que vous avez écrit est collé sur la console AWS, mais cette fois, nous utiliserons [requêtes](module externe), donc téléchargez-le en tant que `` .zip '' qui inclut le module externe.

$ mkdir {your-project-dir}

Installez [requêtes] avec pip. Spécifiez la destination d'installation avec l'option `` -t ''.

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

Enregistrez le corps du script sous le nom de fichier {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'{Jeton alphanumérique à 41 chiffres ici}'
    hipchat_roomid = u'{ID de CHAMBRE à 7 chiffres ici}'
    
    # :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

Convertissez les scripts et les modules externes en `` .zip ''.

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

Après cela, vous pouvez télécharger ce `` lambda.zip '' à partir de la console AWS.

Recommended Posts

Notifier HipChat avec AWS Lambda (Python)
[AWS] Utilisation de fichiers ini avec Lambda [Python]
Connectez-vous à s3 avec AWS Lambda Python
LINE BOT avec Python + AWS Lambda + API Gateway
Application sans serveur avec AWS SAM! (APIGATEWAY + Lambda (Python))
Exploitez TwitterBot avec Lambda, Python
[Python] Scraping dans AWS Lambda
PyTorch avec AWS Lambda [importation Lambda]
Avec skype, notifiez avec skype de python!
Pages HTML dynamiques créées avec AWS Lambda et Python
Déployer la fonction Python 3 avec Serverless Framework sur AWS Lambda
Créer une couche pour AWS Lambda Python dans Docker
Je veux AWS Lambda avec Python sur Mac!
Créez des tweets ordinaires comme une flotte avec AWS Lambda et Python
Récapitulatif si vous utilisez AWS Lambda (Python)
[AWS] Créer une API avec API Gateway + Lambda
Détection de visage avec Lambda (Python) + Rekognition
[AWS] Essayez d'ajouter la bibliothèque Python à la couche avec SAM + Lambda (Python)
Ecrire une fonction AWS Lambda en Python
Exécutez Python selon la planification sur AWS Lambda
Créez rapidement une API avec Python, lambda et API Gateway à l'aide d'AWS SAM
Utiliser PostgreSQL avec Lambda (Python + psycopg2)
Surveillance du site et notification d'alerte avec AWS Lambda + Python + Slack
Manipulation des données Kintone avec le pilote ODBC Python & C Data d'AWS Lambda
Manipulation des données DynamoDB avec Lambda (Node et Python)
Je veux jouer avec aws avec python
[AWS] Associez Lambda et S3 à boto3
[Python] Exécutez Headless Chrome sur AWS Lambda
Diffusez les mises à jour de Redmine vers Hipchat avec Python
[AWS] Faites des choses de type SSI avec S3 / Lambda
Touchez AWS avec Serverless Framework et Python
Essayez d'attribuer ou de changer avec Python: lambda
Je viens de faire FizzBuzz avec AWS Lambda
ImportError lors de la tentative d'utilisation du package gcloud avec la version AWS Lambda Python
FizzBuzz en Python3
Grattage avec Python
Statistiques avec python
[AWS] Créez un environnement Python Lambda avec CodeStar et faites Hello World
Grattage avec Python
Python avec Go
Twilio avec Python
Intégrer avec Python
Jouez avec 2016-Python
AES256 avec python
Surveillance simple du serveur avec AWS Lambda (Python) et notification des résultats avec Slack
Testé avec Python
python commence par ()
avec syntaxe (Python)
Bingo avec python
Zundokokiyoshi avec python
Téléchargez ce que vous avez dans la demande vers S3 avec AWS Lambda Python
Laissez Python notifier
Excel avec Python
Micro-ordinateur avec Python
Cast avec python
Exécutez régulièrement le scraping WEB avec AWS-Lambda + Python + Cron