Automate deployment of an Amazon QuickSight analysis connecting to an Amazon Redshift data warehouse with an AWS CloudFormation template

What matters here for platform teams is the shift from manual BI setup to repeatable infrastructure-as-code for analytics assets. Packaging the QuickSight data source, dataset, template, and analysis into CloudFormation gives architects a way to promote a reporting stack across environments with the same deployment discipline used for application infrastructure. That reduces configuration drift, but it also means the analytics definition becomes subject to the same change control, code review, and release management process as any other workload.

The architecture has a few dependencies that need to be treated explicitly. The source and target accounts must both support QuickSight enterprise access, the Redshift connection must exist in the destination environment, and the template must reference ARNs and permissions that are valid in each account. In practice, this introduces a clear separation between design-time assets in the source account and runtime data access in the target account, which is useful for multi-account governance but easy to break if identity, Region, or cluster details are not aligned.

There is also a meaningful trade-off in the dataset layer. The example uses direct query, which keeps data current and avoids SPICE refresh planning, but it shifts more dependency onto Redshift availability, query tuning, and warehouse capacity. Teams standardizing this pattern should think about whether template portability is enough, or whether they also need consistent performance behavior across environments when the underlying warehouse size or workload mix changes.

Operationally, the most valuable aspect is that the analysis becomes deployable and versionable rather than disposable. That makes rollback, reproducibility, and promotion between dev and prod more predictable, especially for teams that need to manage multiple dashboards or segregated tenant environments. It also creates a maintainable path for integrating BI deployment into CI/CD without relying on console recreation.


Amazon Redshiftย ย is the most widely used data warehouse in the cloud, best suited for analyzing exabytes of data and running complex analytical queries.
Amazonย ย QuickSightย is a fast business analytics service to build visualizations, perform ad hoc analysis, and quickly get business insights from your data. QuickSight provides easy integration with Amazon Redshift, providing native access to all your data and enabling organizations to scale their business analytics capabilities to hundreds of thousands of users. QuickSight delivers fast and responsive query performance by using a robust in-memory engine (SPICE).
As a QuickSight administrator, you can useย AWSย ย CloudFormationย templates to migrate assets between distinct environments from development, to test, to production. AWS CloudFormation helps you model and set up your AWS resources so you can spend less time managing those resources and more time focusing on your applications that run in AWS. You no longer need to create data sources or analyses manually. You create a template that describes all the AWS resources that you want, and AWS CloudFormation takes care of provisioning and configuring those resources for you. In addition, with versioning, you have your previous assets, which provides the flexibility to roll back deployments if the need arises. For more details, refer toย Amazon QuickSight resource type reference. In this post, we show how to automate the deployment of a QuickSight analysis connecting to an Amazon Redshift data warehouse with a CloudFormation template.

Solution overview

Our solution consists of the following steps:
  1. Create a QuickSight analysis using an Amazon Redshift data source.
  2. Create a QuickSight template for your analysis.
  3. Create a CloudFormation template for your analysis using theย AWS Command Line Interfaceย (AWS CLI).
  4. Use the generated CloudFormation template to deploy a QuickSight analysis to a target environment.
The following diagram shows the architecture of how you can have multiple AWS accounts, each with its own QuickSight environment connected to its own Amazon Redshift data source.ย In this post, we outline the steps involved in migrating QuickSight assets in the dev account to the prod account. For this post, we use Amazon Redshift as the data source and create a QuickSight visualization using the Amazon Redshift sample TICKIT database.
The following diagram illustrates flow of the high-level steps.

Prerequisites

Before setting up the CloudFormation stacks, you must have an AWS account and anย AWS Identity and Access Managementย (IAM) user with sufficient permissions to interact with theย AWS Management Consoleย and the services listed in the architecture. The migration requires the following prerequisites:

Create a QuickSight analysis in your dev environment

In this section, we walk through the steps to set up your QuickSight analysis using an Amazon Redshift data source.

Create an Amazon Redshift data source

To connect to your Amazon Redshift data warehouse, you need to create a data source in QuickSight. As shown in the following screenshot, you have two options:
  • Auto-discovered
  • Manual connect
QuickSight auto-discoversย Amazon Redshift clusters that are associated with your AWS account. These resources must be located in the same Region as your QuickSight account. For more details, refer toย Authorizing connections from Amazon QuickSight to Amazon Redshift clusters. You can also manually connect and create a data source.

Create an Amazon Redshift dataset

The next step is to create a QuickSight dataset, which identifies the specific data in a data source you want to use. For this post, we use the TICKIT database created in an Amazon Redshift data warehouse, which consists of seven tables: two fact tables and five dimensions, as shown in the following figure.
This sample database application helps analysts track sales activity for the fictional TICKIT website, where users buy and sell tickets online for sporting events, shows, and concerts.
  1. On theย Datasetsย page, chooseย New dataset.
  2. Choose the data source you created in the previous step.
  3. Chooseย Use custom SQL.
  4. Enter the custom SQL as shown in the following screenshot.
The following screenshot shows our completed data source.

Create a QuickSight analysis

The next step is to create an analysis that utilizes this dataset. In QuickSight, you analyze and visualize your data in analyses. When youโ€™re finished, you can publish your analysis as a dashboard to share with others in your organization.
  1. On theย All analysesย tab of the QuickSight start page, chooseย New analysis.
Theย Datasetsย page opens.
  1. Choose a dataset, then chooseย Use in analysis.
  1. Create a visual. For more information about creating visuals, seeย Adding visuals to Amazon QuickSight analyses.

Create a QuickSight template from your analysis

A QuickSight template is a named object in your AWS account that contains the definition of your analysis and references to the datasets used. You can create a template using the QuickSight API by providing the details of the source analysis via a parameter file. You can use templates to easily create a new analysis. You can use AWS Cloud9 from the console to run AWS CLI commands.
The following AWS CLI command demonstrates how to create a QuickSight template based on the sales analysis you created (provide your AWS account ID for your dev account):
aws quicksight create-template --aws-account-id  <DEVACCOUNT>--template-id QS-RS-SalesAnalysis-Template --cli-input-json file://parameters.json
Theย parameter.jsonย file contains the following details (provide your source QuickSight user ARN, analysis ARN, and dataset ARN):
{
    "Name": "QS-RS-SalesAnalysis-Temp",
    "Permissions": [
        {"Principal": "<QS-USER-ARN>", 
          "Actions": [ "quicksight:CreateTemplate",
                       "quicksight:DescribeTemplate",                   
                       "quicksight:DescribeTemplatePermissions",
                       "quicksight:UpdateTemplate"         
            ] } ] ,
     "SourceEntity": {
       "SourceAnalysis": {
         "Arn": "<QS-ANALYSIS-ARN>",
         "DataSetReferences": [
           {
             "DataSetPlaceholder": "sales",
             "DataSetArn": "<QS-DATASET-ARN>"
           }
         ]
       }
     },
     "VersionDescription": "1"
    }
You can use the AWS CLIย describe-user,ย describe_analysis, andย describe_datasetย commands to get the required ARNs. To upload the updatedย parameter.jsonย file to AWS Cloud9, chooseย Fileย from the tool bar and chooseย Upload local file.
The QuickSight template is created in the background. QuickSight templates arenโ€™t visible within the QuickSight UI; theyโ€™re a developer-managed or admin-managed asset that is only accessible via the AWS CLI or APIs. To check the status of the template, run theย describe-templateย command:
aws quicksight describe-template --aws-account-id <DEVACCOUNT> --template-id "QS-RS-SalesAnalysis-Temp"
The following code shows command output:
Copy the template ARN; we need it later to create a template in the production account. The QuickSight template permissions in the dev account need to be updated to give access to the prod account. Run the following command to update the QuickSight template. This provides the describe privilege to the target account to extract details of the template from the source account:
aws quicksight update-template-permissions --aws-account-id <DEVACCOUNT> --template-id โ€œQS-RS-SalesAnalysis-Tempโ€ --grant-permissions file://TemplatePermission.json
The fileย TemplatePermission.jsonย contains the following details (provide your target AWS account ID):
[
  {
    "Principal": "arn:aws:iam::<TARGET ACCOUNT>",
    "Actions": [
      "quicksight:UpdateTemplatePermissions",
      "quicksight:DescribeTemplate"
    ]
  }
]
To upload the updatedย TemplatePermission.jsonย file to AWS Cloud9, choose theย Fileย menu from the tool bar and chooseย Upload local file.

Create a CloudFormation template

In this section, we create a CloudFormation template containing our QuickSight assets. In this example, we use a YAML formatted template saved on our local machine. We update the following different sections of the template:
  • AWS::QuickSight::DataSource
  • AWS::QuickSight::DataSet
  • AWS::QuickSight::Template
  • AWS::QuickSight::Analysis
Some of the information required to complete the CloudFormation template can be gathered from the source QuickSight account via theย describeย AWS CLI commands, and some information needs to be updated for the target account.

Create an Amazon Redshift data source in AWS CloudFormation

In this step, we add theย AWS::QuickSight::DataSourceย section of the CloudFormation template. Gather the following information on the Amazon Redshift cluster in the target AWS account (production environment):
  • VPC connection ARN
  • Host
  • Port
  • Database
  • User
  • Password
  • Cluster ID
You have the option to create a customย DataSourceID. This ID is unique per Region for each AWS account. Add the following information to the template:
Resources:
  RedshiftBuildQSDataSource:
    Type: 'AWS::QuickSight::DataSource'
    Properties:  
      DataSourceId: "RS-Sales-DW"      
      AwsAccountId: !Sub ${AWS::ACCOUNT ID}
      VpcConnectionProperties:
        VpcConnectionArn: <VPC-CONNECTION-ARN>      
      Type: REDSHIFT   
      DataSourceParameters:
        RedshiftParameters:     
          Host: "<HOST>"
          Port: <PORT>
          Clusterid: "<CLUSTER ID>"
          Database: "<DATABASE>"    
      Name: "RS-Sales-DW"
      Credentials:
        CredentialPair:
          Username: <USER>
          Password: <PASSWORD>
      Permissions:

Create an Amazon Redshift dataset in AWS CloudFormation

In this step, we add theย AWS::QuickSight::DataSetย section in the CloudFormation template to match the dataset definition from the source account. Gather the dataset details and run theย list-data-setsย command to get all datasets from the source account (provide your source dev account ID):
aws quicksight list-data-sets  --aws-account-id <DEVACCOUNT>
The following code is the output:
Run theย describe-data-setย command, specifying the dataset ID from the previous commandโ€™s response:
aws quicksight describe-data-set --aws-account-id <DEVACCOUNT> --data-set-id "<YOUR-DATASET-ID>"
The following code shows partial output:
Based on the dataset description, add theย AWS::Quicksight::DataSetย resource in the CloudFormation template, as shown in the following code. Note that you can also create a customย DataSetID. This ID is unique per Region for each AWS account.
QSRSBuildQSDataSet:
    Type: 'AWS::QuickSight::DataSet'
    Properties:
      DataSetId: "RS-Sales-DW" 
      Name: "sales" 
      AwsAccountId: !Sub ${AWS::ACCOUNT ID}
      PhysicalTableMap:
        PhysicalTable1:          
          CustomSql:
            SqlQuery: "select sellerid, username, (firstname ||' '|| lastname) as name,city, sum(qtysold) as sales
              from sales, date, users
              where sales.sellerid = users.userid and sales.dateid = date.dateid and year = 2008
              group by sellerid, username, name, city
              order by 5 desc
              limit 10"
            DataSourceArn: !GetAtt RedshiftBuildQSDataSource.Arn
            Name"RS-Sales-DW"
            Columns:
            - Type: INTEGER
              Name: sellerid
            - Type: STRING
              Name: username
            - Type: STRING
              Name: name
            - Type: STRING
              Name: city
            - Type: DECIMAL
              Name: sales                                     
      LogicalTableMap:
        LogicalTable1:
          Alias: sales
          Source:
            PhysicalTableId: PhysicalTable1
          DataTransforms:
          - CastColumnTypeOperation:
              ColumnName: sales
              NewColumnType: DECIMAL
      Permissions:
        - Principal: !Join 
            - ''
            - - 'arn:aws:quicksight:'
              - !Ref QuickSightIdentityRegion
              - ':'
              - !Ref 'AWS::AccountId'
              - ':user/default/'
              - !Ref QuickSightUser
          Actions:
            - 'quicksight:UpdateDataSetPermissions'
            - 'quicksight:DescribeDataSet'
            - 'quicksight:DescribeDataSetPermissions'
            - 'quicksight:PassDataSet'
            - 'quicksight:DescribeIngestion'
            - 'quicksight:ListIngestions'
            - 'quicksight:UpdateDataSet'
            - 'quicksight:DeleteDataSet'
            - 'quicksight:CreateIngestion'
            - 'quicksight:CancelIngestion'
      ImportMode: DIRECT_QUERY
You can specifyย ImportModeย to choose betweenย Direct_Queryย orย Spice.

Create a QuickSight template in AWS CloudFormation

In this step, we add theย AWS::QuickSight::Templateย section in the CloudFormation template, representing the analysis template. Use the source template ARN you created earlier and add theย AWS::Quicksight::Templateย resource in the CloudFormation template:
QSTCFBuildQSTemplate:
    Type: 'AWS::QuickSight::Template'
    Properties:
      TemplateId: "QS-RS-SalesAnalysis-Temp"
      Name: "QS-RS-SalesAnalysis-Temp"
      AwsAccountId:!Sub ${AWS::ACCOUNT ID}
      SourceEntity:
        SourceTemplate:
          Arn: '<SOURCE-TEMPLATE-ARN>'          
      Permissions:
        - Principal: !Join 
            - ''
            - - 'arn:aws:quicksight:'
              - !Ref QuickSightIdentityRegion
              - ':'
              - !Ref 'AWS::AccountId'
              - ':user/default/'
              - !Ref QuickSightUser
          Actions:
            - 'quicksight:DescribeTemplate'
      VersionDescription: Initial version - Copied over from AWS account.

Create a QuickSight analysis

In this last step, we add theย AWS::QuickSight::Analysisย section in the CloudFormation template. The analysis is linked to the template created in the target account. Add theย AWS::Quicksight::Analysisย resource in the CloudFormation template as shown in the following code:
QSRSBuildQSAnalysis:
    Type: 'AWS::QuickSight::Analysis'
    Properties:
      AnalysisId: 'Sales-Analysis'
      Name: 'Sales-Analysis'
      AwsAccountId:!Sub ${AWS::ACCOUNT ID}
      SourceEntity:
        SourceTemplate:
          Arn: !GetAtt  QSTCFBuildQSTemplate.Arn
          DataSetReferences:
            - DataSetPlaceholder: 'sales'
              DataSetArn: !GetAtt QSRSBuildQSDataSet.Arn
      Permissions:
        - Principal: !Join 
            - ''
            - - 'arn:aws:quicksight:'
              - !Ref QuickSightIdentityRegion
              - ':'
              - !Ref 'AWS::AccountId'
              - ':user/default/'
              - !Ref QuickSightUser
          Actions:
            - 'quicksight:RestoreAnalysis'
            - 'quicksight:UpdateAnalysisPermissions'
            - 'quicksight:DeleteAnalysis'
            - 'quicksight:DescribeAnalysisPermissions'
            - 'quicksight:QueryAnalysis'
            - 'quicksight:DescribeAnalysis'
            - 'quicksight:UpdateAnalysis'      

Deploy the CloudFormation template in the production account

To create a new CloudFormation stack that uses the preceding template via the AWS CloudFormation console, complete the following steps:
  1. On the AWS CloudFormation console, chooseย Create Stack.
  2. On the drop-down menu, chooseย with new resources (standard).
  3. Forย Prepare template, selectย Template is ready.
  4. Forย Specify template, chooseย Upload a template file.
  5. Save the provided CloudFormation template in a .yaml file and upload it.
  6. Chooseย Next.
  7. Enter a name for the stack. For this post, we useย QS-RS-CF-Stack.
  8. Chooseย Next.
  9. Chooseย Nextย again.
  10. Chooseย Create Stack.
The status of the stack changes toย CREATE_IN_PROGRESS, then toย CREATE_COMPLETE.
Verify the QuickSight objects in the following table have been created in the production environment.
QuickSight Object Type Object Name (Dev) Object Name ( Prod)
Data Source RS-Sales-DW RS-Sales-DW
Dataset Sales Sales
Template QS-RS-Sales-Temp QS-RS-SalesAnalysis-Temp
Analysis Sales Analysis Sales-Analysis
The following example shows thatย Sales Analysisย was created in the target account.

Conclusion

This post demonstrated an approach to migrate a QuickSight analysis with an Amazon Redshift data source from one QuickSight account to another with a CloudFormation template. For more information about automating dashboard deployment, customizing access to the QuickSight console, configuring for team collaboration, and implementing multi-tenancy and client user segregation, check out the videosย Virtual Admin Workshop: Working with Amazon QuickSight APIsย andย Admin Level-Up Virtual Workshop, V2ย on YouTube.

About the author

Sandeep Bajwa is a Sr. Analytics Specialist based out of Northern Virginia, specialized in the design and implementation of analytics and data lake solutions.
Original Post

Enjoyed this article? Sign up for our newsletter to receive regular insights and stay connected.