以下为解决该问题的代码示例:
import requests
import json
def lambda_handler(event, context):
query = 'g.V().limit(1)' # Sample openCypher query
headers = {"Content-Type": "application/json"}
url = "https://:/gremlin"
data = json.dumps({"gremlin": query})
response = requests.post(url, data=data, headers=headers, verify=False)
print(response.content)
return {
'statusCode': 200,
'body': json.dumps('Query executed successfully!')
}
其中,代码中的query可以根据实际需求进行修改。例如:
query = 'g.V().hasLabel("person").values("name").fold()'
该代码可以从label为“person”的顶点中获取“name”属性的值并进行折叠。
需要注意的是,在调用requests.post方法时,需要将verify设置为False,以避免因为证书问题引起的连接失败。另外还需要将url中的
通过以上的修改,可以成功地用openCypher查询向Neptune发起HTTP请求。