|
1 | 1 | import os
|
2 | 2 | from pathlib import Path
|
3 | 3 |
|
4 |
| -from aws_cdk import Stack, Tags |
| 4 | +from aws_cdk import Aspects, Stack, Tags |
| 5 | +from cdk_nag import AwsSolutionsChecks, NagSuppressions |
5 | 6 | from constructs import Construct
|
6 | 7 | from git import Repo
|
7 | 8 | from my_service.api_construct import ApiConstruct # type: ignore
|
@@ -36,4 +37,48 @@ def __init__(self, scope: Construct, id: str, **kwargs) -> None:
|
36 | 37 | # from running the service pipeline and without redeploying the service lambdas. For the sake of this template
|
37 | 38 | # example, it is deployed as part of the service stack
|
38 | 39 | self.dynamic_configuration = ConfigurationStore(self, f'{id}dynamic_conf'[0:64], ENVIRONMENT, SERVICE_NAME, CONFIGURATION_NAME)
|
39 |
| - self.lambdas = ApiConstruct(self, f'{id}Service'[0:64], self.dynamic_configuration.config_app.name) |
| 40 | + self.api = ApiConstruct(self, f'{id}Service'[0:64], self.dynamic_configuration.config_app.name) |
| 41 | + |
| 42 | + # add security check |
| 43 | + self._add_security_tests() |
| 44 | + |
| 45 | + def _add_security_tests(self) -> None: |
| 46 | + Aspects.of(self).add(AwsSolutionsChecks(verbose=True)) |
| 47 | + # Suppress a specific rule for this resource |
| 48 | + NagSuppressions.add_stack_suppressions( |
| 49 | + self, |
| 50 | + [ |
| 51 | + { |
| 52 | + 'id': 'AwsSolutions-IAM4', |
| 53 | + 'reason': 'policy for cloudwatch logs.' |
| 54 | + }, |
| 55 | + { |
| 56 | + 'id': 'AwsSolutions-IAM5', |
| 57 | + 'reason': 'policy for cloudwatch logs.' |
| 58 | + }, |
| 59 | + { |
| 60 | + 'id': 'AwsSolutions-APIG2', |
| 61 | + 'reason': 'lambda does input validation' |
| 62 | + }, |
| 63 | + { |
| 64 | + 'id': 'AwsSolutions-APIG1', |
| 65 | + 'reason': 'not mandatory in a sample template' |
| 66 | + }, |
| 67 | + { |
| 68 | + 'id': 'AwsSolutions-APIG3', |
| 69 | + 'reason': 'not mandatory in a sample template' |
| 70 | + }, |
| 71 | + { |
| 72 | + 'id': 'AwsSolutions-APIG6', |
| 73 | + 'reason': 'not mandatory in a sample template' |
| 74 | + }, |
| 75 | + { |
| 76 | + 'id': 'AwsSolutions-APIG4', |
| 77 | + 'reason': 'authorization not mandatory in a sample template' |
| 78 | + }, |
| 79 | + { |
| 80 | + 'id': 'AwsSolutions-COG4', |
| 81 | + 'reason': 'not using cognito' |
| 82 | + }, |
| 83 | + ], |
| 84 | + ) |
0 commit comments