[PYTHON] Try using Azure Logic Apps

Introduction

Logic Apps, a PaaS service on Azure, GA in July 2016. This time, I tried to notify Slack using only the basic functions of Logic Apps.

Constitution

image

On the on-premise side, I put raspbian in the Raspberry Pi 2 Model B that is left over from the company. This time I will use Python to send to Azure Service Bus.

Azure has Logic Apps and Service Bus that exchanges messages.

For Logic Apps, you can select Twitter, Slack, etc. as the notification destination to social, but this time I chose Slack.

Preparation on the Python side

Python is already installed in rapbian, and the pip command to add various modules is also included, so after that, you can enter the following command and prepare to use the Azure SDK.

$ sudo pip install azure

The above command will install and use the Azure SDK for Python.

Creating Logic Apps

Create quickly from the portal screen. Recently, it has become available in the East Japan and West Japan regions. image

Creating a Service Bus

This is also created quickly from the portal screen. Since the price plan is for verification purposes, the cheapest Basic and the region were created in eastern Japan.

image

Create Queue

The name of the queue is pythontest, and the other items are for verification purposes, so create them with the defaults.

image

Access right settings

Set the Shared access policies for the created queue. Grants queue send and browse permissions to the policy name "user".

image

Make a note of the contents of the Policy name (user) and PRIMARY KEY of the created Shared access policies because they will be embedded in the code on the Python side. The contents of the CONNECTION STRING-PRIMARY KEY are required on the Logic Apps side, so make a note of them as well.

image

Logic Apps Logic Creation

When you deploy and first press "Edit" in Logic Apps, the Logic Apps Designer will open, so this time select "Empty Logic App". Since the designer screen opens, first set the trigger of Service Bus Queue. Select "Service Bus --When a message is received in a queue" and name the connection appropriately. For the connection string, enter the CONNECTION STRING of the Sercice Bus created earlier, but exclude the "Entity Path" at the end of the elements in that CONNECTION STARING. (Include only Endpoint, ShareAccessKeyName, SharedAccessKey)

image

Next, enter the name of the queue created in Service Bus in "Queue Name", and set the frequency and interval appropriately.

image

Then add an action. Click "Add Action" from "+ New Step". image

If you select Slack, it will be added.

image

After that, when you sign in to Slack, you can enter the channel name to post to Slack and the message to post. This time, in the MESSAGE TEXT field, we will simply use the content sent from Service Bus from the screen as it is.

image

Finally, don't forget to "save". image

Python sender

This is an example program on the sending side. Enter the name of the created Service Bus in service_namespace. Paste the contents of the Policy name and PRIMARY KEY that you wrote down earlier into share_access_key_name and shared_access_key_value. The first argument of bus_service.send_event sets the name of the queue created earlier (python test).

sender.py


# -*- coding: utf-8 -*-

import json
from azure.servicebus import ServiceBusService, Message, Queue

if __name__ == '__main__':
        bus_service = ServiceBusService(
          service_namespace='ktkrqiitatest',
          shared_access_key_name='user',
          shared_access_key_value='XXXXXXXXXXXXXXXXXXXXXXXXXX')

        msg = Message('Hello! World')

        bus_service.send_event('pythontest', msg)

Program execution

Now let's run a Python script.

$ python sender.py

Confirm that it was executed normally on the portal screen.

image

I've also received a notification message from BOT on Slack's #logicappstest channel!

image

in conclusion

This time I tried using Azure Logic Apps with a very simple mechanism, but the Azure side was all completed with just UI operations. If you want to create elaborate branches or actions, you need to edit the JSON code directly, but I would like to try it at another time.

Recommended Posts

Try using Azure Logic Apps
[Azure] Try using Azure Functions
Try using Tkinter
Try using docker-py
Try using cookiecutter
Try using PDFMiner
Try using geopandas
Try using Selenium
Try using scipy
Try using pandas.DataFrame
Try using django-swiftbrowser
Try using matplotlib
Try using tf.metrics
Try using PyODE
Try using Jupyter Notebook of Azure Machine Learning
Try using virtualenv (virtualenvwrapper)
Try using virtualenv now
Try using W & B
Try using Django templates.html
[Kaggle] Try using LGBM
Try using Python's feedparser.
Try using Python's Tkinter
Try using Tweepy [Python2.7]
Try using Pytorch's collate_fn
Try using PythonTex with Texpad.
Try using Jupyter's Docker image
Try using scikit-learn (1) --K-means clustering
Try function optimization using Hyperopt
Try using matplotlib with PyCharm
Try using Kubernetes Client -Python-
[Kaggle] Try using xg boost
Try using the Twitter API
Try using OpenCV on Windows
Try using Jupyter Notebook dynamically
Try using AWS SageMaker Studio
Try tweeting automatically using Selenium.
Try using SQLAlchemy + MySQL (Part 1)
Try using the Twitter API
Try using SQLAlchemy + MySQL (Part 2)
Try using Django's template feature
Try using the PeeringDB 2.0 API
Try using Pelican's draft feature
Try using pytest-Overview and Samples-
Try using folium with anaconda
[Statistics] [R] Try using quantile regression.
Try using design patterns (exporter edition)
Azure Functions: Try Durable Functions for Python
Try using Pillow on iPython (Part 1)
Try using Pillow on iPython (Part 2)
Try using Pleasant's API (python / FastAPI)
Try using LevelDB in Python (plyvel)
Try using pynag to configure Nagios
Try using PyCharm's remote debugging feature
Try using ArUco on Raspberry Pi
Try using cheap LiDAR (Camsense X1)
[Sakura rental server] Try using flask.
Try using Pillow on iPython (Part 3)
Reinforcement learning 8 Try using Chainer UI
Try to get statistics using e-Stat
Try using Python argparse's action API
Try using the Python Cmd module