ArcGIS API for Python を利用して AWS S3 のオブジェクト ストアを登録する

ArcGIS API for Python は少ないコードで、ArcGIS Online や ArcGIS Enterprise の運用管理やデータ分析が可能となる使いやすい API です。ただし、利用する環境に関しては ArcGIS Pro を利用してインストールしたり、Python 環境でコマンドを発行してインストールしたりします。 ここでは、ArcGIS API for Python を利用して、ArcGIS Enterprise 11.4 から利用できるようになったオブジェクト ストアを登録してみます。(※サンプル コードは 11.4 以降で動作します。)

以下は本ブログの他に参照すべきヘルプページなどになります。

オブジェクト ストアとは?

ArcGIS Enterprise 11.4(Windows および Linux)以降では、オブジェクト ストアはベースとなる ArcGIS Enterprise 構築の必須コンポーネントです。ArcGIS Data Store を使用して構成するか、AWS または Azure クラウドでのクラウド展開の場合は、Amazon S3 または Azure Blob Storage を通じて構成できます。

オブジェクト ストアは、ホストされたシーン レイヤーのキャッシュ、ホストされた 3D タイル レイヤー、ホストされたフィーチャ レイヤーのクエリ応答キャッシュなど、関連データを保存することで、ホストされた Web レイヤーやその他のシステム機能をサポートする上で重要な役割を果たします。

サンプル コード

以下はサンプル コードになります。Portal for ArcGIS に接続し、Hosting された ArcGIS Server 情報を取得します。 ArcGIS Server の Datastore Manager より、AWS S3 でのオブジェクト ストア接続情報を登録できます。

from arcgis.gis import GIS

username = "[portal admin username]"
password = "[user password]"
portalURL = "https://[portal fqdn]/arcgis/home/"
bucketname = "[AWS S3 bucket name]"
region = "[AWS Region]" #ap-northeast-1など
accessKeyId = "[AWS ACCESS KEY ID]"
secretAccessKey = "[AWS SECRET ACCESS KEY]"

# GIS に接続 
gis = GIS(portalURL, username, password)
print(gis)
#Hosting Server 情報取得
server_mgr = gis.admin.servers
servers = server_mgr.list()
gis_server =  servers[0]
print(gis_server)

datastore_mgr = gis_server.datastores
print(datastore_mgr)

object_str_config: dict =  {
    "path": "/cloudStores/[任意のObjectStore名]",
    "type": "objectStore",
    "provider": "amazon",
        "info": {
            "isManaged": True,
            "systemManaged": False,
            "isManagedData": True,
            "purposes": ["feature-tile", "scene"],
            "connectionString": "{\"accessKeyId\":\""+accessKeyId+"\",\"secretAccessKey\":\""+secretAccessKey+"\",\"regionEndpointUrl\":\"https://s3."+region+".amazonaws.com\",\"defaultEndpointsProtocol\":\"https\",\"credentialType\":\"accesskey\",\"region\":\""+region+"\"}",
            "objectStore": bucketname+"/objectstore-data"
        }
}

object_data_store = datastore_mgr.add(item=object_str_config)

datastores = datastore_mgr.list()
for datastore in datastores:
    if datastore.properties["path"] == "/cloudStores/[任意のObjectStore名]":
        print(datastore.validate())
        #print(datastore.ref_count)
        print("datastore path:", datastore.properties["path"])
        obj_store_config = datastore.properties
        print(obj_store_config)
        # deleteメソッドを呼び出せば削除できる.
        #datastore.delete()

スクリプトの実行

ArcGIS Pro がインストールされているマシンであれば以下のように Windows PowerShell などで実行できます。(※サンプル コードを sample_objectstore.py という名前で保存する場合)

$env:PATH = $env:PATH+";C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3"
python .\sample_objectstore.py

まとめ

ArcGIS Enterprise 12.0 現在で、このオブジェクト ストアの登録は ArcGIS Server Administrator Directory から行うか、ArcGIS API for Python を利用する方法の2つの選択肢があります。

これらの方法により、ArcGIS Enterprise をクラウド環境で構築する際により Cloud Native な構築を実現させることが可能です。

参考

フォローする