Skip to content

Commit 82b30ce

Browse files
authored
allow creation of additional datasets (aws-solutions-library-samples#1301)
1 parent 32bf2c7 commit 82b30ce

File tree

1 file changed

+22
-9
lines changed

1 file changed

+22
-9
lines changed

cid/common.py

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -624,7 +624,16 @@ def _deploy(self, dashboard_id: str=None, recursive=True, update=False, **kwargs
624624
dataset = self.qs.describe_dataset(id=dashboard_datasets.get(dataset_name), no_cache=True)
625625

626626
if not isinstance(dataset, Dataset):
627-
# Second chance: try to find the dataset with the id that is the name
627+
# Second chance: try to find the dataset with the id from resources
628+
try:
629+
_ds_id = self.resources['datasets'].get(dataset_name, {}).get('data', {}).get('DataSetId')
630+
if _ds_id:
631+
dataset = self.qs.describe_dataset(id=_ds_id, no_cache=True)
632+
except Exception as exc:
633+
logger.debug(f'Failed to describe_dataset {dataset_name} {exc}')
634+
635+
if not isinstance(dataset, Dataset):
636+
# Third chance: try to find the dataset with the id that is the name
628637
try:
629638
dataset = self.qs.describe_dataset(id=dataset_name, no_cache=True)
630639
except Exception as exc:
@@ -662,14 +671,18 @@ def _deploy(self, dashboard_id: str=None, recursive=True, update=False, **kwargs
662671

663672
if not matching_datasets:
664673
reco = ''
665-
logger.warning(f'Dataset {dataset_name} is not found.')
666-
if utils.exec_env()['shell'] == 'lambda':
667-
# We are in lambda
668-
reco = 'You can try deleting existing dataset and re-run.'
669-
else:
670-
# We are in command line mode
671-
reco = 'Please retry with --update "yes" --force --recursive flags.'
672-
raise CidCritical(f'Failed to find a Dataset "{dataset_name}" with required fields. ' + reco)
674+
new_datasets = self.create_datasets([dataset_name], known_datasets=dashboard_datasets, recursive=recursive, update=update)
675+
if not new_datasets:
676+
logger.warning(f'Dataset {dataset_name} is not found.')
677+
if utils.exec_env()['shell'] == 'lambda':
678+
# We are in lambda
679+
reco = 'You can try deleting existing dataset and re-run.'
680+
else:
681+
# We are in command line mode
682+
reco = 'Please retry with --update "yes" --force --recursive flags.'
683+
raise CidCritical(f'Failed to find a Dataset "{dataset_name}" with required fields. ' + reco)
684+
_ds_id = self.resources['datasets'].get(dataset_name, {}).get('data', {}).get('DataSetId')
685+
dashboard_definition['datasets'][dataset_name] = f'arn:{self.base.partition}:quicksight:{self.base.region}:{self.base.account_id}:dataset/{_ds_id}'
673686
elif len(matching_datasets) >= 1:
674687
if len(matching_datasets) > 1:
675688
# FIXME: propose a choice?

0 commit comments

Comments
 (0)