Skip to content

Commit 54b5652

Browse files
committed
refactor: Fixed some links for Cloudformation resources docs, quicksightAccountArn needs to be passed as context
1 parent fbbb7b3 commit 54b5652

File tree

6 files changed

+46
-22
lines changed

6 files changed

+46
-22
lines changed

typescript/quicksight/README.md

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
<!--BEGIN STABILITY BANNER-->
2+
---
3+
4+
![Stability: Cfn-Only](https://img.shields.io/badge/stability-Cfn--Only-important.svg?style=for-the-badge)
5+
6+
> **This is an experimental example. It may not build out of the box**
7+
>
8+
> This example is built on Cfn resources.
9+
>
10+
> It requires additional infrastructure prerequisites that must be created before successful build, see below.
11+
>
12+
> If build is unsuccessful, please create an [issue](https://github.com/aws-samples/aws-cdk-examples/issues/new) so that we may debug the problem
13+
---
14+
<!--END STABILITY BANNER-->
15+
116
# Welcome to your CDK TypeScript project
217

318
This is a blank project for CDK development with TypeScript.
@@ -13,5 +28,5 @@ The `cdk.json` file tells the CDK Toolkit how to execute your app.
1328
* `npx cdk diff` compare deployed stack with current state
1429
* `npx cdk synth` emits the synthesized CloudFormation template
1530

16-
Data taken from https://data.worldbank.org/indicator/SP.POP.TOTL
31+
world-population.csv file in data directory taken from https://data.worldbank.org/indicator/SP.POP.TOTL
1732
License: CC BY-4.0

typescript/quicksight/bin/quicksight-example.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ import * as cdk from 'aws-cdk-lib';
44
import { QuicksightExampleStack } from '../lib/quicksight-example-stack';
55

66
const app = new cdk.App();
7-
new QuicksightExampleStack(app, 'QuicksightExampleStack');
87

9-
// 1. define stack props in QuicksightExampleStack
10-
// 2. pass stack props to QuicksightExampleStack
11-
// 3. make them available in the stack
12-
// 4. name it something along quicksight account arn
13-
// 5. use it getContext here and find out how to pass context with the cli. error out if context is missing
14-
// 6. document how to set up the stack
8+
// Quicksight account arn should look like this 'arn:aws:quicksight:<region>:<accountid>:user/<namespace>/<username>'
9+
const quicksightExampleProps = {quicksightAccountArn: app.node.tryGetContext('quicksightAccountArn')};
10+
if (quicksightExampleProps.quicksightAccountArn == null) {
11+
console.log('quicksightAccountArn is empty! Please provide it via the cdk context');
12+
process.exit(1);
13+
}
14+
new QuicksightExampleStack(app, 'QuicksightExampleStack', quicksightExampleProps);

typescript/quicksight/lib/data-transforms.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { CfnDataSet } from "aws-cdk-lib/aws-quicksight";
22
/**
3-
* @see https://docs.aws.amazon.com/quicksight/latest/APIReference/API_TransformOperation.html
3+
* @see https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-quicksight-dataset-transformoperation.html
44
*/
55
export const dataTransforms: CfnDataSet.TransformOperationProperty[] = [
66
{

typescript/quicksight/lib/input-columns.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1-
2-
export const inputColumns = [
1+
import { CfnDataSet } from "aws-cdk-lib/aws-quicksight";
2+
/**
3+
* @see https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-quicksight-dataset-inputcolumn.html
4+
*/
5+
export const inputColumns: CfnDataSet.InputColumnProperty[] = [
36
{ "name": "Country Name", "type": "STRING"},
47
{ "name": "Country Code", "type": "STRING"},
58
{ "name": "1960", "type": "STRING"},

typescript/quicksight/lib/quicksight-example-stack.ts

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,14 @@ import {BlockPublicAccess, Bucket, BucketAccessControl, BucketEncryption} from '
33
import {BucketDeployment, Source} from 'aws-cdk-lib/aws-s3-deployment';
44
import {CfnDataSet, CfnDataSource, CfnTemplate} from 'aws-cdk-lib/aws-quicksight';
55
import {CfnManagedPolicy} from 'aws-cdk-lib/aws-iam';
6-
import { Stack, StackProps } from 'aws-cdk-lib';
6+
import {Stack} from 'aws-cdk-lib';
77
import {dataTransforms} from './data-transforms';
88
import {inputColumns} from './input-columns';
99

10+
interface QuicksightExampleProps {
11+
quicksightAccountArn: string;
12+
}
13+
1014
export class QuicksightExampleStack extends Stack {
1115
/**
1216
* location of the manifest json file in the s3 bucket.
@@ -25,13 +29,11 @@ export class QuicksightExampleStack extends Stack {
2529

2630
public static QUICKSIGHT_DATASET_NAME = 'quicksightExampleDataset';
2731

28-
29-
constructor(scope: Construct, id: string, props?: StackProps) {
30-
super(scope, id, props);
32+
constructor(scope: Construct, id: string, props: QuicksightExampleProps) {
33+
super(scope, id);
3134

3235
const { bucket, deployment } = this.createBucket();
33-
const accountQuicksight = 'arn:aws:quicksight:<region>:<accountid>:user/<namespace>/<username>';
34-
this.createQuicksightResources(bucket, deployment, accountQuicksight);
36+
this.createQuicksightResources(bucket, deployment, props.quicksightAccountArn);
3537
}
3638

3739
// creates s3 bucket and deploys test data
@@ -62,7 +64,7 @@ export class QuicksightExampleStack extends Stack {
6264
QuicksightExampleStack.MANIFEST_KEY,
6365
manifest
6466
);
65-
// deploy them
67+
// deploy them and the files stored in the data directory
6668
const deployment = new BucketDeployment(this, 'BucketDeployment', {
6769
sources: [sourceInternal, Source.asset('./data')],
6870
destinationBucket: bucket,
@@ -154,10 +156,13 @@ export class QuicksightExampleStack extends Stack {
154156
}
155157
)
156158

157-
// quicksight needs these to be created so we waiting for the
159+
// quicksight needs these to be created so we're waiting for the creation of these resources
158160
quicksightS3DataSource.node.addDependency(managedPolicy);
159161
quicksightS3DataSource.node.addDependency(deployment);
160162

163+
/**
164+
* @see https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-quicksight-dataset-physicaltable.html
165+
*/
161166
const physicalTableProperties: CfnDataSet.PhysicalTableProperty = {
162167
s3Source: {
163168
dataSourceArn: quicksightS3DataSource.attrArn,
@@ -170,8 +175,9 @@ export class QuicksightExampleStack extends Stack {
170175
}
171176
}
172177
}
178+
173179
/**
174-
* @see https://docs.aws.amazon.com/quicksight/latest/APIReference/API_LogicalTable.html
180+
* @see https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-quicksight-dataset-logicaltable.html
175181
*/
176182
const logicalTableProperties: CfnDataSet.LogicalTableProperty = {
177183
alias: 's3-extract-data-cast',

typescript/quicksight/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313
"devDependencies": {
1414
"@types/jest": "^29.5.12",
1515
"@types/node": "20.14.9",
16+
"aws-cdk": "2.156.0",
1617
"jest": "^29.7.0",
1718
"ts-jest": "^29.1.5",
18-
"aws-cdk": "2.156.0",
1919
"ts-node": "^10.9.2",
2020
"typescript": "~5.5.3"
2121
},
@@ -24,4 +24,4 @@
2424
"constructs": "^10.0.0",
2525
"source-map-support": "^0.5.21"
2626
}
27-
}
27+
}

0 commit comments

Comments
 (0)