CloudFormation- QuickSight Parameters

Hi,

I’m in the process of redefining all my QuickSight resources in CloudFormation for the sake of ease of migration and redeployability.

I’ve come to a halt due to the difficulty defining the custom parameters that I have in one of my QuickSight analyses within CloudFormation. The documentation for defining a QuickSight datetime parameter within CloudFormation is sparse and only mentions that it should be a string (without stating how this should be formatted):

AWS::QuickSight::Analysis DateTimeParameter - AWS CloudFormation (amazon.com)

On further digging I found this QuickSight article on defining parameters within a URL which gives a good indication of how a datetime parameter should be formatted:

Using parameters in a URL - Amazon QuickSight

Unfortunately, this still doesn’t help with my use-case since the datetime parameter I would like to define is a “rolling” or “relative” datetime corresponding to the start of this week and not a fixed date which I can input.

Any help would be much appreciated. Thanks,
Lewis

Can you edit this parameter in the analysis to be rolling or relative?

If so, you should be able to implement this at the analysis level and create a template that takes the parameter & it’s configurations with it. You shouldn’t need to have to define it in the CloudFormation template.

Here is an example of setting the parameter to be relative at the analysis level.

After you have set that, then you create your template.

https://docs.aws.amazon.com/cli/latest/reference/quicksight/create-template.html

Hi Max,

I have no issues setting up the parameters within an analysis that I create on the fly, the issue is when I try to define parameters as part of my CloudFormation stack.

The reason I want to define all my QuickSight resources within CloudFormation is because I use CloudFormation stacks to define all my other resources. Therefore, if I want to redeploy my environment or deploy it to a new environment all I would need are the CloudFormation stacks. The method with templates which you suggest seems like it could be a solution for redeploying or deploying in a new environment, but it adds another layer of tasks to perform post-deployment. There is CloudFormation documentation for QuickSight and so far I have been able to define all the resources I require excluding the QuickSight Analysis parameters I require.

Thanks,
Lewis

Hmm,

Yeah in that case it doesn’t seem like you can set up a “Rolling” date with a parameter in Cloudformation. It seems as though it will have to be a constant.

However, in order to create an analysis in a new environment from an existing one you need to use templates.

Steps.

  1. aws quicksight create-template (create template from analysis)
  2. aws quicksight update-template-permissions (share template to new account)

Then in your CloudFormation you will need to reference the newly created template.

There are features coming out using “Assets as Code” to allow you to create an analysis without templates and use JSON / YAML. But that is not out yet.

This is the only way to do it now

1 Like

Hi Max,

That makes sense. Thanks for all the prompt help.

Lewis

2 Likes

Hello,

I encountered this issue a month ago and I think I found a solution thanks to a recent QuickSight update. (See here for details: Automate and accelerate your Amazon QuickSight asset deployments using the new APIs | AWS Big Data Blog)

Context:
I am using CloudFormation Templates to create an Analysis that contains a Date Range Filter with Rolling Date values. I did not explicitly use DateTime parameters for the rolling dates, but this solution may be applicable for both Filter Controls and Parameter Controls.

Solution:
At the time of this response, Date Ranger Filters and Date Time Parameters using ‘Rolling Dates’ require an ‘expression’ to set a value. However, AWS Documentation still does not specify what value ‘expression’ requires. Turns out, it is basically a ‘Calculate Field’ Expression. This does not mean you create a Calculated Field, rather you will create an expression with two Functions that are used when creating a Calculated Fields.

Use this as the expression value: ‘addDateTime(amount, period, truncDate(period, date))’

If you are like me and are new / unfamiliar with Calculated Field Functions, I provided two links below that should help explain what each argument requires:
- addDateTime - Amazon QuickSight
- truncDate - Amazon QuickSight

Example - scenario:
In an analysis sheet, I want to create a Date Range Filter with Rolling Dates that reflects daily data from the previous week.

Example - Filter Control:

ExampleAnalysis:
. . .
	FilterGroups:
		- CrossDataset: SINGLE_DATASET
		   FilterGroupId: <your ID>
		   Filters:
			- TimeRangeFilter:
				Column:
					ColumnName: <your date column name>
					DataSetIdentifier: <your DataSet ID>
				FilterId: <your filter id> 
				IncludeMaximum: true
				IncludeMinimum: true
				RangeMaximumValue:
					RollingDate: 
						Expression: "addDateTime(-1, 'SS', truncDate('WK', now()))" # Expression Value = End Of Previous Week
				RangeMinimumValue:
					RollingDate: 
						Expression: "addDateTime(-1, 'WK', truncDate('WK', now()))" # Expression Value = Start Of Previous Week
				NullOption: NON_NULLS_ONLY
				TimeGranularity: DAY
			ScopeConfiguration:
				SelectedSheets:
					SheetVisualScopingConfigurations:
						- Scope: ALL_VISUALS
					  	   SheetId: <your sheet id>

 . . . 

	FilterControls: # Creates filters for Filter groups without parameter usage
		- RelativeDateTime:
			FilterControlId: !Join ["-", [Range, !Ref FilterControlId3, !Ref SheetId5, !Ref AnalysisID]]
			SourceFilterId: !Join ["-", [Range, !Ref FilterId3, !Ref SheetId5, !Ref AnalysisID]]
			Title: "Choose Date Range"

Example (Parameter Control):

ExampleAnalysis:
. . . 
	FilterGroups:
		- CrossDataset: SINGLE_DATASET
	  	  FilterGroupId: <your ID>
		  Filters:
			- TimeRangeFilter:
				Column:
					ColumnName: <your date column name>
					DataSetIdentifier: <your DataSet ID>
				FilterId: <your filter id> 
				IncludeMaximum: true
				IncludeMinimum: true
				RangeMaximumValue:
					Parameter: EndDate
				RangeMinimumValue:
					Parameter: StarDate
				NullOption: NON_NULLS_ONLY
				TimeGranularity: DAY
			ScopeConfiguration:
				SelectedSheets:
					SheetVisualScopingConfigurations:
						- Scope: ALL_VISUALS
					  	   SheetId: <your sheet id>

. . . 

	ParameterDeclarations
		- DateTimeParameterDeclaration:
			DefaultValues:
				RollingDate:
					Expression: "addDateTime(-1, 'WK', truncDate('WK', now()))" # Expression Value = Start Of Previous Week
			Name: StartDate
			TimeGranularity: DAY
		- DateTimeParameterDeclaration:
			DefaultValues:
				RollingDate:
					Expression: "addDateTime(-1, 'SS', truncDate('WK', now()))" # Expression Value = End Of Previous Week
			Name: EndDate
			TimeGranularity: DAY
	
...

	ParameterControls: # Creates a filters for Filter groups with parameter usage
		- DateTimePicker:
			ParameterControlId: <your Param Control ID>
			SourceParameterName: StardDate
			Title: "Choose Start Date"
		- DateTimePicker:
			ParameterControlId: <your Param Control ID>
			SourceParameterName: EndDate
			Title: "Choose End Date"

I hope this helps. I cannot guarantee the “Control Parameter” section is 100% correct (ex. typos), but I just hope this can be a jumping point to get people further along.