Updating a dashboard

Hello,

I have to some dashboards created from analysis. I need to update all the dashboards and add parameters/filters to them (if they dont already exist). How can I achieve this efficiently ? I am trying to do this in java. Should I:

  1. Convert each analysis to template → modify template (add params/filters) → Save template→ publish the dashboard?

  2. Get the analysis → Modify to add params/filters → Save analysis → Create/Update template → publish the dashboard?

  3. Any other recommended approach ?

Please advise.

Thank you

Hi @harpar1808,

Since you are trying to add/update parameters and filters, I would definitely recommend modifying and saving the analysis, followed by publishing the dashboard. Although templates are an option to create dashboards, I do not believe they offer any parameter/filter instruction capabilities.

However, if all of your desired analyses are basically the same and you just want to make slight changes to each before publishing, you could save a copy of analysis by clicking “File > Save as Analysis” so that you do not have to do everything from scratch.

Hope this helps!

Hello @WLS-Luis ,

Here is my workflow –>

  1. Users will create the analysis and dashboards themselves in QS.

  2. Every night I will have a job, which will do the following:

– Go through each dashboard and get the corresponding analysis
– In the analysis, add a couple of calculated fields and parameters to the existing sets of filters/params (skip the next step if analysis already has everything)
– Save the analysis and publish the dashboard.

Do I need to create templates for this workflow? Which methods will I need to call via the Java sdk api ? any example code you have around this?

Thank you.

Hi @harpar1808,

Listed here is documentation containing all QuickSight API actions available (all of which include examples on how to properly structure them). Since your workflow does not involve creating new dashboards, you will not need to create templates. A code implementation utilizing the SDK methods should be sufficient for extracting necessary information from any existing user dashboard.

Hello @WLS-Luis ,

I have got the initial code there and it executes except at the last step when I try to update the dashboard, I get an error that “Invalid analysis arn given: ….” but the analysis arn is correct so I am not sure what the problem is. Here is my code:

private void DescribeDashboard() {
    try {

        String accountId = "<account_id>";
        String accessKey = "<access_key";
        String secretKey = "<secret_key>";
        String dashboardId = "<dashboard_id>";

        QuickSightClient client = QuickSightClient.builder()
                .region(Region.of(Regions.US_EAST_1.getName()))
                .credentialsProvider(StaticCredentialsProvider.create(AwsBasicCredentials.create(accessKey, secretKey)))
                .build();

        //Step 1: Describe the Dashboard to get the SourceEntityArn
        DescribeDashboardRequest request = DescribeDashboardRequest.builder()
                .awsAccountId(accountId)
                .dashboardId(dashboardId)
                .build();

        DescribeDashboardResponse response = client.describeDashboard(request);
        System.out.println("Dashboard description: " + response.dashboard());

        String dashboardSourceEntityArnString = response.dashboard().version().sourceEntityArn();
        System.out.println("Source Entity ARN: " + dashboardSourceEntityArnString);

        //Step 2: Describe the Analysis to get its Definition
        DescribeAnalysisRequest describeAnalysisRequest = DescribeAnalysisRequest.builder()
                .awsAccountId(accountId)
                .analysisId(Arn.parse(dashboardSourceEntityArnString).get().resource().get(1))
                .build();

        DescribeAnalysisResponse describeAnalysisResponse = client.describeAnalysis(describeAnalysisRequest);
        System.out.println("Analysis description: " + describeAnalysisResponse.analysis());

        Analysis analysis = describeAnalysisResponse.analysis();
        DescribeAnalysisDefinitionRequest describeAnalysisDefinitionRequest = DescribeAnalysisDefinitionRequest.builder()
                .analysisId(analysis.analysisId())
                .awsAccountId(accountId)
                .build();
        DescribeAnalysisDefinitionResponse analysisDefinitionResponse =
                client.describeAnalysisDefinition(describeAnalysisDefinitionRequest);
        AnalysisDefinition origAnalysisDefinition = analysisDefinitionResponse.definition();

        //Step 3: Update the Analysis Definition to add a Parameter
        ArrayList<ParameterDeclaration> allParams = new ArrayList<>(origAnalysisDefinition.parameterDeclarations());
        StringParameterDeclaration stringParam = StringParameterDeclaration.builder().name("RegionParam")
                .parameterValueType(ParameterValueType.SINGLE_VALUED)
                .defaultValues(StringDefaultValues.builder().staticValues("us-east-1").build())
                .build();
        allParams.add(ParameterDeclaration.builder().stringParameterDeclaration(stringParam).build());
        AnalysisDefinition updatedAnalysisDefinition = analysisDefinitionResponse.definition().toBuilder().parameterDeclarations(allParams).build();

        //Step 4: Update the Analysis with the new Definition
        UpdateAnalysisRequest updateAnalysisRequest = UpdateAnalysisRequest.builder()
                .awsAccountId(accountId)
                .analysisId(analysis.analysisId())
                .name(analysis.name())
                .definition(updatedAnalysisDefinition)
                .build();

        UpdateAnalysisResponse updateAnalysisResponse = client.updateAnalysis(updateAnalysisRequest);
        System.out.println("Updated Analysis: " + updateAnalysisResponse.arn());

        //Step 5: Get the Data Set References from the analysis
        ArrayList<DataSetReference> refs = new ArrayList<>();
        for (String arn : response.dashboard().version().dataSetArns()) {
            refs.add(DataSetReference.builder()
                    .dataSetPlaceholder("DataSet1")
                    .dataSetArn(arn)
                    .build());
        }

        //Step 6: Create dashboard source entity with the analysis ARN
        DashboardSourceEntity dashboardSourceEntity = DashboardSourceEntity.builder()
                .sourceTemplate(DashboardSourceTemplate.builder()
                        .arn(dashboardSourceEntityArnString)
                        .dataSetReferences(refs)
                        .build())
                .build();

        //Step 7: Update the Dashboard with the new Source Entity
        UpdateDashboardRequest updateDashboardRequest = UpdateDashboardRequest.builder()
                .awsAccountId(accountId)
                .dashboardId(dashboardId)
                .name(response.dashboard().name())
                .sourceEntity(dashboardSourceEntity)
                .build();

        //Step 8: Call UpdateDashboard
        UpdateDashboardResponse updateDashboardResponse = client.updateDashboard(updateDashboardRequest);
        System.out.println("Updated Dashboard: " + updateDashboardResponse);

    } catch (Exception e) {
        System.err.println("Failed to update dashboard: " + e.getMessage());
    }
}

Error:

image

Can you please advise?

Thank you.

@harpar1808, did you try to create a new dashboard using this workflow instead of updating exiting one to make sure that steps 1…6 are Ok?

No, per my normal workflow, I created the dashboard from quicksight and then performed all the steps as mentioned in my msg earlier

So, looks like I found the problem. Seems you cannot update a dashboard directly from analysis. Analysis → template → dashboard update seems to work.

Hi @harpar1808 ,

As you figured out above, the SourceEntity parameter accepts only template arns. If you want to avoid having to create templates and go directly from analysis to dashboard, you can leverage the Definition parameter in UpdateDashboard call.

Regards,

Arun Santhosh

Pr Quick Suite SA