page_type | languages | products | description | urlFragment | ||
---|---|---|---|---|---|---|
sample |
|
|
Azure Logic Apps enables the creation of powerful business workflows by integrating connectors for various services into a single graphical interface. |
aci-logicapps-integration |
Run sentiment analysis based on triggers with Azure Container Instances (ACI) and the ACI Logic Apps connector.
Azure Logic Apps enables the creation of powerful business workflows by integrating connectors for various services into a single graphical interface. With the connector for Azure Container Instances, you can run containerized applications as part of your Logic Apps workflow. This article covers how to create a simple workflow using the Azure Container Instances connector.
In this article, you create a logic app that regularly checks Email and Twitter for new items. If new items exist, the logic app runs a container in Azure Container Instances that analyze the sentiment of that text. When you're done, your logic app looks like this workflow at a high level:
To follow this quickstart, you need an email account from a provider that's supported by Logic Apps, such as Office 365 Outlook, Outlook.com, or Gmail. For other providers, review the connectors list here. This logic app uses an Office 365 Outlook account. If you use another email account, the overall steps are the same, but your UI might slightly differ.
Also, if you don't have an Azure subscription, sign up for a free Azure account.
And you need a Twitter account to get tweets.
Build the Docker images required for the containers on your local machine.
-
Clone this repository to your local machine.
git clone https://github.com/Azure-Samples/aci-logicapps-integration.git cd aci-logicapps-integration
-
Execute the command below to build and push the sentiment image to Docker Hub.
docker build -t YOURDOCKERACCOUNTNAME/sentiment . docker push YOURDOCKERACCOUNTNAME/sentiment
Sign in to the Azure portal with your Azure account credentials.
-
From the main Azure menu, choose Resource groups > + Add
-
Input the name of the resource group e.g.
MSAzure-ACI-AKS-LogicApp-Demo
, then click Create.
-
Open the resource group you just created, choose + Add on the nav bar.
-
Input
Text Analytics API
in search box, then choose the Text Analytics API > Create in results. -
Under Create Text Analytics API, provide details about your Text Analytics API as shown here. After you're done, choose Create.
Setting Value Description Name TextAnalyze The name for your Text Analytics API Subscription <your-Azure-subscription-name> The name for your Azure subscription Location East US The region where to store your logic app information Price tier F0 In this case, we will use the free version of this service. Resource group MSAzure-ACI-AKS-LogicApp-Demo The name for the Azure resource group used to organize related resources -
Navigate to the Text Analytics API you just created, copy the Endpoint. This will be used in logic app creation.
-
Then click Show access keys under Manage keys, and copy the Key. This will be used in logic app creation.
-
Open the resource group you just created, choose + Add on the nav bar.
-
Input
logic app
in search box, then choose the Logic App > Create in results. -
Under Create logic app, provide details about your logic app as shown here. After you're done, choose Pin to dashboard > Create.
Setting Value Description Name EmailAnalyze The name for your logic app Subscription <your-Azure-subscription-name> The name for your Azure subscription Resource group MSAzure-ACI-AKS-LogicApp-Demo The name for the Azure resource group used to organize related resources Location East US The region where to store your logic app information Log Analytics Off Keep the Off setting for diagnostic logging. -
After Azure deploys your app, the Logic Apps Designer opens and shows a page with an introduction video and commonly used triggers. Under Templates, choose Blank Logic App.
Next, add a trigger that fires when a new Email arrives. Every logic app must start with a trigger, which fires when a specific event happens or when a specific condition is met. Each time the trigger fires, the Logic Apps engine creates a logic app instance that starts and runs your workflow.
-
On the designer, enter
office 365 outlook
in the search box. Select this trigger: Office 365 Outlook - When a new email arrives. -
Login with your Office 365 account, provide this information for your trigger as shown and described:
Setting Value Description Folder Inbox The folder of your Outlook you want to monitor Interval 3 The number of intervals to wait between checks Frequency Minute The unit of time for each interval between checks Together, the interval and frequency define the schedule for your logic app's trigger. This logic app checks the feed every 3 minutes.
-
Save your logic app. On the designer toolbar, choose Save.
Your logic app is now live but doesn't do anything other than check the Email. So, add an action that responds when the trigger fires.
Now add an action to create an Azure Container Instances that analyze the sentiment of this email.
-
Under the When a new email arrives trigger, choose + New step > Add an action.
-
Under Choose an action, search for "content conversion", then select the Content Conversion - Html to text action.
-
In the Content textbox, choose the Body of the email as an input.
-
Under Choose an action, search for
container
, then select the Azure Container Instance - Create container group action. -
Choose a subscription, resource group, deployment location, and name for your container group.
-
In this case, the container group contains just one container. Choose a name for the container, then specify the following values:
Note: Update the image below to point to the one you built/pushed previously.
- Image:
YOURDOCKERACCOUNTNAME/sentiment
- CPU request: 1.0
- Memory request 1.5
- Image:
-
Create 3 container environment variables, then fill it with following values:
Setting Description BASE_URL The Endpoint of Text Analytics API. Remember to add a /
after the url if there is not.SUBSCRIPTION_KEY The Key of Text Analytics API. TEXT The text to get sentiment. -
Finally, set the RestartPolicy property to OnFailure. This ensures that your container will not restart if it exits successfully.
When you are done, the Create container group step will look something like this:
For simplicity, the logic app pulls the summarized text from the container logs. To ensure that the container has time to run, add delay logic to the app.
-
Click + New step > More > Add a do until, then click + Add an action inside of the Until
-
Under Choose an action, search for
container
, then select the Azure Container Instance - Get properties of a container group action. -
Choose a subscription, resource group, deployment location, and name for your container group.
-
Set the condition of the Until to this: state is equal to
Succeeded
. The state is the state of the group. -
Click Add a condition, then set the condition as same as the condition of the Unti.
-
In false part, click Add an action, search for
Delay
, then select the Schedule - Delay action. -
Choose the Schedule - Delay action and configure a 10 second delay.
Now add a new action to collect the logs from the completed container, which contain the summarized text of the article.
-
Click Add an action again in true part of the condition and search for
container
. -
Choose the Azure Container Instances - Get logs of a container action.
-
Fill in the subscription, resource group, container group name, and container name from previous steps.
Now we need to clean up the created resource group.
Now add a new action to collect the logs from the completed container, which contain the summarized text of the article.
-
Click Add an action again in true part of the condition and search for
container
. -
Choose the Azure Container Instances - Delete container group action.
-
Fill in the subscription, resource group, container group name, and container name from previous steps.
Send an email to your Outlook, and wait for 3 minutes.
Now you can see the flow has running history.
Click a running history, and navigate to Get logs of a container action.
Now you can see the sentiment of your email.
-
Navigate to the Logic App you just created, then click the Overview > Clone.
-
Input the name of new Logic App as
TwitterAnalyze
, then choose Create. -
Navigate to the
TwitterAnalyze
app, choose Logic App Designer. -
In Create container group action, remove all dynamic contents from it so we can delete previous actions.
Name Description Message Id The message id of your email. The plain text content The plain text content of your email. -
Delete Html to text and When a new email arrives.
-
Search for "twitter" then choose the Twitter - When a new tweet is posted.
-
Login with your Twitter account, provide this information for your trigger as shown and described:
Setting Value Description Search text from:USER_NAME This will fetch new tweets from a twitter user. Interval 3 The number of intervals to wait between checks Frequency Minute The unit of time for each interval between checks -
Then set the Create container group action like this.
When no longer needed, delete the resource group that contains your logic app and related resources. On the main Azure menu, go to Resource groups, and select the resource group for your logic app. Choose Delete resource group. Enter the resource group name as confirmation, and choose Delete.
Send a tweet with selected account in Twitter, and wait for 3 minutes.
Now you can see the flow has running history.
Click a running history, and navigate to Get logs of a container action.
Now you can see the sentiment of your tweet.