Migration-scripts/cdk/lambda/quicksight_migration/quicksight_migration/batch_migration_lambda.py [361:494]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
        source_dashboard = qs_utils.describe_dashboard(sourcesession, dashboard['DashboardId'])
        source_entity_arn = source_dashboard['Dashboard']['Version']['SourceEntityArn']

        if source_entity_arn.split("/")[0].split(":")[-1] == "analysis":
            source_analysis = source_dashboard['Dashboard']['Version']['SourceEntityArn']
        else:
            dashboard_failed.append(
                {
                    "Error Type": "Source Analysis is missing!",
                    "DashboardId": source_analysis_id,
                    "Name": source_analysis_name,
                    "Error": "Source Analysis is missing!"
                }
            )
            continue

        source_version = source_dashboard['Dashboard']['Version']['VersionNumber']
        source_dash_id = source_dashboard['Dashboard']['DashboardId']
        source_dash_name = source_dashboard['Dashboard']['Name']
        dataset_arns = source_dashboard['Dashboard']['Version']['DataSetArns']
        target_theme_arn=''
        if 'ThemeArn' in source_dashboard['Dashboard']['Version'].keys():
            target_theme_arn = f'arn:aws:quicksight:{target_region}:{account_id}:theme/'+source_dashboard['Dashboard']['Version']['ThemeArn'].split("/")[1]

        sourcedsref = []

        for dataset_arn in dataset_arns:
            missing = False
            dataset_id = dataset_arn.split("/")[1]

            try:
                dname = qs_utils.get_dataset_name(dataset_id, sourcesession)
            except Exception as ex:
                dashboard_failed.append(
                    {
                        "Error Type": f"Dataset: {dataset_id} is missing!",
                        "DashboardId": source_dash_id,
                        "Name": source_dash_name,
                        "Error": str(ex)
                    }
                )
                missing=True
                break

            sourcedsref.append({'DataSetPlaceholder': dname,
                        'DataSetArn': dataset_arn})
        if missing:
            continue
        try:
            source_template = qs_utils.create_template(
                sourcesession, source_dash_id, source_dash_name, sourcedsref, source_analysis, '1')
            source_template = qs_utils.describe_template(sourcesession, source_dash_id)
        except Exception as ex:
            dashboard_failed.append(
                {
                    "Error Type": "Create Source Template Error",
                    "DashboardId": source_dash_id,
                    "Name": source_dash_name,
                    "Error": str(ex)
                }
            )
            continue

        while source_template['Template']['Version']['Status'] == "CREATION_IN_PROGRESS":
            time.sleep(5)
            source_template = qs_utils.describe_template(sourcesession, source_dash_id)
            if source_template['Template']['Version']['Status'] == "CREATION_SUCCESSFUL":
                try:
                    updateres = qs_utils.update_template_permission(
                        sourcesession, source_dash_id, targetadmin)
                except Exception as ex:
                    qs_utils.delete_template(sourcesession, source_dash_id)
                    dashboard_failed.append(
                        {
                            "Error Type": "Update Source Template Permission Error",
                            "DashboardId": source_dash_id,
                            "Name": source_dash_name,
                            "Error": str(ex)
                        }
                    )
        else:
            if source_template['Template']['Version']['Status'] == "CREATION_SUCCESSFUL":
                try:
                    updateres = qs_utils.update_template_permission(
                        sourcesession, source_dash_id, targetadmin
                    )
                except Exception as ex:
                    qs_utils.delete_template(sourcesession, source_dash_id)
                    dashboard_failed.append(
                        {
                            "Error Type": "Update Source Template Permission Error",
                            "DashboardId": source_dash_id,
                            "Name": source_dash_name,
                            "Error": str(ex)
                        }
                    )
                    continue

        if updateres['Status'] == 200:
            try:
                targettemplate = qs_utils.copy_template(
                    targetsession, source_dash_id, source_dash_name, updateres['TemplateArn'])
            except Exception as ex:
                qs_utils.delete_template(sourcesession, source_dash_id)
                dashboard_failed.append(
                    {
                        "Error Type": "Copy Template Error",
                        "DashboardId": source_dash_id,
                        "Name": source_dash_name,
                        "Error": str(ex)
                    }
                )
                continue
        else:
            qs_utils.delete_template(sourcesession, source_dash_id)
            dashboard_failed.append(
                {
                    "Error Type": "Update Source Template Permission Error",
                    "DashboardId": source_dash_id,
                    "Name": source_dash_name,
                    "Error": str(ex)
                }
            )
            continue

        targettemplate = qs_utils.describe_template(targetsession, source_dash_id)

        while targettemplate['Template']['Version']['Status'] == "CREATION_IN_PROGRESS":
            time.sleep(5)
            targettemplate = qs_utils.describe_template(targetsession, source_dash_id)
            if targettemplate['Template']['Version']['Status'] == "CREATION_SUCCESSFUL":
                break
        else:
            if targettemplate['Template']['Version']['Status'] == "CREATION_SUCCESSFUL":
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



Migration-scripts/cdk/lambda/quicksight_migration/quicksight_migration/incremental_migration_lambda.py [476:608]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
        source_dashboard = qs_utils.describe_dashboard(sourcesession, dashboard['DashboardId'])
        source_entity_arn = source_dashboard['Dashboard']['Version']['SourceEntityArn']

        if source_entity_arn.split("/")[0].split(":")[-1] == "analysis":
            source_analysis = source_dashboard['Dashboard']['Version']['SourceEntityArn']
        else:
            dashboard_failed.append(
                {
                    "Error Type": "Source Analysis is missing!",
                    "DashboardId": source_analysis_id,
                    "Name": source_analysis_name,
                    "Error": "Source Analysis is missing!"
                }
            )
            continue

        source_version = source_dashboard['Dashboard']['Version']['VersionNumber']
        source_dash_id = source_dashboard['Dashboard']['DashboardId']
        source_dash_name = source_dashboard['Dashboard']['Name']
        dataset_arns = source_dashboard['Dashboard']['Version']['DataSetArns']
        target_theme_arn=''
        if 'ThemeArn' in source_dashboard['Dashboard']['Version'].keys():
            target_theme_arn = f'arn:aws:quicksight:{target_region}:{account_id}:theme/'+source_dashboard['Dashboard']['Version']['ThemeArn'].split("/")[1]

        sourcedsref = []

        for dataset_arn in dataset_arns:
            missing = False
            dataset_id = dataset_arn.split("/")[1]
            try:
                dname = qs_utils.get_dataset_name(dataset_id, sourcesession)
            except Exception as ex:
                dashboard_failed.append(
                    {
                        "Error Type": f"Dataset: {dataset_id} is missing!",
                        "DashboardId": source_dash_id,
                        "Name": source_dash_name,
                        "Error": str(ex)
                    }
                )
                missing=True
                break

            sourcedsref.append({'DataSetPlaceholder': dname,
                        'DataSetArn': dataset_arn})
        if missing:
            continue
        try:
            source_template = qs_utils.create_template(
                sourcesession, source_dash_id, source_dash_name, sourcedsref, source_analysis, '1')
            source_template = qs_utils.describe_template(sourcesession, source_dash_id)
        except Exception as ex:
            dashboard_failed.append(
                {
                    "Error Type": "Create Source Template Error",
                    "DashboardId": source_dash_id,
                    "Name": source_dash_name,
                    "Error": str(ex)
                }
            )
            continue

        while source_template['Template']['Version']['Status'] == "CREATION_IN_PROGRESS":
            time.sleep(5)
            source_template = qs_utils.describe_template(sourcesession, source_dash_id)
            if source_template['Template']['Version']['Status'] == "CREATION_SUCCESSFUL":
                try:
                    updateres = qs_utils.update_template_permission(
                        sourcesession, source_dash_id, targetadmin)
                except Exception as ex:
                    qs_utils.delete_template(sourcesession, source_dash_id)
                    dashboard_failed.append(
                        {
                            "Error Type": "Update Source Template Permission Error",
                            "DashboardId": source_dash_id,
                            "Name": source_dash_name,
                            "Error": str(ex)
                        }
                    )
        else:
            if source_template['Template']['Version']['Status'] == "CREATION_SUCCESSFUL":
                try:
                    updateres = qs_utils.update_template_permission(
                        sourcesession, source_dash_id, targetadmin
                    )
                except Exception as ex:
                    qs_utils.delete_template(sourcesession, source_dash_id)
                    dashboard_failed.append(
                        {
                            "Error Type": "Update Source Template Permission Error",
                            "DashboardId": source_dash_id,
                            "Name": source_dash_name,
                            "Error": str(ex)
                        }
                    )
                    continue

        if updateres['Status'] == 200:
            try:
                targettemplate = qs_utils.copy_template(
                    targetsession, source_dash_id, source_dash_name, updateres['TemplateArn'])
            except Exception as ex:
                qs_utils.delete_template(sourcesession, source_dash_id)
                dashboard_failed.append(
                    {
                        "Error Type": "Copy Template Error",
                        "DashboardId": source_dash_id,
                        "Name": source_dash_name,
                        "Error": str(ex)
                    }
                )
                continue
        else:
            qs_utils.delete_template(sourcesession, source_dash_id)
            dashboard_failed.append(
                {
                    "Error Type": "Update Source Template Permission Error",
                    "DashboardId": source_dash_id,
                    "Name": source_dash_name,
                    "Error": str(ex)
                }
            )
            continue

        targettemplate = qs_utils.describe_template(targetsession, source_dash_id)

        while targettemplate['Template']['Version']['Status'] == "CREATION_IN_PROGRESS":
            time.sleep(5)
            targettemplate = qs_utils.describe_template(targetsession, source_dash_id)
            if targettemplate['Template']['Version']['Status'] == "CREATION_SUCCESSFUL":
                break
        else:
            if targettemplate['Template']['Version']['Status'] == "CREATION_SUCCESSFUL":
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



