forked from aws-samples/aws-data-mesh-utils
-
Notifications
You must be signed in to change notification settings - Fork 0
/
0_setup_central_account.py
64 lines (50 loc) · 2.89 KB
/
0_setup_central_account.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import warnings
import logging
import sys
import os
import inspect
import argparse
parent_dir = os.path.dirname(os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe()))))
sys.path.insert(0, parent_dir)
import data_mesh_util.lib.utils as utils
from data_mesh_util.lib.constants import *
from data_mesh_util import DataMeshAdmin as data_mesh_admin
from data_mesh_util import DataMeshMacros as data_mesh_macros
warnings.filterwarnings(action="ignore", message="unclosed", category=ResourceWarning)
class Step0():
'''
Script to configure an set of accounts as central data mesh, producer, and consumer. Mesh credentials must already
have DataLakeAdmin permissions.
'''
_logger = logging.getLogger("DataMeshAdmin")
_region, _clients, _account_ids, _creds = utils.load_client_info_from_file()
def setUp(self) -> None:
warnings.filterwarnings("ignore", category=ResourceWarning)
def setup_central_account(self, producer_crawler_role_arn: str = None, consumer_crawler_role_arn: str = None):
# create the data mesh
mesh_admin = data_mesh_admin.DataMeshAdmin(data_mesh_account_id=self._account_ids.get(MESH),
region_name=self._region,
log_level=logging.DEBUG, use_credentials=self._creds.get(MESH))
mesh_admin.initialize_mesh_account()
# create a macro handler which works across accounts
mesh_macros = data_mesh_macros.DataMeshMacros(data_mesh_account_id=self._account_ids.get(MESH),
region_name=self._region,
log_level=logging.DEBUG)
# create the producer account
mesh_macros.bootstrap_account(account_type=PRODUCER,
mesh_credentials=self._creds.get(MESH),
account_credentials=self._creds.get(PRODUCER_ADMIN),
crawler_role_arn=producer_crawler_role_arn)
# create the consumer_account
mesh_macros.bootstrap_account(account_type=CONSUMER,
mesh_credentials=self._creds.get(MESH),
account_credentials=self._creds.get(CONSUMER_ADMIN),
crawler_role_arn=consumer_crawler_role_arn)
if __name__ == '__main__':
utils.purify_sysargs()
parser = argparse.ArgumentParser()
parser.add_argument('--producer_crawler_role_arn', dest='producer_crawler_role_arn', required=False)
parser.add_argument('--consumer_crawler_role_arn', dest='consumer_crawler_role_arn', required=False)
args = parser.parse_args()
Step0().setup_central_account(producer_crawler_role_arn=args.producer_crawler_role_arn,
consumer_crawler_role_arn=args.consumer_crawler_role_arn)