Skip to content
START FOR FREE
START FOR FREE
  • SUPPORT
  • COMMUNITY
Menu
  • SUPPORT
  • COMMUNITY
MENUMENU
  • Products
    • The World’s Fastest and Most Scalable Graph Platform

      LEARN MORE

      Watch a TigerGraph Demo

      TIGERGRAPH CLOUD

      • Overview
      • TigerGraph Cloud Suite
      • FAQ
      • Pricing

      USER TOOLS

      • GraphStudio
      • Insights
      • Application Workbenches
      • Connectors and Drivers
      • Starter Kits
      • openCypher Support

      TIGERGRAPH DB

      • Overview
      • GSQL Query Language
      • Compare Editions

      GRAPH DATA SCIENCE

      • Graph Data Science Library
      • Machine Learning Workbench
  • Solutions
    • The World’s Fastest and Most Scalable Graph Platform

      LEARN MORE

      Watch a TigerGraph Demo

      Solutions

      • Solutions Overview

      INCREASE REVENUE

      • Customer Journey/360
      • Product Marketing
      • Entity Resolution
      • Recommendation Engine

      MANAGE RISK

      • Fraud Detection
      • Anti-Money Laundering
      • Threat Detection
      • Risk Monitoring

      IMPROVE OPERATIONS

      • Supply Chain Analysis
      • Energy Management
      • Network Optimization

      By Industry

      • Advertising, Media & Entertainment
      • Financial Services
      • Healthcare & Life Sciences

      FOUNDATIONAL

      • AI & Machine Learning
      • Time Series Analysis
      • Geospatial Analysis
  • Customers
    • The World’s Fastest and Most Scalable Graph Platform

      LEARN MORE

      CUSTOMER SUCCESS STORIES

      • Ford
      • Intuit
      • JPMorgan Chase
      • READ MORE SUCCESS STORIES
      • Jaguar Land Rover
      • United Health Group
      • Xbox
  • Partners
    • The World’s Fastest and Most Scalable Graph Platform

      LEARN MORE

      PARTNER PROGRAM

      • Partner Benefits
      • TigerGraph Partners
      • Sign Up
      TigerGraph partners with organizations that offer complementary technology solutions and services.​
  • Resources
    • The World’s Fastest and Most Scalable Graph Platform

      LEARN MORE

      BLOG

      • TigerGraph Blog

      RESOURCES

      • Resource Library
      • Benchmarks
      • Demos
      • O'Reilly Graph + ML Book

      EVENTS & WEBINARS

      • Graph+AI Summit
      • Graph for All - Million Dollar Challenge
      • Events &Trade Shows
      • Webinars

      DEVELOPERS

      • Documentation
      • Ecosystem
      • Developers Hub
      • Community Forum

      SUPPORT

      • Contact Support
      • Production Guidelines

      EDUCATION

      • Training & Certifications
  • Company
    • Join the World’s Fastest and Most Scalable Graph Platform

      WE ARE HIRING

      COMPANY

      • Company Overview
      • Leadership
      • Legal Terms
      • Patents
      • Security and Compliance

      CAREERS

      • Join Us
      • Open Positions

      AWARDS

      • Awards and Recognition
      • Leader in Forrester Wave
      • Gartner Research

      PRESS RELEASE

      • Read All Press Releases
      TigerGraph Recognized in 2022 Gartner® Critical Capabilities for Cloud Database Management Systems for Analytical Use Cases
      January 12, 2023
      Read More »

      NEWS

      • Read All News

      A Shock to the System: ShockNet Predicts How Economic Shocks Could Affect the World Economy

      TigerGraph Recognized for the First Time in the 2022 Gartner® Magic Quadrant™ for Cloud Database Management Systems

  • START FREE
    • The World’s Fastest and Most Scalable Graph Platform

      GET STARTED

      • Request a Demo
      • CONTACT US
      • Try TigerGraph
      • START FREE
      • TRY AN ONLINE DEMO

Update TigerGraph Vertex Data Via REST API Using AWS Alexa

  • Emily McAuliffe
  • July 8, 2020
  • Developers
  • Blog >
  • Update TigerGraph Vertex Data Via REST API Using AWS Alexa

Originally posted on Medium by Kelley Brigman. Follow Kelley on Medium and Linkedin.

This article will demonstrate how to update data in an existing TigerGraph vertex using voice commands given to an Alexa-enabled device. To complete the setup, you will need:

  • An AWS account, including privileges to modify VPC network settings and create new objects like Lambda Functions
  • An Amazon Alexa Developer account
  • Access to an Alexa device that is configured for your Amazon Alexa Developer account
  • Access to a TigerGraph Cloud instance with at least one existing vertex
  • All files necessary for this demonstration are available on Git.
  • OVERVIEW

Voice commands issued to an Alexa-enabled device will trigger the execution of an Alexa Skill. The Alexa skill interprets voice commands and translates them into instructions that are then sent to a Lambda Function that processes the instructions and performs appropriate actions for those instructions. In this example, the Lambda Function will read JSON data from a file in an S3 bucket and load the data (perform an UPSERT operation) into a TigerGraph vertex. This might be useful for many scenarios, like updating existing customer or sales data or updating the metadata that controls a data pipeline application.

The basic steps we will follow are:

  • Configure the Amazon Virtual Private Cloud (VPC)
  • Upload data to an Amazon S3 bucket
  • Create an Alexa Skill
  • Create an AWS Lambda Function
  • Add the Alexa Skill as a trigger for the Lambda Function
  • Add the Lambda Function as a destination for the Alexa Skill
  • Test!

VPC Configuration

Lambda Functions, like other AWS assets, are deployed into a subnet of a Virtual Private Cloud (VPC). AWS recommends that Lambda Functions be deployed into at least two subnets for high availability. Because our Lambda Function will use REST API methods to push data into TigerGraph, we must also create a NAT Gateway in our VPC that is accessible by both subnets used by our Lambda Function.

VPN Diagram

VPC subnets gain access to a NAT Gateway via a route table. Both subnets must be associated with a route table that has a path to the NAT Gateway. At minimum, the route table will look like this:

Route Table

Where 172.x.x.x/16 is the address for the VPC itself, 0.0.0.0/0 refers to the internet and nat-097afeecc20fd9172 is an AWS-generated name for the NAT Gateway. Together, these two route table entries grant traffic in the subnet permission to leave the subnet, move into local VPC space, then transit the NAT Gateway using the URL of the REST API that will be used to push data into TigerGraph Cloud. If you are unfamiliar with adding a NAT Gateway in your VPC, more information is available here.

Upload Data to Amazon S3

First, I will add a data file called business_entities.json to a S3 bucket in my account. I am also uploading an image that I want to display when the Alexa Skill finishes successfully.

S3 Objects

This data file is already formatted properly to be consumed by the TigerGraph REST API. For this example, I will be uploading two rows for a vertex that stores business entities:

{
"vertices": {
"business entity": {
"17735": {
"type" : { "value" : "company" },
"name" : { "value" : "Kam_Air" },
"url" : { "value" : "http://dbpedia.org/resource/Kam_Air" },
},
"878253": {
"type" : { "value" : "university" },
"name" : { "value" : "Belarusian_National_Technical_University" },
"url" : { "value" : 
http://dbpedia.org/resource/Belarusian_National_Technical_University" },
}}}}

Here, business_entity is the name of the vertex and 17735 and 878253 are the business entity (primary id) values. If records already exist for these ids, TigerGraph will update them, otherwise they will be inserted. Type, name and url are the vertex attributes. Note that attributes are not simple name-value pairs. The value for each attribute must be expressed as “attribute_name” : { “value” : “the_value_for_attribute” }.

Create an Alexa Skill

Alexa Skills are comprised of an Invocation and one or more intents. The Invocation initiates a command and intents allow you to use that command in different contexts. For example, the invocation might be “reload data for graph” and intents might be the graph name or a vertex within the graph. The invocation and the intents together form the complete Alexa command. This way we could write one Alexa Skill to load data into any table in any graph. For our example, however, we will have one skill for one graph vertex.

Log into the Alexa Developer Console and create a new Alexa Skill called UpdateVertexData using the Custom model and click Create skillImage for post

Choose a skill model

When prompted to choose a skill template, select Hello World Skill then click Continue with template.

Image for post

Choose a skill template

A new skill template will be created. After a minute or two, you will be directed to the Interaction Model form where we can build the behaviors for this Alexa Skill. From the menu on the left, click Invocation. Use update vertex for the Invocation Name.Image for post

Next, click Intents and then Add Intent. Enter business_entity for the name of the intent.

Image for post

Click the Create custom intent button. Next, we enter Sample Utterances. These are short phrases that are used to complete the Alexa command. You can enter multiple words or short phrases to make the Alexa command more conversational. For example, any of the following utterances will be considered valid when invoking our Alexa Skill.

Image for post

Intents and utterances 

With these four utterances, our Alexa command could be “Alexa, update vertex business entity”, “Alexa, update vertex business entities”, “Alexa, update vertex businesses” or “Alexa, update vertex business”. Any one of these phrases will have the same effect. Click Save Model. Then, from the navigation menu on the left, click Endpoint. You should see the Skill ID for this Alexa Skill. Click Copy to Clipboard. You will need this in the next step when we create a Lambda Function.

Image for post

Leave this window open. We will finish the Alexa Skill configuration in a later step.

Create a Lambda Function

Log into the AWS Console and select Lambda from the Services menu. Then click Create function. The function name will be UpdateVertexBusinessEntity and the runtime will be Python 3.7. Then click Create function.

Image for post
Create a new Lambda Function

In the Designer panel, click Add Trigger.

Image for post
 
Add a trigger
 

Select Alexa Skills Kit as the trigger and then paste in the Alexa Skills ID that you copied in a previous step. Then click Add.

Image for post
 
Link to an Alexa Skill

You should now see that the Alexa Skill has been added as a trigger for this Lambda Function.

Image for post

Alexa Skill trigger

The Alexa Skills Kit trigger is currently selected. Click on the attached box for the Lambda Function UpdateVertexBusinessEntity.

Scroll down, skipping over the Function Code section, to Environment Variables and click Edit. You will need to enter your AWS access key and secret access key, TigerGraph IP address (domain), TigerGraph secret, and S3 bucket name, the file name and prefix for the business_entity.json file and the tigergraph.jpg file (if you put them in a subdirectory, otherwise just use the file names). Set the following variables then click Save:

Image for post

Environment Variables 

Continue scrolling down to the Basic Settings section and click Edit. Change the Timeout setting to 2 minutes and 0 seconds. Then click Save.

Continue scrolling down to the VPC Section and click Edit. Select the name of your VPC and include at least two subnets that are associated with your NAT interface as described in the VPC Configuration section above. Also add at least one security group that allows egress from your VPC on ports used for TCP, HTTP and HTTPS. Then click Save.

Scroll back up to the Function Code section:

Image for post

On the right, look for the Actions drop down box. Select Upload a .zip file. Upload the zip file in /lambda/UpdateVertexBusinessEntity.zip from the git repository. Once uploaded, the Python code will be visible:

Image for post

Let’s take a look at the most important parts of the code. First, we create a function that connects to S3 and returns a connection:

def get_s3_conn():
    s3_conn = boto3.resource(
        ‘s3’,
        region_name=’us-east-1',
        aws_access_key_id=MY_AWS_ACCESS_KEY,
        aws_secret_access_key=MY_AWS_SECRET_ACCESS_KEY
    )    return s3_conn

We also create a function that gets an API token from TigerGraph. We cannot GET or POST using the TigerGraph API without a token:

def get_tg_auth_token() -> str:
try:
url = "{ip}:{port}/requesttoken?secret={secret}&lifetime={lt}".format(
    ip=tigergraph_ip,
    port=tigergraph_apitoken_port,
    secret=tigergraph_secret,
    lt=tigergraph_apitoken_lifetime
)    response = requests.get(url).json()
    return response['token']
except Exception as e:
    print('Error getting authentication token from TigerGraph: {0}'.format(e))

Next, we get the contents of the business_entity.json file from S3.

try:
    s3_object = s3_conn.Object(s3_bucket, s3_data_file).get()
    payload = s3_object['Body']
except Exception as e:
    print("Error getting metadata file from S3: {a}".format(a=e))
    return False

Now that we have the data, we can create our request header and then POST it. One of the benefits of TigerGraph is that each vertex or query is automatically accessible from a built-in REST interface. No coding is required.

try:
    url = "{ip}:{port}/graph/{graph}".format(
        ip=tigergraph_ip,
        port=tigergraph_apitoken_port,
        graph=tigergraph_graph_name
    )    response = requests.request(
        "POST", 
        url, 
        headers=request_header, 
        data=payload
    )except Exception as e:
    return_msg = e
else:
    return_msg = " reloaded successfully"

Last, after the data is posted to TigerGraph, we need to return a JSON structure to our Alexa skill so that an Alexa-enabled device can speak the return message. The response must be in the following format:

json_resp = {
"version": "1.0.0",
"sessionAttributes": {
"TigerGraph": "Load data"
},"response": {
"outputSpeech": {
"type": "PlainText",
"text": return_msg,
"ssml": "" + return_msg + ""
},
"card": {
"type": "Standard",
"title": tigergraph_graph_name,
"content": return_msg,
"text": return_msg,
"image": {
"smallImageUrl": "https://{0}.s3.amazonaws.com/{1}".format(s3_bucket, s3_image_file),"largeImageUrl": "https://{0}.s3.amazonaws.com/{1}".format(s3_bucket, s3_image_file)
}
},
"reprompt": {
"outputSpeech": {
"type": "PlainText",
"text": "Plain text string to speak",
"ssml": "SSML text string to speak"
}
},
"shouldEndSession": should_end_session
}
}

Click Save in the top right corner of the Lambda function.

Register the Alexa Skill as a trigger for the Lambda Function

In the upper right-hand corner of the Lambda Editor window, click the copy icon next to the lambda ARN:

Image for post

Return to the Alexa Developer Console. From the menu on the left, choose Endpoint.

Enter the ARN for the lambda function in both the default region and the North American region:

Image for post

From the menu on the left, click Interaction Model. Then click Build Model. We can now test the new skill!

Test!

We can test the new skill directly in the Alexa Developer Console. Simply click on the Test link on the top menu and make sure that skill testing is enabled for Development. You can then enter the text for the new skill. Simply update vertex should be sufficient:

Image for post

We can hear Alexa say that our vertex data was loaded successfully. We can also see the JSON input (to the Lambda function) and output (results from the lambda function):

Image for post

Input and Output

We can also see the image we uploaded along with the data. This shows the output for an Alexa-enabled device with a screen or mobile phone app:

Image for post

Alexa Screen Results

If testing passes in the Alexa Developer Console, we can then try our skill on an Alexa device. I can also see that the two rows from the business_entities.json file have been loaded into the business_entity vertex of my graph:

Image for post

TigerGraph Studio query results

Conclusion

I hope you found this post informative. This method for linking an Alexa Skill with a Lambda function is a quick and simple way to load graph data, but this pattern could be equally applicable for more complex interactions. In a future post I will explore other scenarios like voice-activated (and touchless) patient check-in functionality or a graph search application that finds health care providers based on proximity to a user’s location.

You Might Also Like

Developer Spotlight: Kapil Saini

Developer Spotlight: Kapil Saini

October 21, 2022
Graph Neural Network-based Graph Outlier Detection: A Brief Introduction

Graph Neural Network-based Graph Outlier Detection:...

September 15, 2022
Developer Spotlight: Renata Bastos Gottgtroy

Developer Spotlight: Renata Bastos Gottgtroy

September 12, 2022

Introducing TigerGraph 3.0

July 1, 2020

Everything to Know to Pass your TigerGraph Certification Test

June 24, 2020

Neo4j 4.0 Fabric – A Look Behind the Curtain

February 7, 2020

TigerGraph Blog

  • Categories
    • blogs
      • About TigerGraph
      • Benchmark
      • Business
      • Community
      • Compliance
      • Customer
      • Customer 360
      • Cybersecurity
      • Developers
      • Digital Twin
      • eCommerce
      • Emerging Use Cases
      • Entity Resolution
      • Finance
      • Fraud / Anti-Money Laundering
      • GQL
      • Graph Database Market
      • Graph Databases
      • GSQL
      • Healthcare
      • Machine Learning / AI
      • Podcast
      • Supply Chain
      • TigerGraph
      • TigerGraph Cloud
    • Graph AI On Demand
      • Analysts and Research
      • Customer 360 and Entity Resolution
      • Customer Spotlight
      • Development
      • Finance, Banking, Insurance
      • Keynote
      • Session
    • Video
  • Recent Posts

    • It’s Time to Harness the Power of Graph Technology [Infographic]
    • TigerGraph Showcases Unrivaled Performance at Scale
    • TigerGraph 101 An Introduction to Graph | Jan 26th @ 9am PST
    • Data Science Salon New York
    • Tech For Retail
    TigerGraph

    Product

    SOLUTIONS

    customers

    RESOURCES

    start for free

    TIGERGRAPH DB
    • Overview
    • Features
    • GSQL Query Language
    GRAPH DATA SCIENCE
    • Graph Data Science Library
    • Machine Learning Workbench
    TIGERGRAPH CLOUD
    • Overview
    • Cloud Starter Kits
    • Login
    • FAQ
    • Pricing
    • Cloud Marketplaces
    USEr TOOLS
    • GraphStudio
    • TigerGraph Insights
    • Application Workbenches
    • Connectors and Drivers
    • Starter Kits
    • openCypher Support
    SOLUTIONS
    • Why Graph?
    industry
    • Advertising, Media & Entertainment
    • Financial Services
    • Healthcare & Life Sciences
    use cases
    • Benefits
    • Product & Service Marketing
    • Entity Resolution
    • Customer 360/MDM
    • Recommendation Engine
    • Anti-Money Laundering
    • Cybersecurity Threat Detection
    • Fraud Detection
    • Risk Assessment & Monitoring
    • Energy Management
    • Network & IT Management
    • Supply Chain Analysis
    • AI & Machine Learning
    • Geospatial Analysis
    • Time Series Analysis
    success stories
    • Customer Success Stories

    Partners

    Partner program
    • Partner Benefits
    • TigerGraph Partners
    • Sign Up
    LIBRARY
    • Resources
    • Benchmark
    • Webinars
    Events
    • Trade Shows
    • Graph + AI Summit
    • Million Dollar Challenge
    EDUCATION
    • Training & Certifications
    Blog
    • TigerGraph Blog
    DEVELOPERS
    • Developers Hub
    • Community Forum
    • Documentation
    • Ecosystem

    COMPANY

    Company
    • Overview
    • Careers
    • News
    • Press Release
    • Awards
    • Legal
    • Patents
    • Security and Compliance
    • Contact
    Get Started
    • Start Free
    • Compare Editions
    • Online Demo - Test Drive
    • Request a Demo

    Product

    • Overview
    • TigerGraph 3.0
    • TIGERGRAPH DB
    • TIGERGRAPH CLOUD
    • GRAPHSTUDIO
    • TRY NOW

    customers

    • success stories

    RESOURCES

    • LIBRARY
    • Events
    • EDUCATION
    • BLOG
    • DEVELOPERS

    SOLUTIONS

    • SOLUTIONS
    • use cases
    • industry

    Partners

    • partner program

    company

    • Overview
    • news
    • Press Release
    • Awards

    start for free

    • Request Demo
    • take a test drive
    • SUPPORT
    • COMMUNITY
    • CONTACT
    • Copyright © 2023 TigerGraph
    • Privacy Policy
    • Linkedin
    • Facebook
    • Twitter

    Copyright © 2020 TigerGraph | Privacy Policy

    Copyright © 2020 TigerGraph Privacy Policy

    • SUPPORT
    • COMMUNITY
    • COMPANY
    • CONTACT
    • Linkedin
    • Facebook
    • Twitter

    Copyright © 2020 TigerGraph

    Privacy Policy

    • Products
    • Solutions
    • Customers
    • Partners
    • Resources
    • Company
    • START FREE
    START FOR FREE
    START FOR FREE
    TigerGraph
    PRODUCT
    PRODUCT
    • Overview
    • GraphStudio UI
    • Graph Data Science Library
    TIGERGRAPH DB
    • Overview
    • Features
    • GSQL Query Language
    TIGERGRAPH CLOUD
    • Overview
    • Cloud Starter Kits
    TRY TIGERGRAPH
    • Get Started for Free
    • Compare Editions
    SOLUTIONS
    SOLUTIONS
    • Why Graph?
    use cases
    • Benefits
    • Product & Service Marketing
    • Entity Resolution
    • Customer Journey/360
    • Recommendation Engine
    • Anti-Money Laundering (AML)
    • Cybersecurity Threat Detection
    • Fraud Detection
    • Risk Assessment & Monitoring
    • Energy Management
    • Network Resources Optimization
    • Supply Chain Analysis
    • AI & Machine Learning
    • Geospatial Analysis
    • Time Series Analysis
    industry
    • Advertising, Media & Entertainment
    • Financial Services
    • Healthcare & Life Sciences
    CUSTOMERS
    read all success stories

     

    PARTNERS
    Partner program
    • Partner Benefits
    • TigerGraph Partners
    • Sign Up
    RESOURCES
    LIBRARY
    • Resource Library
    • Benchmark
    • Webinars
    Events
    • Trade Shows
    • Graph + AI Summit
    • Graph for All - Million Dollar Challenge
    EDUCATION
    • TigerGraph Academy
    • Certification
    Blog
    • TigerGraph Blog
    DEVELOPERS
    • Developers Hub
    • Community Forum
    • Documentation
    • Ecosystem
    COMPANY
    COMPANY
    • Overview
    • Leadership
    • Careers  
    NEWS
    PRESS RELEASE
    AWARDS
    START FREE
    Start Free
    • Request a Demo
    • SUPPORT
    • COMMUNITY
    • CONTACT
    Dr. Jay Yu

    Dr. Jay Yu | VP of Product and Innovation

    Dr. Jay Yu is the VP of Product and Innovation at TigerGraph, responsible for driving product strategy and roadmap, as well as fostering innovation in graph database engine and graph solutions. He is a proven hands-on full-stack innovator, strategic thinker, leader, and evangelist for new technology and product, with 25+ years of industry experience ranging from highly scalable distributed database engine company (Teradata), B2B e-commerce services startup, to consumer-facing financial applications company (Intuit). He received his PhD from the University of Wisconsin - Madison, where he specialized in large scale parallel database systems

    Todd Blaschka | COO

    Todd Blaschka is a veteran in the enterprise software industry. He is passionate about creating entirely new segments in data, analytics and AI, with the distinction of establishing graph analytics as a Gartner Top 10 Data & Analytics trend two years in a row. By fervently focusing on critical industry and customer challenges, the companies under Todd's leadership have delivered significant quantifiable results to the largest brands in the world through channel and solution sales approach. Prior to TigerGraph, Todd led go to market and customer experience functions at Clustrix (acquired by MariaDB), Dataguise and IBM.