{"id":26055,"date":"2024-04-04T18:22:19","date_gmt":"2024-04-04T09:22:19","guid":{"rendered":"https:\/\/www.skyarch.net\/blog\/?p=26055"},"modified":"2024-04-04T18:22:19","modified_gmt":"2024-04-04T09:22:19","slug":"aws-neptune%e3%81%ablambda%e3%81%8b%e3%82%89%e3%82%a2%e3%82%af%e3%82%bb%e3%82%b9%e3%81%97%e3%81%a6%e3%81%bf%e3%81%9f","status":"publish","type":"post","link":"https:\/\/www.skyarch.net\/blog\/aws-neptune%e3%81%ablambda%e3%81%8b%e3%82%89%e3%82%a2%e3%82%af%e3%82%bb%e3%82%b9%e3%81%97%e3%81%a6%e3%81%bf%e3%81%9f\/","title":{"rendered":"AWS Neptune\u306bLambda\u304b\u3089\u30a2\u30af\u30bb\u30b9\u3057\u3066\u307f\u305f"},"content":{"rendered":"<h2>\u306f\u3058\u3081\u306b<\/h2>\n<p>AWS Neptune\u3092\u4f7f\u3046\u6a5f\u4f1a\u304c\u3042\u308a\u3001Neptune\u4f5c\u6210\u3001Lambda\u304b\u3089Neptune\u3078\u306e\u30a2\u30af\u30bb\u30b9\u3092\u307e\u3068\u3081\u3066\u307f\u307e\u3057\u305f\u3002<\/p>\n<h2>\u76ee\u6b21<\/h2>\n<ul>\n<li><a href=\"#neptune\">AWS Neptune\u3068\u306f<\/a><\/li>\n<li><a href=\"#env\">Neptune\u3092\u6e96\u5099<\/a><\/li>\n<li><a href=\"#lambdaneptuneaccess\">Lambda\u304b\u3089Neptune\u3078\u30a2\u30af\u30bb\u30b9<\/a><\/li>\n<li><a href=\"#matome\">\u307e\u3068\u3081<\/a><\/li>\n<\/ul>\n<h2 id=\"neptune\">AWS Neptune\u3068\u306f<\/h2>\n<p>AWS Neptune\u306f\u3001\u30d5\u30eb\u30de\u30cd\u30fc\u30b8\u30c9\u306e\u30b0\u30e9\u30d5\u69cb\u9020\u3092\u5099\u3048\u305f\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u30b5\u30fc\u30d3\u30b9\u3067\u3059\u3002<br \/>\n\u57fa\u672c\u8981\u7d20\u306f\u4ee5\u4e0b\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<ul>\n<li>\u30ce\u30fc\u30c9\uff1a\u9802\u70b9(Node, Vertex)<\/li>\n<li>\u30a8\u30c3\u30b8\uff1a\u8fba(Edge\uff09\u30ce\u30fc\u30c9\u3068\u30ce\u30fc\u30c9\u306e\u95a2\u4fc2\u3092\u8868\u3059<\/li>\n<li>\u30d7\u30ed\u30d1\u30c6\u30a3\uff1a\u30ce\u30fc\u30c9\u3068\u30a8\u30c3\u30b8\u306e\u5c5e\u6027\uff08Key\/Value\u5f62\u5f0f\u3067\u4fdd\u6301\uff09<\/li>\n<\/ul>\n<a href=\"https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2024\/03\/nodeedge.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-26192\" src=\"https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2024\/03\/nodeedge.png\" alt=\"\" width=\"488\" height=\"329\" srcset=\"https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2024\/03\/nodeedge.png 635w, https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2024\/03\/nodeedge-300x202.png 300w\" sizes=\"auto, (max-width: 488px) 100vw, 488px\" \/><\/a>\n<p>\u3061\u306a\u307f\u306b\u30b0\u30e9\u30d5\u306f\u3001\u30bd\u30fc\u30b7\u30e3\u30eb\u30cd\u30c3\u30c8\u30ef\u30fc\u30af\u3001\u8def\u7dda\u56f3\u3001\u30ec\u30b3\u30e1\u30f3\u30c7\u30fc\u30b7\u30e7\u30f3\u30fb\u30fb\u30fb\u7b49\u3001\u8eab\u8fd1\u306a\u3068\u3053\u308d\u3067\u4f7f\u7528\u3055\u308c\u3066\u3044\u307e\u3059\u3002<\/p>\n<h3>\u30b5\u30dd\u30fc\u30c8\u3055\u308c\u3066\u3044\u308b\u30b0\u30e9\u30d5\u30e2\u30c7\u30eb\u3068\u30af\u30a8\u30ea\u8a00\u8a9e<\/h3>\n<a href=\"https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2024\/03\/f380bbb91cd62b599fa5f76d43023308.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-26195\" src=\"https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2024\/03\/f380bbb91cd62b599fa5f76d43023308.png\" alt=\"\" width=\"932\" height=\"485\" srcset=\"https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2024\/03\/f380bbb91cd62b599fa5f76d43023308.png 932w, https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2024\/03\/f380bbb91cd62b599fa5f76d43023308-300x156.png 300w, https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2024\/03\/f380bbb91cd62b599fa5f76d43023308-768x400.png 768w, https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2024\/03\/f380bbb91cd62b599fa5f76d43023308-728x379.png 728w\" sizes=\"auto, (max-width: 932px) 100vw, 932px\" \/><\/a>\n<p>Gremlin\u3001openCypher\u3001SPARQL \u306e3\u3064\u306e\u8a00\u8a9e\u3067\u30af\u30a8\u30ea\u304c\u53ef\u80fd\u3067\u3059\u3002\u4eca\u56de\u306f\u3001Gremlin\u3092\u4f7f\u7528\u3057\u307e\u3057\u305f\u3002<\/p>\n<h2 id=\"env\">Neptune\u3092\u6e96\u5099<\/h2>\n<p>Neptune\u3092\u4f5c\u6210\u3059\u308b\u524d\u306b\u3001\u3042\u3089\u304b\u3058\u3081\u30b5\u30d6\u30cd\u30c3\u30c8\u3092\u6301\u3064VPC\u3092\u4f5c\u6210\u3057\u3066\u304a\u304d\u307e\u3059\u3002<br \/>\n\u30de\u30cd\u30b8\u30e1\u30f3\u30c8\u30b3\u30f3\u30bd\u30fc\u30eb\u306eNeptune -&gt; \u30c7\u30fc\u30bf\u30d9\u30fc\u30b9 -&gt; \u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u3092\u4f5c\u6210\u3092\u9078\u629e\u3057\u3066\u4f5c\u6210\u3057\u307e\u3059\u3002<\/p>\n<a href=\"https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2024\/03\/3814cccd0aecaa9e5609239e4f9d841b.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-large wp-image-26198\" src=\"https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2024\/03\/3814cccd0aecaa9e5609239e4f9d841b-1024x168.png\" alt=\"\" width=\"728\" height=\"119\" srcset=\"https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2024\/03\/3814cccd0aecaa9e5609239e4f9d841b-1024x168.png 1024w, https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2024\/03\/3814cccd0aecaa9e5609239e4f9d841b-300x49.png 300w, https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2024\/03\/3814cccd0aecaa9e5609239e4f9d841b-768x126.png 768w, https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2024\/03\/3814cccd0aecaa9e5609239e4f9d841b-1536x252.png 1536w, https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2024\/03\/3814cccd0aecaa9e5609239e4f9d841b-728x119.png 728w, https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2024\/03\/3814cccd0aecaa9e5609239e4f9d841b.png 1560w\" sizes=\"auto, (max-width: 728px) 100vw, 728px\" \/><\/a>\n<p>\u753b\u9762\u306b\u6cbf\u3063\u3066\u5fc5\u8981\u306a\u9805\u76ee\u3092\u8a2d\u5b9a\u3057\u3066\u3044\u304d\u307e\u3059\u3002<\/p>\n<a href=\"https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2024\/03\/neptune1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-large wp-image-26199\" src=\"https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2024\/03\/neptune1-1024x936.png\" alt=\"\" width=\"728\" height=\"665\" srcset=\"https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2024\/03\/neptune1-1024x936.png 1024w, https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2024\/03\/neptune1-300x274.png 300w, https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2024\/03\/neptune1-768x702.png 768w, https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2024\/03\/neptune1-1536x1405.png 1536w, https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2024\/03\/neptune1-728x666.png 728w, https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2024\/03\/neptune1.png 1625w\" sizes=\"auto, (max-width: 728px) 100vw, 728px\" \/><\/a>\n<p>\u7121\u6599\u5229\u7528\u67a0\u3082\u7528\u610f\u3055\u308c\u3066\u3044\u308b\u306e\u3067\u3001\u4eca\u56de\u306f\u7121\u6599\u67a0\u3092\u9078\u629e\u3002<\/p>\n<a href=\"https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2024\/03\/neptune1-1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-26202\" src=\"https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2024\/03\/neptune1-1.png\" alt=\"\" width=\"728\" height=\"317\" srcset=\"https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2024\/03\/neptune1-1.png 728w, https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2024\/03\/neptune1-1-300x131.png 300w\" sizes=\"auto, (max-width: 728px) 100vw, 728px\" \/><\/a>\n<p>\u4e88\u3081\u7528\u610f\u3057\u305fVPC\u3068\u30b5\u30d6\u30cd\u30c3\u30c8\u3092\u8a2d\u5b9a\u3057\u307e\u3059\u3002<\/p>\n<a href=\"https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2024\/03\/neptune2.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-large wp-image-26204\" src=\"https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2024\/03\/neptune2-1024x424.png\" alt=\"\" width=\"728\" height=\"301\" srcset=\"https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2024\/03\/neptune2-1024x424.png 1024w, https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2024\/03\/neptune2-300x124.png 300w, https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2024\/03\/neptune2-768x318.png 768w, https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2024\/03\/neptune2-1536x636.png 1536w, https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2024\/03\/neptune2-728x301.png 728w, https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2024\/03\/neptune2.png 1828w\" sizes=\"auto, (max-width: 728px) 100vw, 728px\" \/><\/a>\n<p>Gremrin\u30af\u30a8\u30ea\u3092\u3059\u308b\u305f\u3081\u306b\u3001Jupyter\u30ce\u30fc\u30c8\u30d6\u30c3\u30af\u3082\u4e00\u7dd2\u306b\u4f5c\u6210\u3057\u307e\u3057\u305f\u3002<\/p>\n<a href=\"https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2024\/03\/neptune-notebook.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-large wp-image-26203\" src=\"https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2024\/03\/neptune-notebook-1024x444.png\" alt=\"\" width=\"728\" height=\"316\" srcset=\"https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2024\/03\/neptune-notebook-1024x444.png 1024w, https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2024\/03\/neptune-notebook-300x130.png 300w, https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2024\/03\/neptune-notebook-768x333.png 768w, https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2024\/03\/neptune-notebook-1536x667.png 1536w, https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2024\/03\/neptune-notebook-728x316.png 728w, https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2024\/03\/neptune-notebook.png 1825w\" sizes=\"auto, (max-width: 728px) 100vw, 728px\" \/><\/a>\n<p>\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u306e\u4f5c\u6210\u30dc\u30bf\u30f3\u3092\u30af\u30ea\u30c3\u30af\u3059\u308b\u3068Neptune\u304c\u4f5c\u6210\u3055\u308c\u307e\u3059\u3002<\/p>\n<a href=\"https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2024\/03\/neptune3.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-large wp-image-26205\" src=\"https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2024\/03\/neptune3-1024x391.png\" alt=\"\" width=\"728\" height=\"278\" srcset=\"https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2024\/03\/neptune3-1024x391.png 1024w, https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2024\/03\/neptune3-300x115.png 300w, https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2024\/03\/neptune3-768x293.png 768w, https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2024\/03\/neptune3-1536x587.png 1536w, https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2024\/03\/neptune3-728x278.png 728w, https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2024\/03\/neptune3.png 1825w\" sizes=\"auto, (max-width: 728px) 100vw, 728px\" \/><\/a>\n<p>\u4eca\u56de\u306f\u3001\u624b\u52d5\u3067\u30dd\u30c1\u30dd\u30c1\u3057\u306a\u304c\u3089\u4f5c\u6210\u3057\u307e\u3057\u305f\u304c\u3001CloudFormation \u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u3067\u74b0\u5883\u3092\u4f5c\u6210\u3059\u308bNeptune\u306e\u30cf\u30f3\u30ba\u30aa\u30f3\u3082\u3042\u308b\u306e\u3067\u3001\u691c\u8a3c\u3067\u3084\u3063\u3066\u307f\u308b\u306e\u3082\u3044\u3044\u3067\u3059\u306d\uff01<\/p>\n<p><a title=\"\u30b0\u30e9\u30d5\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u3063\u3066\u3069\u3093\u306a\u3082\u306e\uff1fAmazon Neptune \u3092\u4f7f\u3063\u3066 \u30b0\u30e9\u30d5\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u306e\u30af\u30a8\u30ea\u3092\u4f53\u9a13\u3057\u3088\u3046\uff08\u6e96\u5099\u7de8\uff09\" href=\"https:\/\/aws.amazon.com\/jp\/blogs\/news\/queries-with-neptune-preparation\/\" target=\"_blank\" rel=\"noopener\">\u30b0\u30e9\u30d5\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u3063\u3066\u3069\u3093\u306a\u3082\u306e\uff1fAmazon Neptune \u3092\u4f7f\u3063\u3066 \u30b0\u30e9\u30d5\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u306e\u30af\u30a8\u30ea\u3092\u4f53\u9a13\u3057\u3088\u3046\uff08\u6e96\u5099\u7de8\uff09<\/a><\/p>\n<h2 id=\"lambdaneptuneaccess\">Lambda\u304b\u3089Neptune\u3078\u30a2\u30af\u30bb\u30b9<\/h2>\n<p>\u4eca\u56de\u4f5c\u6210\u3057\u305f\u69cb\u6210\u306f\u4ee5\u4e0b\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<a href=\"https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2024\/03\/5fff315ed7bdbb34331bdfa513ae054c.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-26215\" src=\"https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2024\/03\/5fff315ed7bdbb34331bdfa513ae054c.png\" alt=\"\" width=\"935\" height=\"371\" srcset=\"https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2024\/03\/5fff315ed7bdbb34331bdfa513ae054c.png 935w, https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2024\/03\/5fff315ed7bdbb34331bdfa513ae054c-300x119.png 300w, https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2024\/03\/5fff315ed7bdbb34331bdfa513ae054c-768x305.png 768w, https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2024\/03\/5fff315ed7bdbb34331bdfa513ae054c-728x289.png 728w\" sizes=\"auto, (max-width: 935px) 100vw, 935px\" \/><\/a>\n<p>Lambda\u3067\u306f\u4e0b\u8a18\u3092\u304a\u3053\u306a\u3044\u307e\u3059\u3002<\/p>\n<ol>\n<li>Neptune\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u306b\u63a5\u7d9a<\/li>\n<li>Gremrin\u30af\u30a8\u30ea\u751f\u6210<\/li>\n<li>\u751f\u6210\u3057\u305fGremrin\u30af\u30a8\u30ea\u3092\u5b9f\u884c<\/li>\n<li>\u30af\u30a8\u30ea\u306e\u5b9f\u884c\u7d50\u679c\u3092\u30ec\u30b9\u30dd\u30f3\u30b9\u3068\u3057\u3066\u30e6\u30fc\u30b6\u30fc\u306b\u8fd4\u5374<\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n<h3>\uff11\uff0eNeptune\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u306b\u63a5\u7d9a<\/h3>\n<p>Neptune\u3078\u306e\u63a5\u7d9a\u306b\u95a2\u3059\u308b\u30ed\u30b8\u30c3\u30af\u3002<br \/>\n\u3053\u3061\u3089\u3092\u53c2\u8003\u306b\u3057\u3066\u5b9f\u88c5\u3002<br \/>\n<a title=\"AWS Lambda Amazon Neptune \u95a2\u6570\u306e\u4f8b\" href=\"https:\/\/docs.aws.amazon.com\/ja_jp\/neptune\/latest\/userguide\/lambda-functions-examples.html#lambda-functions-examples-python\" target=\"_blank\" rel=\"noopener\">AWS Lambda Amazon Neptune \u95a2\u6570\u306e\u4f8b<\/a><br \/>\n<a title=\"\u7f72\u540d\u30d0\u30fc\u30b8\u30e7\u30f3 4 \u7f72\u540d\u3092\u4f7f\u7528\u3057\u3066 Neptune \u306b\u63a5\u7d9a\" href=\"https:\/\/docs.aws.amazon.com\/ja_jp\/neptune\/latest\/userguide\/iam-auth-connecting-python.html\" target=\"_blank\" rel=\"noopener\">\u7f72\u540d\u30d0\u30fc\u30b8\u30e7\u30f3 4 \u7f72\u540d\u3092\u4f7f\u7528\u3057\u3066 Neptune \u306b\u63a5\u7d9a<\/a><\/p>\n<p>Neptune\u304c IAM\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u8a8d\u8a3c\uff1a\u3042\u308a\u306e\u5834\u5408\u3001\u30d0\u30fc\u30b8\u30e7\u30f3 4 \u7f72\u540d\u3092\u4f7f\u7528\u3057\u3066 Neptune \u306b\u63a5\u7d9a\u3092\u884c\u3044\u307e\u3059\u3002<br \/>\n\u74b0\u5883\u5909\u6570\u304b\u3089AWS\u306e\u8a8d\u8a3c\u60c5\u5831\u3092\u53d6\u5f97\u3057\u3001Neptune\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u3078\u306e\u30ea\u30af\u30a8\u30b9\u30c8\u306bSigV4\u8a8d\u8a3c\u3092\u8ffd\u52a0\u3002<\/p>\n<p>\u203b\u53c2\u8003\u306b\u3057\u305f\u30b3\u30fc\u30c9\u3067\u306f\u3001\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9URL\u3068\u30ea\u30af\u30a8\u30b9\u30c8\u30d8\u30c3\u30c0\u30fc\u306e\u30a2\u30a4\u30c6\u30e0\u3092List\u578b\u3067\u8fd4\u3057\u3066\u3044\u305f\u3051\u3069\u3001Dict\u578b\u3067\u8fd4\u3055\u306a\u3044\u3068\u30a8\u30e9\u30fc\u3068\u306a\u308a\u307e\u3057\u305f\u3002<\/p>\n<pre class=\"lang:default decode:true\" title=\"\u74b0\u5883\u5909\u6570\u304b\u3089AWS\u306e\u8a8d\u8a3c\u60c5\u5831\u3092\u53d6\u5f97\u3057\u3001Neptune\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u3078\u306e\u30ea\u30af\u30a8\u30b9\u30c8\u306bSigV4\u8a8d\u8a3c\u3092\u8ffd\u52a0\u3059\u308b\"># IAM\u8a8d\u8a3c\u3092\u4f7f\u7528\u3057\u3066Neptune\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u3078\u306e\u30ea\u30af\u30a8\u30b9\u30c8\u3092\u6e96\u5099\u3059\u308b\u95a2\u6570\ndef prepare_iamdb_request(database_url):\n\n    service = \"neptune-db\"\n    method = \"GET\"\n\n    # Lambd\u4e88\u7d04\u6e08\u307f\u74b0\u5883\u5909\u6570\u304b\u3089\u53d6\u5f97\n    access_key = os.environ['AWS_ACCESS_KEY_ID']\n    secret_key = os.environ['AWS_SECRET_ACCESS_KEY']\n    region = os.environ['AWS_REGION']\n    session_token = os.environ['AWS_SESSION_TOKEN']\n\n    # \u8a8d\u8a3c\u60c5\u5831\u306e\u4f5c\u6210\n    creds = SimpleNamespace(\n        access_key=access_key,\n        secret_key=secret_key,\n        token=session_token,\n        region=region,\n    )\n    # AWSRequest\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u4f5c\u6210\u3057\u3001SigV4Auth\u3092\u4f7f\u7528\u3057\u3066\u8a8d\u8a3c\u60c5\u5831\u3092\u8ffd\u52a0\n    request = AWSRequest(method=method, url=database_url, data=None)\n    SigV4Auth(creds, service, region).add_auth(request)\n\n    # \u30ea\u30af\u30a8\u30b9\u30c8\u30d8\u30c3\u30c0\u30fc\u3092\u8f9e\u66f8\u306b\u5909\u63db\n    dict_hedaer = {}\n    for k in request.headers.keys():\n        v = request.headers.get(k)\n        dict_hedaer[k] = v\n\n    return (database_url, dict_hedaer)<\/pre>\n<p>&nbsp;<\/p>\n<p>\u63a5\u7d9a\u60c5\u5831\uff08\u30a8\u30f3\u30c9\u30dd\u30a4\u30f3\u30c8\u3068\u30dd\u30fc\u30c8\u756a\u53f7\uff09\u3092\u53d6\u5f97\u3057\u3001\u30ea\u30e2\u30fc\u30c8\u63a5\u7d9a\u3092\u4f5c\u6210\u3002<\/p>\n<pre class=\"lang:default decode:true\" title=\"\u63a5\u7d9a\u60c5\u5831\u3092\u53d6\u5f97\u3057\u3001\u30ea\u30e2\u30fc\u30c8\u63a5\u7d9a\u3092\u4f5c\u6210\"># Neptune\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u3078\u306e\u63a5\u7d9a\u60c5\u5831\u3092\u53d6\u5f97\u3059\u308b\u95a2\u6570\ndef connection_info():\n    # Neptune\u30a8\u30f3\u30c9\u30dd\u30a4\u30f3\u30c8\u3068\u30dd\u30fc\u30c8\u3092\u53d6\u5f97\n    neptune_endpoint = os.environ[\"neptuneEndpoint\"]\n    neptune_port = os.environ[\"neptunePort\"]\n\n    # \u30c7\u30fc\u30bf\u30d9\u30fc\u30b9URL\u3092\u4f5c\u6210\n    database_url = \"wss:\/\/{}:{}\/gremlin\".format(neptune_endpoint, neptune_port)\n\n    if \"USE_IAM\" in os.environ and os.environ[\"USE_IAM\"] == \"true\":\n\u3000\u3000\u3000\u3000# \u30ea\u30af\u30a8\u30b9\u30c8\u306bSigV4\u8a8d\u8a3c\u3092\u8ffd\u52a0\n        return prepare_iamdb_request(database_url)\n    else:\n        return (database_url, {})\n\n# Neptune\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u3078\u306e\u30ea\u30e2\u30fc\u30c8\u63a5\u7d9a\u3092\u4f5c\u6210\u3059\u308b\u95a2\u6570\ndef create_remote_connection():\n\n    # \u63a5\u7d9a\u60c5\u5831\u3092\u53d6\u5f97\n    (database_url, headers) = connection_info()\n\n    return DriverRemoteConnection(\n        database_url, \"g\", pool_size=1, message_serializer=serializer.GraphSONSerializersV2d0(), headers=headers\n    )<\/pre>\n<p>&nbsp;<\/p>\n<p>Neptune \u30b3\u30cd\u30af\u30b7\u30e7\u30f3\u4f5c\u6210\u3002<\/p>\n<pre class=\"lang:default decode:true\" title=\"Neptune \u30b3\u30cd\u30af\u30b7\u30e7\u30f3\u4f5c\u6210\"># Neptune\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u3078\u306e\u63a5\u7d9a\u3092\u4f5c\u6210\u3057\u3001\u30b0\u30e9\u30d5\u30c8\u30e9\u30d0\u30fc\u30b5\u30eb\u30bd\u30fc\u30b9\u3092\u8fd4\u3059\u95a2\u6570\ndef create_connection():\n\n    # \u30ea\u30e2\u30fc\u30c8\u63a5\u7d9a\u3092\u4f5c\u6210\n    conn = create_remote_connection()\n\n    # \u30b0\u30e9\u30d5\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306e\u4f5c\u6210\n    graph = Graph()\n\n    # Neptune\u306b\u30ea\u30e2\u30fc\u30c8\u63a5\u7d9a\u3092\u8a2d\u5b9a\u3057\u305f\u30b0\u30e9\u30d5\u30c8\u30e9\u30d0\u30fc\u30b5\u30eb\u30bd\u30fc\u30b9\u3092\u4f5c\u6210\n    g = graph.traversal().withRemote(conn)\n\n    return g, conn<\/pre>\n<p>&nbsp;<\/p>\n<p>Neptune\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u3078\u306e\u63a5\u7d9a\u3092\u7ba1\u7406\u3059\u308b\u90e8\u5206\u306f\u30c7\u30b3\u30ec\u30fc\u30bf\u3067\u6e96\u5099\u3057\u3001Neptune\u3078\u306e\u63a5\u7d9a\u3068\u30c8\u30e9\u30f3\u30b6\u30af\u30b7\u30e7\u30f3\u3092\u5b9f\u88c5\u3057\u307e\u3057\u305f\u3002<br \/>\n\u3053\u306e\u63a5\u7d9a\u51e6\u7406\u3092\u547c\u3073\u51fa\u3059\u95a2\u6570\u5185\u3067\u4f8b\u5916\u304c\u767a\u751f\u3057\u305f\u5834\u5408\u3001\u30ed\u30fc\u30eb\u30d0\u30c3\u30af\u3055\u308c\u308b\u3088\u3046\u306b\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n<pre class=\"lang:default decode:true\" title=\"Neptune\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u3078\u306e\u63a5\u7d9a\u3092\u7ba1\u7406\u3059\u308b\u30c7\u30b3\u30ec\u30fc\u30bf\"># Neptune\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u3078\u306e\u63a5\u7d9a\u3092\u7ba1\u7406\u3059\u308b\u30c7\u30b3\u30ec\u30fc\u30bf\ndef with_neptune_connection(func):\n    @wraps(func)\n    def wrapper(*args, **kwargs):\n        # Neptune \u30b3\u30cd\u30af\u30b7\u30e7\u30f3\u306e\u4f5c\u6210\n        g, conn = create_connection()\n\n        # \u30c8\u30e9\u30f3\u30b6\u30af\u30b7\u30e7\u30f3\u306e\u4f5c\u6210\n        tran = g.tx()\n        try:\n            # \u30c8\u30e9\u30f3\u30b6\u30af\u30b7\u30e7\u30f3\u306e\u958b\u59cb\n            g_tran = tran.begin()\n\n            # \u30c7\u30b3\u30ec\u30fc\u30c8\u3055\u308c\u305f\u95a2\u6570\u3092\u5b9f\u884c\n            response = func(g_tran, *args, **kwargs)\n\n            # \u30b3\u30df\u30c3\u30c8\n            tran.commit()\n\n        except Exception as e:\n            logger.error(\"error: [{}] {}\".format(type(e), str(e)))\n            # \u30ed\u30fc\u30eb\u30d0\u30c3\u30af\n            tran.rollback()\n\n        finally:\n            # \u30c8\u30e9\u30f3\u30b6\u30af\u30b7\u30e7\u30f3\u3092\u9589\u3058\u308b\n            if tran.isOpen():\n                tran.close()\n\n            # \u30b3\u30cd\u30af\u30b7\u30e7\u30f3\u306e\u30af\u30ed\u30fc\u30ba\n            conn.close()\n\n        return response\n\n    return wrapper<\/pre>\n<p>Neptune\u63a5\u7d9a\u30ed\u30b8\u30c3\u30af\u306f\u3001Layer\u306b\u3057\u3066\u5171\u901a\u5316\u3057\u307e\u3057\u305f\u3002<\/p>\n<h3>\uff12\uff0eGremrin\u30af\u30a8\u30ea\u751f\u6210<\/h3>\n<p>\u6b21\u306f\u30ce\u30fc\u30c9\u4f5c\u6210\u306eAPI\u304c\u547c\u3073\u51fa\u3055\u308c\u305f\u6642\u306e\u30ed\u30b8\u30c3\u30af\uff08Gremrin\u30af\u30a8\u30ea\u751f\u6210\u3068\u5b9f\u884c\uff09\u3067\u3059\u3002<\/p>\n<pre class=\"lang:default decode:true\" title=\"app.py\"># \u65b0\u3057\u3044\u30ce\u30fc\u30c9\u3092\u4f5c\u6210\u3059\u308b\u305f\u3081\u306eAPI\u30a8\u30f3\u30c9\u30dd\u30a4\u30f3\u30c8\n@app.route(\"\/create-node\", methods=[\"POST\"], content_types=[\"application\/json\"], cors=True)\n@with_neptune_connection  # Neptune\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u3078\u306e\u63a5\u7d9a\u3092\u7ba1\u7406\u3059\u308b\u30c7\u30b3\u30ec\u30fc\u30bf\ndef create_node(g):\n\n    # \u30ea\u30af\u30a8\u30b9\u30c8\u30dc\u30c7\u30a3\u304b\u3089\u60c5\u5831\u3092\u53d6\u5f97\n    request_body = app.current_request.json_body\n\n    # \u30ce\u30fc\u30c9\u4f5c\u6210\u306egremlin\u30af\u30a8\u30ea\u3092\u4f5c\u6210\u3057\u3066\u5b9f\u884c\u3059\u308b\n    result = create_node_query_execute(request_body, g)\n\n    return response(200, json.dumps(result, ensure_ascii=True))<\/pre>\n<p>&nbsp;<\/p>\n<div>\n<div>\u30ea\u30af\u30a8\u30b9\u30c8\u30dc\u30c7\u30a3\u306f\u3001\u4e0b\u8a18\u306e\u3088\u3046\u306b\u3001\u30ce\u30fc\u30c9\u306e\u30e9\u30d9\u30eb\u540d\u3068\u30ce\u30fc\u30c9\u306e\u30d7\u30ed\u30d1\u30c6\u30a3\u3092\u30ea\u30b9\u30c8\u5f62\u5f0f\u3067\u6301\u3064\u3088\u3046\u306b\u3057\u307e\u3057\u305f\u3002<\/div>\n<\/div>\n<pre class=\"lang:default decode:true\" title=\"\u30ea\u30af\u30a8\u30b9\u30c8\u30dc\u30c7\u30a3\">{\n  \"node_label_name\": \"test-node\",\n  \"property_list\": [\n    {\n      \"property_name\": \"name\",\n      \"property_value\": \"test\u306e\u30ce\u30fc\u30c9\"\n    },\n    {\n      \"property_name\": \"memo\",\n      \"property_value\": \"api:create-node\u3067\u4f5c\u6210\"\n    }\n  ]\n}<\/pre>\n<p>&nbsp;<\/p>\n<h3>\uff13\uff0e\u751f\u6210\u3057\u305fGremrin\u30af\u30a8\u30ea\u3092\u5b9f\u884c<\/h3>\n<pre class=\"lang:default decode:true\" title=\"Gremrin\u30af\u30a8\u30ea\u3092\u4f5c\u6210\u3057\u3066\u5b9f\u884c\"># \u30ce\u30fc\u30c9\u4f5c\u6210\u306eGremrin\u30af\u30a8\u30ea\u3092\u4f5c\u6210\u3057\u3066\u5b9f\u884c\ndef create_node_query_execute(request_body: dict[str, Any], g: GraphTraversalSource) -&gt; str:\n\n    # \u30ce\u30fc\u30c9\u8ffd\u52a0 \u30af\u30a8\u30ea\u4f5c\u6210\n    query = g.addV(request_body[\"node_label_name\"])\n\n    # property_list\u304b\u3089\u5404\u30d7\u30ed\u30d1\u30c6\u30a3\u306e\u540d\u524d\u3068\u5024\u3092\u53d6\u5f97\u3057\u3066\n    # .property({property_name},{property_value})\u306e\u30af\u30a8\u30ea\u4f5c\u6210\n    property_list = request_body.get(\"property_list\", [])\n    for property in property_list:\n        query = query.property(property[\"property_name\"], property[\"property_value\"])\n\n    # \u30af\u30a8\u30ea\u5b9f\u884c\n    result = query.next()\n\n    return \"{0}\".format(result)<\/pre>\n<p>\u3053\u3053\u3067\u767a\u884c\u3055\u308c\u308bGremrin\u30af\u30a8\u30ea\u306f\u3001\u4e0b\u8a18\u306e\u69d8\u306b\u4f5c\u6210\u3055\u308c\u3001<span class=\"crayon-v\">result<\/span> <span class=\"crayon-o\">=<\/span> <span class=\"crayon-v\">query<\/span><span class=\"crayon-sy\">.<\/span><span class=\"crayon-e\">next<\/span><span class=\"crayon-sy\">(<\/span><span class=\"crayon-sy\">) \u3067\u30af\u30a8\u30ea\u304c\u767a\u884c\u3055\u308c\u307e\u3059\u3002<\/span><\/p>\n<pre class=\"lang:default decode:true\">g.addV(\"test-node\").property(\"name\",\"test\u306e\u30ce\u30fc\u30c9\").property(\"memo\",\"api:create-node\u3067\u4f5c\u6210\").next()<\/pre>\n<p>&nbsp;<\/p>\n<h3>\u30af\u30a8\u30ea\u306e\u5b9f\u884c\u7d50\u679c<\/h3>\n<a href=\"https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2024\/04\/944e21c2e7a58ddacd6ab67a3590c966.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-26246 size-full\" src=\"https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2024\/04\/944e21c2e7a58ddacd6ab67a3590c966.png\" alt=\"\" width=\"781\" height=\"370\" srcset=\"https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2024\/04\/944e21c2e7a58ddacd6ab67a3590c966.png 781w, https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2024\/04\/944e21c2e7a58ddacd6ab67a3590c966-300x142.png 300w, https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2024\/04\/944e21c2e7a58ddacd6ab67a3590c966-768x364.png 768w, https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2024\/04\/944e21c2e7a58ddacd6ab67a3590c966-728x345.png 728w\" sizes=\"auto, (max-width: 781px) 100vw, 781px\" \/><\/a>\n<p>\u30ce\u30fc\u30c9\u4f5c\u6210\u306eAPI\u306e\u5b9f\u884c\u7d50\u679c\u3067\u3059\u3002<br \/>\nv[xxxxxx-xxxx-xxxx-xxxx-xxxxxxxx]\u306e\u5024\u306f\u3001Neptune\u3067\u81ea\u52d5\u4f5c\u6210\u3055\u308c\u305fid\u304c\u8fd4\u5374\u3055\u308c\u307e\u3059\u3002<\/p>\n<h2 id=\"matome\">\u307e\u3068\u3081<\/h2>\n<p>AWS Neptune\u3068Lambda\u3092\u7d44\u307f\u5408\u308f\u305b\u3066\u30b0\u30e9\u30d5\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u3092\u64cd\u4f5c\u3057\u3066\u5206\u304b\u3063\u305f\u3053\u3068<\/p>\n<ul>\n<li>Lambda\u306fNeptune\u3068\u540c\u3058VPC\u5185\u306b\u4f5c\u6210\u304c\u5fc5\u8981<\/li>\n<li>IAM DB\u8a8d\u8a3c\u3042\u308a\u306e\u5834\u5408\u3001\u7f72\u540d\u30d0\u30fc\u30b8\u30e7\u30f3 4 \u3092\u4f7f\u7528\u3057\u4e00\u6642\u8a8d\u8a3c\u60c5\u5831\u3092\u53d6\u5f97\u3057\u3066\u63a5\u7d9a<\/li>\n<li>Gremrin\u30af\u30a8\u30ea\u306e\u5b9f\u884c\u306f\u3001\u00a0<code>.next()<\/code>\u00a0\u3084\u00a0<code>.iterate()<\/code> \u306a\u3069\u306e\u7d42\u4e86\u30b9\u30c6\u30c3\u30d7\u3067\u5b9f\u884c\u3055\u308c\u308b<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<p>\u4eca\u56de\u521d\u3081\u3066\u30b0\u30e9\u30d5\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u3068\u3044\u3046\u3082\u306e\u3092\u8abf\u67fb\u3057\u306a\u304c\u3089\u89e6\u3063\u3066\u307f\u3066\u3001\u30ea\u30ec\u30fc\u30b7\u30e7\u30ca\u30eb\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u3067\u8907\u96d1\u306a\u30af\u30a8\u30ea\u3067\u5b9f\u73fe\u3057\u3066\u3044\u305f\u30c7\u30fc\u30bf\u9593\u306e\u95a2\u4fc2\u6027\u3092\u53d6\u5f97\u3059\u308b\u3088\u3046\u306a\u30b1\u30fc\u30b9\u306b\u306f\u9069\u3057\u3066\u3044\u305f\u308a\u3068\u3001\u30b0\u30e9\u30d5\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u3068\u30ea\u30ec\u30fc\u30b7\u30e7\u30ca\u30eb\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u306e\u305d\u308c\u305e\u308c\u306e\u826f\u3044\u3068\u3053\u308d\u3092\u7d44\u307f\u5408\u308f\u305b\u3066\u3001\u4e21\u65b9\u3092\u5229\u7528\u3059\u308b\u306e\u304c\u3044\u3044\u3068\u601d\u3044\u307e\u3057\u305f\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u306f\u3058\u3081\u306b AWS Neptune\u3092\u4f7f\u3046\u6a5f\u4f1a\u304c\u3042\u308a\u3001Neptune\u4f5c\u6210\u3001Lambda\u304b\u3089Neptune\u3078\u306e\u30a2\u30af\u30bb\u30b9\u3092\u307e\u3068\u3081\u3066\u307f\u307e\u3057\u305f\u3002 \u76ee\u6b21 AWS Neptune\u3068\u306f Neptune\u3092\u6e96\u5099 Lambda\u304b\u3089Neptune&#8230;<\/p>\n","protected":false},"author":212,"featured_media":26240,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_locale":"ja","_original_post":"https:\/\/www.skyarch.net\/blog\/?p=26055","footnotes":""},"categories":[20,23],"tags":[],"class_list":{"0":"post-26055","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","7":"category-aws","8":"category-23","9":"ja"},"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.skyarch.net\/blog\/wp-json\/wp\/v2\/posts\/26055","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.skyarch.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.skyarch.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.skyarch.net\/blog\/wp-json\/wp\/v2\/users\/212"}],"replies":[{"embeddable":true,"href":"https:\/\/www.skyarch.net\/blog\/wp-json\/wp\/v2\/comments?post=26055"}],"version-history":[{"count":54,"href":"https:\/\/www.skyarch.net\/blog\/wp-json\/wp\/v2\/posts\/26055\/revisions"}],"predecessor-version":[{"id":26263,"href":"https:\/\/www.skyarch.net\/blog\/wp-json\/wp\/v2\/posts\/26055\/revisions\/26263"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.skyarch.net\/blog\/wp-json\/wp\/v2\/media\/26240"}],"wp:attachment":[{"href":"https:\/\/www.skyarch.net\/blog\/wp-json\/wp\/v2\/media?parent=26055"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.skyarch.net\/blog\/wp-json\/wp\/v2\/categories?post=26055"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.skyarch.net\/blog\/wp-json\/wp\/v2\/tags?post=26055"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}