-- 前提: Gremlin コンソールインストール済み
-- 1. S3バケット作成
aws s3 mb s3://bucket123
aws s3 ls
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "",
"Effect": "Allow",
"Principal": {
"Service": [
"rds.amazonaws.com"
]
},
"Action": "sts:AssumeRole"
}
]
}
aws iam create-role \
--role-name role01 \
--assume-role-policy-document file://role01.json
-- 3. ポリシーをロールにアタッチ
aws iam attach-role-policy \
--policy-arn arn:aws:iam::aws:policy/AmazonS3ReadOnlyAccess \
--role-name role01
-- 4. DBクラスター作成
aws neptune create-db-cluster \
--db-cluster-identifier cluster01 \
--engine neptune \
--engine-version 1.0.5.0 \
--port 8182 \
--no-storage-encrypted \
--no-deletion-protection
aws neptune create-db-instance \
--db-cluster-identifier cluster01 \
--engine neptune \
--db-instance-identifier instance01 \
--db-instance-class db.t3.medium \
--no-multi-az \
--no-auto-minor-version-upgrade
aws neptune describe-db-clusters --db-cluster-identifier cluster01
aws neptune describe-db-instances --db-instance-identifier instance01
-- 5. IAMロールをクラスターに関連付ける
aws neptune add-role-to-db-cluster \
--db-cluster-identifier cluster01 \
--role-arn arn:aws:iam::999999999999:role/role01
aws neptune describe-db-clusters --db-cluster-identifier cluster01
-- 6. S3ゲートウェイエンドポイントの作成
aws ec2 create-vpc-endpoint \
--vpc-endpoint-type Gateway \
--vpc-id vpc-xxxxxxxxxxxxxxxxx \
--service-name com.amazonaws.ap-northeast-1.s3 \
--route-table-ids rtb-xxxxxxxxxxxxxxxxx
-- 7. ロードするグラフデータの作成
vim vertex01.csv
~id, name:String, age:Int, lang:String, interests:String[], ~label
v1, "marko", 29, , "sailing;graphs", person
v2, "lop", , "java", , software
vim edge01.csv
~id, ~from, ~to, ~label, weight:Double
e1, v1, v2, created, 0.4
aws s3 ls s3://bucket123 --recursive --human-readable
aws s3 cp vertex01.csv s3://bucket123/neptune/
aws s3 cp edge01.csv s3://bucket123/neptune/
-- 8. バルクロード実行
curl -X POST \
-H 'Content-Type: application/json' \
https://cluster01.cluster-xxxxxxxxxxxx.ap-northeast-1.neptune.amazonaws.com:8182/loader -d '
{
"source" : "s3://bucket123/neptune/",
"format" : "csv",
"iamRoleArn" : "arn:aws:iam::999999999999:role/role01",
"region" : "ap-northeast-1",
"mode" : "AUTO",
"failOnError" : "TRUE",
"parallelism" : "LOW",
"updateSingleCardinalityProperties" : "FALSE",
"queueRequest" : "FALSE"
}'
-- ロードステータス確認
curl -G 'https://cluster01.cluster-xxxxxxxxxxxx.ap-northeast-1.neptune.amazonaws.com:8182/loader/11111111-2222-3333-4444-555555555555'
-- 9. ロード結果確認
cd /home/ec2-user/apache-tinkerpop-gremlin-console-3.4.10
bin/gremlin.sh
:remote connect tinkerpop.server conf/neptune-remote.yaml
:remote console
-- 頂点一覧
g.V()
g.V().valueMap()
-- エッジ一覧
g.E()
:exit
-- 10. クリーンアップ
-- インスタンスの削除
aws neptune delete-db-instance \
--db-instance-identifier instance01 \
--skip-final-snapshot
aws neptune describe-db-instances
-- クラスターの削除
aws neptune delete-db-cluster \
--db-cluster-identifier cluster01 \
--skip-final-snapshot
aws neptune describe-db-clusters
-- S3ゲートウェイエンドポイントの削除
aws ec2 describe-vpc-endpoints
aws ec2 delete-vpc-endpoints \
--vpc-endpoint-ids vpce-xxxxxxxxxxxxxxxxx
-- ロールの一覧
aws iam list-roles | grep role01
-- ロールの削除
aws iam detach-role-policy \
--role-name role01 \
--policy-arn arn:aws:iam::aws:policy/AmazonS3ReadOnlyAccess
aws iam delete-role --role-name role01
-- バケット削除
aws s3 rb s3://bucket123 --force