Skip to content

Commit

Permalink
Update to version v1.4.1
Browse files Browse the repository at this point in the history
- Updated the bucket policy on the logging bucket to grant access to the logging service principal (logging.s3.amazonaws.com) for access log delivery.
- Upgraded CDK version to 2.75.0
  • Loading branch information
tabdunabi authored Apr 18, 2023
2 parents 7144ea1 + a33a12e commit 99132f9
Show file tree
Hide file tree
Showing 22 changed files with 175 additions and 97 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ pyvenv.cfg
**/.pytest_cache
**/.coverage
**/coverage-reports/
.coverage.*

# linting, scanning configurations, sonarqube
.scannerwork/
Expand Down
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [1.4.1] - 2023-04-18

### Changed

- Enabled Amazon S3 server access logging on the logging bucket
- Upgraded CDK version to 2.75.0

## [1.4.0] - 2023-03-29

### Changed
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -609,7 +609,7 @@ The following procedures assumes that all the OS-level configuration has been co
- [AWS Command Line Interface](https://aws.amazon.com/cli/)
- [Python](https://www.python.org/) 3.9 or newer
- [Node.js](https://nodejs.org/en/) 16.x or newer
- [AWS CDK](https://aws.amazon.com/cdk/) 2.44.0 or newer
- [AWS CDK](https://aws.amazon.com/cdk/) 2.75.0 or newer
- [Amazon Corretto OpenJDK](https://docs.aws.amazon.com/corretto/) 17.0.4.1

> **Please ensure you test the templates before updating any production deployments.**
Expand Down
2 changes: 1 addition & 1 deletion source/cdk_solution_helper_py/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ This README summarizes using the tool.
Install this package. It requires at least

- Python 3.9
- AWS CDK version 2.44.0 or higher
- AWS CDK version 2.75.0 or higher

To install the packages:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

from aws_solutions.cdk.context import SolutionContext
from aws_solutions.cdk.stack import SolutionStack
from aws_solutions.cdk.synthesizers import SolutionStackSubstitions
from aws_solutions.cdk.synthesizers import SolutionStackSubstitutions


class CDKSolution:
Expand All @@ -31,11 +31,11 @@ class CDKSolution:
def __init__(self, cdk_json_path: Path, qualifier="hnb659fds"):
self.qualifier = qualifier
self.context = SolutionContext(cdk_json_path=cdk_json_path)
self.synthesizer = SolutionStackSubstitions(qualifier=self.qualifier)
self.synthesizer = SolutionStackSubstitutions(qualifier=self.qualifier)

def reset(self) -> None:
"""
Get a new synthesizer for this CDKSolution - useful for testing
:return: None
"""
self.synthesizer = SolutionStackSubstitions(qualifier=self.qualifier, generate_bootstrap_version_rule=False)
self.synthesizer = SolutionStackSubstitutions(qualifier=self.qualifier, generate_bootstrap_version_rule=False)
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
aws-lambda-powertools==2.10.0
aws-xray-sdk==2.11.0
aws-lambda-powertools==2.14.0
aws-xray-sdk==2.12.0
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@
import re
import shutil
from contextlib import suppress
from dataclasses import field, dataclass
from dataclasses import dataclass, field
from fileinput import FileInput
from pathlib import Path
from typing import List, Dict, Tuple
from typing import Dict, List, Tuple

import jsii
from aws_cdk import IStackSynthesizer, DefaultStackSynthesizer, ISynthesisSession
from aws_cdk import DefaultStackSynthesizer, IStackSynthesizer, ISynthesisSession

logger = logging.getLogger("cdk-helper")

Expand Down Expand Up @@ -256,7 +256,7 @@ def save(self, asset_path_global: Path = None, asset_path_regional: Path = None)


@jsii.implements(IStackSynthesizer)
class SolutionStackSubstitions(DefaultStackSynthesizer):
class SolutionStackSubstitutions(DefaultStackSynthesizer):
"""Used to handle AWS Solutions template substitutions and sanitization"""

substitutions = None
Expand Down Expand Up @@ -295,11 +295,11 @@ def synthesize(self, session: ISynthesisSession):

logger.info(f"solutions parameter substitution in {session.assembly.outdir} started")
for template in self._template_names(session):
logger.info(f"substutiting parameters in {str(template)}")
logger.info(f"substituting parameters in {str(template)}")
with FileInput(template, inplace=True) as template_lines:
for line in template_lines:
# handle all template subsitutions in the line
for match in SolutionStackSubstitions.substitution_re.findall(line):
# handle all template substitutions in the line
for match in SolutionStackSubstitutions.substitution_re.findall(line):
placeholder = match.replace("%", "")
replacement = self._stack.node.try_get_context(placeholder)
if not replacement:
Expand Down
2 changes: 1 addition & 1 deletion source/cdk_solution_helper_py/helpers_cdk/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def get_version():
},
install_requires=[
"pip>=22.3.1",
"aws_cdk_lib==2.44.0",
"aws_cdk_lib==2.75.0",
"Click==8.1.3",
"boto3==1.26.47",
"requests==2.28.1",
Expand Down
4 changes: 2 additions & 2 deletions source/cdk_solution_helper_py/requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
aws_cdk_lib==2.44.0
aws-cdk.aws-servicecatalogappregistry-alpha==2.44.0a0
aws_cdk_lib==2.75.0
aws-cdk.aws-servicecatalogappregistry-alpha==2.75.0a0
black
boto3==1.26.47
requests==2.28.1
Expand Down
5 changes: 3 additions & 2 deletions source/infrastructure/cdk.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
"context": {
"SOLUTION_NAME": "Maintaining Personalized Experiences with Machine Learning",
"SOLUTION_ID": "SO0170",
"SOLUTION_VERSION": "v1.4.0",
"SOLUTION_VERSION": "v1.4.1",
"APP_REGISTRY_NAME": "personalized-experiences-ML",
"APPLICATION_TYPE": "AWS-Solutions"
"APPLICATION_TYPE": "AWS-Solutions",
"@aws-cdk/aws-s3:serverAccessLogsUseBucketPolicy": true
}
}
7 changes: 3 additions & 4 deletions source/infrastructure/personalize/s3/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,11 @@
from typing import List

import aws_cdk.aws_iam as iam
from aws_cdk import RemovalPolicy, CfnResource
from aws_cdk.aws_s3 import Bucket, BucketEncryption, BlockPublicAccess
from aws_cdk import CfnResource, RemovalPolicy
from aws_cdk.aws_s3 import BlockPublicAccess, Bucket, BucketEncryption
from aws_solutions.cdk.cfn_nag import CfnNagSuppression, add_cfn_nag_suppressions
from constructs import Construct

from aws_solutions.cdk.cfn_nag import add_cfn_nag_suppressions, CfnNagSuppression

logger = logging.getLogger("cdk-helper")


Expand Down
39 changes: 17 additions & 22 deletions source/infrastructure/personalize/stack.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,51 +12,45 @@
# ######################################################################################################################

from aws_cdk import (
CfnCondition,
Fn,
Aspects,
Aws,
Duration,
CfnCondition,
CfnOutput,
CfnParameter,
Duration,
Fn,
Tags,
Aspects,
)
from aws_cdk.aws_events import EventBus
from aws_cdk.aws_s3 import EventType, NotificationKeyFilter
from aws_cdk.aws_s3_notifications import LambdaDestination
from aws_cdk.aws_stepfunctions import (
StateMachine,
Chain,
Parallel,
TaskInput,
)
from constructs import Construct

from aws_cdk.aws_stepfunctions import Chain, Parallel, StateMachine, TaskInput
from aws_solutions.cdk.aws_lambda.cfn_custom_resources.resource_name import ResourceName
from aws_solutions.cdk.aws_lambda.layers.aws_lambda_powertools import PowertoolsLayer
from aws_solutions.cdk.cfn_nag import (
CfnNagSuppressAll,
CfnNagSuppression,
add_cfn_nag_suppressions,
CfnNagSuppressAll,
)
from aws_solutions.cdk.stack import SolutionStack
from aws_solutions.scheduler.cdk.construct import Scheduler
from constructs import Construct
from personalize.aws_lambda.functions import (
S3EventHandler,
CreateDatasetGroup,
CreateSchema,
CreateBatchInferenceJob,
CreateBatchSegmentJob,
CreateCampaign,
CreateConfig,
CreateDataset,
CreateDatasetGroup,
CreateDatasetImportJob,
CreateEventTracker,
CreateFilter,
CreateRecommender,
CreateSchema,
CreateSolution,
CreateSolutionVersion,
CreateCampaign,
CreateFilter,
CreateBatchInferenceJob,
CreateTimestamp,
CreateConfig,
CreateBatchSegmentJob,
CreateRecommender,
S3EventHandler,
)
from personalize.aws_lambda.functions.prepare_input import PrepareInput
from personalize.aws_lambda.layers import SolutionsLayer
Expand All @@ -79,6 +73,7 @@
class PersonalizeStack(SolutionStack):
def __init__(self, scope: Construct, construct_id: str, *args, **kwargs) -> None:
super().__init__(scope, construct_id, *args, **kwargs)
self.synthesizer.bind(self)

# CloudFormation Parameters
self.email = CfnParameter(
Expand Down
2 changes: 1 addition & 1 deletion source/infrastructure/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
author="AWS Solutions Builders",
packages=setuptools.find_packages(),
install_requires=[
"aws-cdk-lib==2.44.0",
"aws-cdk-lib==2.75.0",
"pip>=22.3.1",
],
python_requires=">=3.9",
Expand Down
6 changes: 3 additions & 3 deletions source/requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
avro==1.11.1
black
boto3==1.26.47
aws_cdk_lib==2.44.0
aws_solutions_constructs.aws_lambda_sns==2.25.0
aws-cdk.aws-servicecatalogappregistry-alpha==2.44.0a0
aws_cdk_lib==2.75.0
aws_solutions_constructs.aws_lambda_sns==2.38.0
aws-cdk.aws-servicecatalogappregistry-alpha==2.75.0a0
requests==2.28.1
crhelper==2.0.11
cronex==0.1.3.1
Expand Down
2 changes: 1 addition & 1 deletion source/scheduler/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ This README summarizes using the scheduler.
Install this package. It requires at least:

- Python 3.9
- AWS CDK version 2.44.0 or higher
- AWS CDK version 2.75.0 or higher

To install the packages:

Expand Down
2 changes: 1 addition & 1 deletion source/scheduler/cdk/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def get_version():
packages=setuptools.find_namespace_packages(exclude=["build*"]),
install_requires=[
"pip>=22.3.1",
"aws_cdk_lib==2.44.0",
"aws_cdk_lib==2.75.0",
"Click==8.1.3",
"boto3==1.26.47",
],
Expand Down
4 changes: 2 additions & 2 deletions source/scheduler/common/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ def get_version():
packages=setuptools.find_namespace_packages(exclude=["build*"]),
install_requires=[
"pip>=22.3.1",
"aws-lambda-powertools==2.10.0",
"aws-xray-sdk==2.11.0",
"aws-lambda-powertools==2.14.0",
"aws-xray-sdk==2.12.0",
"aws-solutions-python==2.0.0",
"click==8.1.3",
"cronex==0.1.3.1",
Expand Down
11 changes: 6 additions & 5 deletions source/tests/aspects/test_personalize_app_stack.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,17 @@
# the specific language governing permissions and limitations under the License. #
# #####################################################################################################################

import pytest
from pathlib import Path

import aws_cdk as cdk
from aws_cdk.assertions import Template, Capture
import pytest
from aws_cdk.assertions import Capture, Template
from aws_solutions.cdk import CDKSolution

solution = CDKSolution(cdk_json_path=Path(__file__).parent.parent.absolute() / "infrastructure" / "cdk.json")

from infrastructure.personalize.stack import PersonalizeStack
from infrastructure.aspects.app_registry import AppRegistry
from infrastructure.personalize.stack import PersonalizeStack


@pytest.fixture(scope="module")
Expand Down Expand Up @@ -66,11 +67,11 @@ def test_service_catalog_registry_application(synth_template):
"Tags": {
"SOLUTION_ID": "SO0170",
"SOLUTION_NAME": "Maintaining Personalized Experiences with Machine Learning",
"SOLUTION_VERSION": "v1.4.0",
"SOLUTION_VERSION": "v1.4.1",
"Solutions:ApplicationType": "AWS-Solutions",
"Solutions:SolutionID": "SO0170",
"Solutions:SolutionName": "Maintaining Personalized Experiences with Machine Learning",
"Solutions:SolutionVersion": "v1.4.0",
"Solutions:SolutionVersion": "v1.4.1",
},
},
)
Expand Down
9 changes: 4 additions & 5 deletions source/tests/cdk_solution_helper/test_synthesizers.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,9 @@

import pytest
from aws_cdk import App, Stack

from aws_solutions.cdk.interfaces import TemplateOptions
from aws_solutions.cdk.mappings import Mappings
from aws_solutions.cdk.synthesizers import (
SolutionStackSubstitions,
)
from aws_solutions.cdk.synthesizers import SolutionStackSubstitutions


@pytest.fixture
Expand All @@ -45,9 +42,10 @@ def template():
if ctx_var_val:
context[ctx_var] = ctx_var_val

synth = SolutionStackSubstitions()
synth = SolutionStackSubstitutions()
app = App(context=context)
stack = Stack(app, "stack-id-1", synthesizer=synth)
stack.synthesizer.bind(stack)
TemplateOptions(stack, "id_1", "description_1", "stack_1.template")
Mappings(stack, "SO001")

Expand All @@ -56,6 +54,7 @@ def template():
yield app.synth().stacks[0].template



def test_cloudformation_template_init(template):
assert template["Parameters"]
assert template["Rules"]["CheckBootstrapVersion"]
Expand Down
3 changes: 3 additions & 0 deletions source/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
LayerVersionProps,
Runtime,
)
from aws_solutions.cdk.synthesizers import SolutionStackSubstitutions
from aws_solutions.core import get_service_client
from botocore.stub import Stubber
from constructs import Construct
Expand All @@ -44,6 +45,7 @@
class Solution:
id = "SO0170test"
version = "99.99.99"
synthesizer = SolutionStackSubstitutions()

@property
def context(self):
Expand All @@ -53,6 +55,7 @@ def context(self):
"SOLUTION_VERSION": self.version,
"APP_REGISTRY_NAME": "personalized-experiences-ML",
"APPLICATION_TYPE": "AWS-Solutions",
"@aws-cdk/aws-s3:serverAccessLogsUseBucketPolicy": True,
}


Expand Down
Loading

0 comments on commit 99132f9

Please sign in to comment.