Skip to content
This repository was archived by the owner on Jul 16, 2024. It is now read-only.

Commit a00d02c

Browse files
authored
fix: cicd pipeline and quicksight custom resources (#597)
* fix cicd pipeline and quicksight custom resources
1 parent 86d87e8 commit a00d02c

File tree

7 files changed

+47
-35
lines changed

7 files changed

+47
-35
lines changed

refarch/README.md

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ To disable, for example, the data visualization module, the following argument h
7878
**NOTE:
7979
Step 4 and 5 only have to be executed if the data visualization module has been installed.**
8080

81-
1. Configure Amazon QuickSight:
81+
1. <a name="quicksight">Configure Amazon QuickSight:</a>
8282
* To link the clean data S3 bucket to the QuickSight account:
8383
* Visit the [QuickSight web console](https://quicksight.aws.amazon.com)
8484
* Click on your username in the upper right corner
@@ -164,10 +164,20 @@ The pipeline and the reference architecture can live in different accounts or in
164164
* **<DEV_ACCOUNT>** and **<PROD_ACCOUNT>**: with the account that will be deployed.
165165
* Note that you can have only a single account to be both CI/CD and DEV. If you don't want PROD account, you can comment out the line `deploy_envs.append(prod_env)` in the file `refarch/aws-native/app.py`
166166

167-
1. Run `cdk deploy --profile <CICD_ACCOUNT_PROFILE_NAME> araPipelineStack` using the credentials for your CICD account.
167+
1. Push the code into the repository used by the CICD pipeline.
168+
169+
```
170+
git push RepositoryName RepositoryBranch
171+
```
172+
173+
2. Run `cdk deploy --profile <CICD_ACCOUNT_PROFILE_NAME> araPipelineStack` using the credentials for your CICD account.
168174
* This will deploy the stack containing the pipeline to your CICD account
169175
* After the pipeline has been successfully deploy, it will fetch code from the specified repo and deploy to the target account.
170176

177+
2. Configure Quicksight as mentioned in [step 4](#quicksight) when provisioning the application directly
178+
179+
180+
171181
#### Adding users to Kibana
172182

173183
The main CDK stack also deploys the streaming module (if not explicitly disabled), which includes:

refarch/aws-native/app.py

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,9 @@ def make_env(scope: Construct, context_key: str):
4343
},
4444
)
4545

46+
deploy_envs = []
47+
4648
if app.node.try_get_context('EnableCICD') == 'true':
47-
deploy_envs = []
4849

4950
cicd_account_context = app.node.try_get_context('CICD')
5051
if cicd_account_context is None:
@@ -54,16 +55,16 @@ def make_env(scope: Construct, context_key: str):
5455
deploy_envs.append(dev_env)
5556

5657
# Comment out to deploy only to dev environment
57-
prod_env = make_env(app, 'PROD')
58-
deploy_envs.append(prod_env)
58+
# prod_env = make_env(app, 'PROD')
59+
# deploy_envs.append(prod_env)
60+
61+
PipelineStack(app, "araPipelineStack",
62+
env={
63+
'account': cicd_account_context.get('account'),
64+
'region': cicd_account_context.get('region')
65+
},
66+
deploy_envs=deploy_envs)
5967

60-
PipelineStack(app, "araPipelineStack",
61-
env={
62-
'account': cicd_account_context.get('account'),
63-
'region': cicd_account_context.get('region')
64-
},
65-
deploy_envs=deploy_envs)
66-
else:
67-
DataLake(app, "ara")
68+
DataLake(app, "ara")
6869

6970
app.synth()

refarch/aws-native/cdk.context.json

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,21 @@
66
},
77
"DEV": {
88
"name": "dev",
9-
"region": "eu-west-1",
9+
"region": "<DEV_REGION>",
1010
"account": "<DEV_ACCOUNT>"
1111
},
1212
"PROD": {
1313
"name": "prod",
14-
"region": "eu-west-1",
14+
"region": "<PROD_REGION>",
1515
"account": "<PROD_ACCOUNT>"
1616
},
17-
"availability-zones:account=<DEV_ACCOUNT>:region=eu-west-1": [
18-
"eu-west-1a",
19-
"eu-west-1b",
20-
"eu-west-1c"
17+
"availability-zones:account=<DEV_ACCOUNT>:region=<DEV_REGION>": [
18+
"<DEV_REGION>a",
19+
"<DEV_REGION>b",
20+
"<DEV_REGION>c"
2121
],
22-
"availability-zones:account=<PROD_ACCOUNT>:region=eu-west-1": [
23-
"eu-west-1a",
24-
"eu-west-1b",
25-
"eu-west-1c"
26-
]
22+
"availability-zones:account=<PROD_ACCOUNT>:region=<PROD_REGION>": [
23+
"<PROD_REGION>a",
24+
"<PROD_REGION>b",
25+
"<PROD_REGION>c"
2726
}

refarch/aws-native/cdk.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@
1616
"QuickSightIdentityRegion": "<QUICKSIGHT_IDENTITY_REGION>",
1717
"EnableDeploymentTracking": "true"
1818
}
19-
}
19+
}

refarch/aws-native/cicd/pipeline.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,14 @@ def __init__(self, scope: Construct, id: str, deploy_envs: list, **kwargs) -> No
4545
'cd refarch/aws-native',
4646
'pip install -r requirements.txt',
4747
'which npx',
48-
'npm install -g aws-cdk',
48+
'npm install -g aws-cdk@2.51.0',
4949
'cdk synth'
5050
],
5151
primary_output_directory='refarch/aws-native/cdk.out'),
5252
cross_account_keys=True,
53-
53+
self_mutation=True
5454
)
55-
55+
5656
for env in deploy_envs:
5757
pipeline.add_stage(stage=PipelineStage(self, 'AnalyticsPipelineStage', env=Environment(
5858
account=env.account,

refarch/aws-native/common/common_cdk/data_lake.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# SPDX-License-Identifier: MIT-0
33

44
from aws_cdk import aws_dynamodb as _dynamodb
5+
from aws_cdk import aws_iam as _iam
56
from aws_cdk import CfnOutput, Stack, Tags
67
from constructs import Construct
78

@@ -101,6 +102,10 @@ def __init__(self, scope: Construct, id: str, **kwargs) -> None:
101102
quicksight_username=quicksight_username,
102103
quicksight_identity_region=quicksight_identity_region)
103104

105+
quicksight_role = _iam.Role.from_role_name(self,'QuicksightRole', role_name='aws-quicksight-service-role-v0')
106+
quicksight_role.node.add_dependency(dataviz_stack)
107+
data_lake.clean_s3_bucket.encryption_key.grant_decrypt(quicksight_role)
108+
104109
CfnOutput(self, 'QuickSight-Security-Group-Id',
105110
value=dataviz_stack.quicksight_security_group_id)
106111

refarch/aws-native/dataviz/dataviz_cdk/qs_athena_dataset.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,17 +32,14 @@ def __init__(
3232
super().__init__(scope, id, **kwargs)
3333

3434
aws_account_id = Aws.ACCOUNT_ID
35-
uniquestring = datetime.datetime.utcnow().strftime('%Y%m%d%H%M%S')
36-
athena_dataset_id = athena_dataset_name + uniquestring
37-
athena_dataset_physical_id = athena_dataset_name + uniquestring
3835

3936
quicksight_athena_dataset = cr.AwsCustomResource(self, 'AthenaDataSet',
4037
on_create={
4138
"service": "QuickSight",
4239
"action": "createDataSet",
4340
"parameters": {
4441
"AwsAccountId": aws_account_id,
45-
"DataSetId": athena_dataset_id,
42+
"DataSetId": athena_dataset_name,
4643
"Name": athena_dataset_name,
4744
"ImportMode": "DIRECT_QUERY",
4845
"PhysicalTableMap": {
@@ -73,16 +70,16 @@ def __init__(
7370

7471
},
7572
"physical_resource_id": cr.PhysicalResourceId.of(
76-
athena_dataset_physical_id)},
73+
athena_dataset_name)},
7774
on_delete={
7875
"service": "QuickSight",
7976
"action": "deleteDataSet",
8077
"parameters": {
8178
"AwsAccountId": aws_account_id,
82-
"DataSetId": athena_dataset_id
79+
"DataSetId": athena_dataset_name
8380
},
8481
"physical_resource_id": cr.PhysicalResourceId.of(
85-
athena_dataset_physical_id)},
82+
athena_dataset_name)},
8683
policy=iam_policy
8784
)
8885

0 commit comments

Comments
 (0)