├── .github ├── ISSUE_TEMPLATE │ ├── bug_report.md │ └── feature_request.md └── PULL_REQUEST_TEMPLATE.md ├── .gitignore ├── CHANGELOG.md ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── LICENSE.txt ├── NOTICE.txt ├── README.md ├── deployment └── run-unit-tests.sh └── source ├── .coveragerc ├── .gitignore ├── cdk_solution_helper_py ├── CHANGELOG.md ├── README.md ├── helpers_cdk │ ├── aws_solutions │ │ ├── __init__.py │ │ └── cdk │ │ │ ├── __init__.py │ │ │ ├── aspects.py │ │ │ ├── aws_lambda │ │ │ ├── __init__.py │ │ │ ├── cfn_custom_resources │ │ │ │ ├── __init__.py │ │ │ │ ├── resource_hash │ │ │ │ │ ├── __init__.py │ │ │ │ │ ├── hash.py │ │ │ │ │ └── src │ │ │ │ │ │ ├── __init__.py │ │ │ │ │ │ └── custom_resources │ │ │ │ │ │ ├── __init__.py │ │ │ │ │ │ ├── hash.py │ │ │ │ │ │ └── requirements.txt │ │ │ │ ├── resource_name │ │ │ │ │ ├── __init__.py │ │ │ │ │ ├── name.py │ │ │ │ │ └── src │ │ │ │ │ │ ├── __init__.py │ │ │ │ │ │ └── custom_resources │ │ │ │ │ │ ├── __init__.py │ │ │ │ │ │ ├── name.py │ │ │ │ │ │ └── requirements.txt │ │ │ │ ├── solutions_metrics │ │ │ │ │ ├── __init__.py │ │ │ │ │ ├── metrics.py │ │ │ │ │ └── src │ │ │ │ │ │ ├── __init__.py │ │ │ │ │ │ └── custom_resources │ │ │ │ │ │ ├── __init__.py │ │ │ │ │ │ ├── metrics.py │ │ │ │ │ │ └── requirements.txt │ │ │ │ ├── url_downloader │ │ │ │ │ ├── __init__.py │ │ │ │ │ ├── src │ │ │ │ │ │ ├── __init__.py │ │ │ │ │ │ └── custom_resources │ │ │ │ │ │ │ ├── __init__.py │ │ │ │ │ │ │ ├── requirements.txt │ │ │ │ │ │ │ └── url_downloader.py │ │ │ │ │ └── url_downloader.py │ │ │ │ └── url_helper │ │ │ │ │ ├── __init__.py │ │ │ │ │ ├── src │ │ │ │ │ ├── __init__.py │ │ │ │ │ └── custom_resources │ │ │ │ │ │ ├── __init__.py │ │ │ │ │ │ ├── requirements.txt │ │ │ │ │ │ └── url_helper.py │ │ │ │ │ └── url_helper.py │ │ │ ├── environment.py │ │ │ ├── environment_variable.py │ │ │ ├── java │ │ │ │ ├── __init__.py │ │ │ │ ├── bundling.py │ │ │ │ └── function.py │ │ │ ├── layers │ │ │ │ ├── __init__.py │ │ │ │ └── aws_lambda_powertools │ │ │ │ │ ├── __init__.py │ │ │ │ │ ├── layer.py │ │ │ │ │ └── requirements │ │ │ │ │ └── requirements.txt │ │ │ └── python │ │ │ │ ├── __init__.py │ │ │ │ ├── bundling.py │ │ │ │ ├── directory_hash.py │ │ │ │ ├── function.py │ │ │ │ └── layer.py │ │ │ ├── cfn_nag.py │ │ │ ├── context.py │ │ │ ├── helpers │ │ │ ├── __init__.py │ │ │ ├── copytree.py │ │ │ ├── loader.py │ │ │ └── logger.py │ │ │ ├── interfaces.py │ │ │ ├── mappings.py │ │ │ ├── scripts │ │ │ ├── __init__.py │ │ │ └── build_s3_cdk_dist.py │ │ │ ├── stack.py │ │ │ ├── stepfunctions │ │ │ ├── __init__.py │ │ │ ├── solution_fragment.py │ │ │ └── solutionstep.py │ │ │ ├── synthesizers.py │ │ │ ├── tools │ │ │ ├── __init__.py │ │ │ └── cleaner.py │ │ │ └── utils │ │ │ ├── __init__.py │ │ │ ├── is_solution_build.py │ │ │ └── secure_bucket.py │ └── setup.py ├── helpers_common │ ├── aws_solutions │ │ └── core │ │ │ ├── __init__.py │ │ │ ├── config.py │ │ │ ├── helpers.py │ │ │ └── logging.py │ └── setup.py └── requirements-dev.txt ├── example ├── 1-defaults │ └── forecast-defaults.yaml ├── 2-overrides │ └── forecast-defaults.yaml ├── 3-different-algorithm │ └── forecast-defaults.yaml ├── 5-taxi │ └── forecast-defaults.yaml └── data │ ├── demand.csv │ ├── demand.metadata.csv │ └── demand.related.csv ├── forecast-shared ├── setup.py └── shared │ ├── Dataset │ ├── __init__.py │ ├── data_frequency.py │ ├── data_timestamp_format.py │ ├── dataset.py │ ├── dataset_domain.py │ ├── dataset_file.py │ ├── dataset_import_job.py │ ├── dataset_name.py │ └── dataset_type.py │ ├── DatasetGroup │ ├── __init__.py │ ├── dataset_group.py │ ├── dataset_group_name.py │ └── schemas.py │ ├── Forecast │ ├── __init__.py │ └── forecast.py │ ├── Predictor │ ├── __init__.py │ ├── auto_predictor.py │ └── predictor.py │ ├── Tags │ ├── __init__.py │ └── tags.py │ ├── __init__.py │ ├── config.py │ ├── helpers.py │ ├── logging.py │ ├── quicksight_custom_resources │ ├── __init__.py │ ├── quicksight.py │ └── util │ │ ├── __init__.py │ │ ├── analysis.py │ │ ├── config │ │ ├── __init__.py │ │ ├── analysis-main.config.json │ │ ├── config.yaml │ │ ├── dashboard-main.config.json │ │ ├── dataset-forecast.config.json │ │ └── template-main.config.json │ │ ├── dashboard.py │ │ ├── dataset.py │ │ ├── datasource.py │ │ ├── quicksight.py │ │ ├── quicksight_application.py │ │ ├── quicksight_resource.py │ │ ├── source_entity.py │ │ └── template.py │ ├── s3 │ ├── __init__.py │ ├── exceptions.py │ └── notification.py │ └── status.py ├── glue ├── __init__.py └── jobs │ ├── __init__.py │ └── forecast_etl.py ├── images └── Forecast.jpg ├── infrastructure ├── README.md ├── aspects │ ├── __init__.py │ └── app_registry.py ├── cdk.json ├── deploy.py ├── forecast │ ├── __init__.py │ ├── aws_lambda │ │ ├── __init__.py │ │ ├── functions │ │ │ ├── __init__.py │ │ │ ├── base.py │ │ │ ├── create_dataset_group.py │ │ │ ├── create_dataset_import_job.py │ │ │ ├── create_forecast.py │ │ │ ├── create_forecast_export.py │ │ │ ├── create_glue_table_name.py │ │ │ ├── create_predictor.py │ │ │ ├── create_predictor_backtest_export.py │ │ │ ├── create_quicksight_analysis.py │ │ │ ├── s3_event.py │ │ │ └── sns.py │ │ ├── layers │ │ │ ├── __init__.py │ │ │ └── forecast_solution │ │ │ │ ├── __init__.py │ │ │ │ ├── layer.py │ │ │ │ └── requirements │ │ │ │ └── requirements.txt │ │ └── policies │ │ │ ├── __init__.py │ │ │ └── factory.py │ ├── buckets │ │ ├── __init__.py │ │ ├── access_logs_bucket.py │ │ ├── athena_bucket.py │ │ └── data_bucket.py │ ├── etl │ │ ├── __init__.py │ │ ├── athena.py │ │ ├── glue.py │ │ └── policies.py │ ├── forecast │ │ ├── __init__.py │ │ ├── downloader.py │ │ └── parameters.py │ ├── sagemaker │ │ ├── __init__.py │ │ ├── lifecycle_config.py │ │ ├── notebook.py │ │ └── policies.py │ ├── sns │ │ ├── __init__.py │ │ └── notifications.py │ └── stack.py ├── pytest.ini ├── quicksight │ ├── __init__.py │ └── template_source.py ├── setup.py └── tests │ ├── __init__.py │ ├── assets │ └── .keep │ └── test_parameters.py ├── lambdas ├── __init__.py ├── createdatasetgroup │ ├── __init__.py │ └── handler.py ├── createdatasetimportjob │ ├── __init__.py │ └── handler.py ├── createforecast │ ├── __init__.py │ ├── create_forecast.py │ └── create_forecast_export.py ├── creategluetablename │ ├── __init__.py │ └── handler.py ├── createpredictor │ ├── __init__.py │ ├── create_predictor.py │ └── create_predictor_backtest_export.py ├── createquicksightanalysis │ ├── __init__.py │ └── handler.py ├── lambda_datasetutils │ └── requirements.txt ├── lambda_dependencies │ └── requirements.txt ├── notification │ ├── __init__.py │ └── handler.py └── sns │ ├── __init__.py │ └── handler.py ├── notebook ├── __init__.py └── samples │ └── notebooks │ └── SampleVisualization.ipynb ├── pytest.ini ├── requirements-build-and-test.txt ├── synthetic ├── README.md ├── __init__.py ├── config.yaml └── create_synthetic_data.py └── tests ├── __init__.py ├── aspects └── test_python_cdk_app_stack.py ├── conftest.py ├── fixtures └── config_and_overrides.yaml ├── glue ├── __init__.py └── test_glue_etl_spark.py ├── lambdas ├── __init__.py ├── createdataset │ ├── __init__.py │ └── test_handler.py ├── createdatasetgroup │ ├── __init__.py │ └── test_handler.py ├── createdatasetimportjob │ ├── __init__.py │ └── test_handler.py ├── createforecast │ ├── __init__.py │ └── test_handler.py ├── creategluetablename │ ├── __init__.py │ └── test_handler.py ├── createpredictor │ ├── __init__.py │ └── test_handler.py ├── createquicksightanalysis │ ├── __init__.py │ └── test_handler.py ├── notification │ ├── __init__.py │ └── test_handler.py └── sns │ ├── __init__.py │ └── test_sns.py ├── notebook ├── __init__.py └── test_notebook.py ├── shared ├── __init__.py ├── test_data_frequency.py ├── test_data_timestamp_format.py ├── test_dataset.py ├── test_dataset_domain.py ├── test_dataset_file.py ├── test_dataset_group.py ├── test_dataset_group_name.py ├── test_dataset_import_job.py ├── test_dataset_name.py ├── test_dataset_type.py ├── test_forecast.py ├── test_predictor.py ├── test_s3_event.py └── test_s3_exceptions.py ├── test_config_data.py ├── test_helpers.py ├── test_logging.py ├── test_secure_bucket.py ├── test_status.py ├── test_synthetic.py └── test_tags.py /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a report to help us improve 4 | title: '' 5 | labels: bug 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Describe the bug** 11 | A clear and concise description of what the bug is. 12 | 13 | **To Reproduce** 14 | Steps to reproduce the behavior. 15 | 16 | **Expected behavior** 17 | A clear and concise description of what you expected to happen. 18 | 19 | **Please complete the following information about the solution:** 20 | - [ ] Version: [e.g. v1.3.0] 21 | 22 | To get the version of the solution, you can look at the description of the created CloudFormation stack. For example, "(SO0123) Improving Forecast Accuracy with Machine Learning v1.3.0[...]". 23 | 24 | - [ ] Region: [e.g. us-east-1] 25 | - [ ] Was the solution modified from the version published on this repository? 26 | - [ ] If the answer to the previous question was yes, are the changes available on GitHub? 27 | - [ ] Have you checked your [service quotas](https://docs.aws.amazon.com/general/latest/gr/aws_service_limits.html) for the services this solution uses? 28 | - [ ] Were there any errors in the CloudWatch Logs? 29 | 30 | **Screenshots** 31 | If applicable, add screenshots to help explain your problem (please **DO NOT include sensitive information**). 32 | 33 | **Additional context** 34 | Add any other context about the problem here. 35 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: Suggest an idea for this solution 4 | title: '' 5 | labels: enhancement 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Is your feature request related to a problem? Please describe.** 11 | A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] 12 | 13 | **Describe the feature you'd like** 14 | A clear and concise description of what you want to happen. 15 | 16 | **Additional context** 17 | Add any other context or screenshots about the feature request here. 18 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | *Issue #, if available:* 2 | 3 | *Description of changes:* 4 | 5 | By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice. 6 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Modified based on https://www.gitignore.io/api/visualstudiocode,python 2 | 3 | # compiled output 4 | **/global-s3-assets 5 | **/regional-s3-assets 6 | **/build-s3-assets 7 | **/open-source 8 | **/tmp 9 | 10 | ### Python ### 11 | # Byte-compiled / optimized / DLL files 12 | __pycache__/ 13 | *.py[cod] 14 | *$py.class 15 | 16 | # Python Distribution / packaging 17 | *.egg-info/ 18 | *.egg 19 | 20 | # Python Virtual Environments 21 | **/venv* 22 | **/.venv* 23 | 24 | ## Python Testing 25 | **/.pytest_cache 26 | **/.coverage 27 | **/coverage-reports/ 28 | 29 | # linting, scanning configurations, sonarqube 30 | .scannerwork/ 31 | 32 | ### VisualStudioCode ### 33 | .vscode/* 34 | 35 | ### IntelliJ/ PyCharm ### 36 | **/.idea/* 37 | 38 | # System Files 39 | **/.DS_Store 40 | 41 | # CDK 42 | **/cdk.out 43 | 44 | # Glue 45 | .glue/* 46 | 47 | # Generated test assets 48 | source/infrastructure/tests/assets/* 49 | !source/infrastructure/tests/assets/.keep 50 | 51 | # Python build files 52 | source/cdk_solution_helper_py/helpers_cdk/build/* 53 | source/cdk_solution_helper_py/helpers_common/build/* 54 | source/infrastructure/build/* 55 | source/forecast-shared/build/* -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | ## Code of Conduct 2 | This project has adopted the [Amazon Open Source Code of Conduct](https://aws.github.io/code-of-conduct). 3 | For more information see the [Code of Conduct FAQ](https://aws.github.io/code-of-conduct-faq) or contact 4 | opensource-codeofconduct@amazon.com with any additional questions or comments. 5 | -------------------------------------------------------------------------------- /NOTICE.txt: -------------------------------------------------------------------------------- 1 | aws-forecast-visualization 2 | 3 | Copyright 2020-2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. 4 | Licensed under the Apache License Version 2.0 (the "License"). You may not use this file except 5 | in compliance with the License. A copy of the License is located at http://www.apache.org/licenses/ 6 | or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, 7 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, express or implied. See the License for the 8 | specific language governing permissions and limitations under the License. 9 | 10 | ********************** 11 | THIRD PARTY COMPONENTS 12 | ********************** 13 | This software includes third party software subject to the following copyrights: 14 | 15 | AWS SDK under the Apache License Version 2.0 16 | boto3 under the Apache License Version 2.0 17 | black under the Massachusetts Institute of Technology (MIT) license 18 | click under the BSD 3-Clause license 19 | coverage under the Apache License Version 2.0 20 | crhelper under the Apache License Version 2.0 21 | docker-py under the Apache License Version 2.0 22 | flaky under the Apache License Version 2.0 23 | matplotlib under the PSF license 24 | moto under the Apache License Version 2.0 25 | numpy under the BSD 3-Clause license 26 | packaging under the Apache License Version 2.0 27 | pandas under the BSD 3-Clause license 28 | pytest under the Massachusetts Institute of Technology (MIT) license 29 | pytest-cov under the Massachusetts Institute of Technology (MIT) license 30 | pytest-mock under the Massachusetts Institute of Technology (MIT) license 31 | pytest-env under the Massachusetts Institute of Technology (MIT) license 32 | PyYAML under the Massachusetts Institute of Technology (MIT) license 33 | requests under the Apache License Version 2.0 34 | requests-mock under the Apache License Version 2.0 35 | responses under the Apache License Version 2.0 36 | tenacity under the Apache License Version 2.0 37 | 38 | The Apache License Version Version 2.0 is included in LICENSE.txt. -------------------------------------------------------------------------------- /deployment/run-unit-tests.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # This assumes all of the OS-level configuration has been completed and git repo has already been cloned 4 | # 5 | # This script should be run from the repo's deployment directory 6 | # cd deployment 7 | # ./run-unit-tests.sh 8 | # 9 | 10 | [ "$DEBUG" == 'true' ] && set -x 11 | set -e 12 | 13 | # Get reference for all important folders 14 | template_dir="$PWD" 15 | source_dir="$(cd $template_dir/../source; pwd -P)" 16 | root_dir="$template_dir/.." 17 | 18 | echo "------------------------------------------------------------------------------" 19 | echo "[Init] Clean old folders" 20 | echo "------------------------------------------------------------------------------" 21 | 22 | cd $root_dir 23 | if [ -d ".venv" ]; then 24 | rm -rf ".venv" 25 | fi 26 | 27 | echo "------------------------------------------------------------------------------" 28 | echo "[Env] Create virtual environment and install dependencies" 29 | echo "------------------------------------------------------------------------------" 30 | 31 | virtualenv .venv 32 | source .venv/bin/activate 33 | 34 | cd $source_dir 35 | pip install -r $source_dir/requirements-build-and-test.txt 36 | cd - 37 | 38 | echo "------------------------------------------------------------------------------" 39 | echo "[Test] Run pytest with coverage" 40 | echo "------------------------------------------------------------------------------" 41 | cd $source_dir 42 | # setup coverage report path 43 | coverage_report_path=$source_dir/tests/coverage-reports/source.coverage.xml 44 | echo "coverage report path set to $coverage_report_path" 45 | 46 | pytest --cov --cov-report=term-missing --cov-report "xml:$coverage_report_path" 47 | 48 | # The pytest --cov with its parameters and .coveragerc generates a xml cov-report with `coverage/sources` list 49 | # with absolute path for the source directories. To avoid dependencies of tools (such as SonarQube) on different 50 | # absolute paths for source directories, this substitution is used to convert each absolute source directory 51 | # path to the corresponding project relative path. The $source_dir holds the absolute path for source directory. 52 | sed -i -e "s,$source_dir,source,g" $coverage_report_path 53 | 54 | # deactivate the virtual environment 55 | deactivate 56 | 57 | cd $template_dir 58 | 59 | -------------------------------------------------------------------------------- /source/.coveragerc: -------------------------------------------------------------------------------- 1 | [run] 2 | omit = 3 | images/* 4 | tests/* 5 | forecast-shared/shared/quicksight_custom_resources/* 6 | source = 7 | shared 8 | lambdas 9 | notebook 10 | synthetic 11 | 12 | [report] 13 | omit = 14 | forecast-shared/shared/quicksight_custom_resources/* 15 | fail_under = 80.0 -------------------------------------------------------------------------------- /source/.gitignore: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /source/cdk_solution_helper_py/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Change Log 2 | All notable changes to this project will be documented in this file. 3 | 4 | The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), 5 | and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). 6 | 7 | ## [1.0.0] - 2021-09-23 8 | ### Added 9 | - initial release 10 | 11 | -------------------------------------------------------------------------------- /source/cdk_solution_helper_py/helpers_cdk/aws_solutions/__init__.py: -------------------------------------------------------------------------------- 1 | # ##################################################################################################################### 2 | # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. # 3 | # # 4 | # Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance # 5 | # with the License. You may obtain a copy of the License at # 6 | # # 7 | # http://www.apache.org/licenses/LICENSE-2.0 # 8 | # # 9 | # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed # 10 | # on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for # 11 | # the specific language governing permissions and limitations under the License. # 12 | # ##################################################################################################################### 13 | -------------------------------------------------------------------------------- /source/cdk_solution_helper_py/helpers_cdk/aws_solutions/cdk/aspects.py: -------------------------------------------------------------------------------- 1 | # ##################################################################################################################### 2 | # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. # 3 | # # 4 | # Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance # 5 | # with the License. You may obtain a copy of the License at # 6 | # # 7 | # http://www.apache.org/licenses/LICENSE-2.0 # 8 | # # 9 | # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed # 10 | # on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for # 11 | # the specific language governing permissions and limitations under the License. # 12 | # ##################################################################################################################### 13 | import jsii 14 | from constructs import IConstruct 15 | from aws_cdk import CfnCondition, IAspect 16 | 17 | @jsii.implements(IAspect) 18 | class ConditionalResources: 19 | """Mark any CDK construct as conditional (this is useful to apply to stacks and L2+ constructs)""" 20 | 21 | def __init__(self, condition: CfnCondition): 22 | self.condition = condition 23 | 24 | def visit(self, node: IConstruct): 25 | if "is_cfn_element" in dir(node) and node.is_cfn_element(node): 26 | node.cfn_options.condition = self.condition 27 | elif "is_cfn_element" in dir(node.node.default_child): 28 | node.node.default_child.cfn_options.condition = self.condition 29 | -------------------------------------------------------------------------------- /source/cdk_solution_helper_py/helpers_cdk/aws_solutions/cdk/aws_lambda/__init__.py: -------------------------------------------------------------------------------- 1 | # ##################################################################################################################### 2 | # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. # 3 | # # 4 | # Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance # 5 | # with the License. You may obtain a copy of the License at # 6 | # # 7 | # http://www.apache.org/licenses/LICENSE-2.0 # 8 | # # 9 | # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed # 10 | # on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for # 11 | # the specific language governing permissions and limitations under the License. # 12 | # ##################################################################################################################### 13 | -------------------------------------------------------------------------------- /source/cdk_solution_helper_py/helpers_cdk/aws_solutions/cdk/aws_lambda/cfn_custom_resources/__init__.py: -------------------------------------------------------------------------------- 1 | # ##################################################################################################################### 2 | # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. # 3 | # # 4 | # Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance # 5 | # with the License. You may obtain a copy of the License at # 6 | # # 7 | # http://www.apache.org/licenses/LICENSE-2.0 # 8 | # # 9 | # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed # 10 | # on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for # 11 | # the specific language governing permissions and limitations under the License. # 12 | # ##################################################################################################################### 13 | -------------------------------------------------------------------------------- /source/cdk_solution_helper_py/helpers_cdk/aws_solutions/cdk/aws_lambda/cfn_custom_resources/resource_hash/__init__.py: -------------------------------------------------------------------------------- 1 | # ##################################################################################################################### 2 | # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. # 3 | # # 4 | # Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance # 5 | # with the License. You may obtain a copy of the License at # 6 | # # 7 | # http://www.apache.org/licenses/LICENSE-2.0 # 8 | # # 9 | # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed # 10 | # on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for # 11 | # the specific language governing permissions and limitations under the License. # 12 | # ##################################################################################################################### 13 | 14 | from aws_solutions.cdk.aws_lambda.cfn_custom_resources.resource_hash.hash import ( 15 | ResourceHash, 16 | ) 17 | -------------------------------------------------------------------------------- /source/cdk_solution_helper_py/helpers_cdk/aws_solutions/cdk/aws_lambda/cfn_custom_resources/resource_hash/src/__init__.py: -------------------------------------------------------------------------------- 1 | # ##################################################################################################################### 2 | # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. # 3 | # # 4 | # Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance # 5 | # with the License. You may obtain a copy of the License at # 6 | # # 7 | # http://www.apache.org/licenses/LICENSE-2.0 # 8 | # # 9 | # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed # 10 | # on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for # 11 | # the specific language governing permissions and limitations under the License. # 12 | # ##################################################################################################################### 13 | -------------------------------------------------------------------------------- /source/cdk_solution_helper_py/helpers_cdk/aws_solutions/cdk/aws_lambda/cfn_custom_resources/resource_hash/src/custom_resources/__init__.py: -------------------------------------------------------------------------------- 1 | # ##################################################################################################################### 2 | # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. # 3 | # # 4 | # Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance # 5 | # with the License. You may obtain a copy of the License at # 6 | # # 7 | # http://www.apache.org/licenses/LICENSE-2.0 # 8 | # # 9 | # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed # 10 | # on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for # 11 | # the specific language governing permissions and limitations under the License. # 12 | # ##################################################################################################################### 13 | -------------------------------------------------------------------------------- /source/cdk_solution_helper_py/helpers_cdk/aws_solutions/cdk/aws_lambda/cfn_custom_resources/resource_hash/src/custom_resources/requirements.txt: -------------------------------------------------------------------------------- 1 | crhelper==2.0.11 -------------------------------------------------------------------------------- /source/cdk_solution_helper_py/helpers_cdk/aws_solutions/cdk/aws_lambda/cfn_custom_resources/resource_name/__init__.py: -------------------------------------------------------------------------------- 1 | # ##################################################################################################################### 2 | # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. # 3 | # # 4 | # Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance # 5 | # with the License. You may obtain a copy of the License at # 6 | # # 7 | # http://www.apache.org/licenses/LICENSE-2.0 # 8 | # # 9 | # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed # 10 | # on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for # 11 | # the specific language governing permissions and limitations under the License. # 12 | # ##################################################################################################################### 13 | 14 | from aws_solutions.cdk.aws_lambda.cfn_custom_resources.resource_name.name import ( 15 | ResourceName, 16 | ) 17 | -------------------------------------------------------------------------------- /source/cdk_solution_helper_py/helpers_cdk/aws_solutions/cdk/aws_lambda/cfn_custom_resources/resource_name/src/__init__.py: -------------------------------------------------------------------------------- 1 | # ##################################################################################################################### 2 | # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. # 3 | # # 4 | # Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance # 5 | # with the License. You may obtain a copy of the License at # 6 | # # 7 | # http://www.apache.org/licenses/LICENSE-2.0 # 8 | # # 9 | # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed # 10 | # on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for # 11 | # the specific language governing permissions and limitations under the License. # 12 | # ##################################################################################################################### 13 | -------------------------------------------------------------------------------- /source/cdk_solution_helper_py/helpers_cdk/aws_solutions/cdk/aws_lambda/cfn_custom_resources/resource_name/src/custom_resources/__init__.py: -------------------------------------------------------------------------------- 1 | # ##################################################################################################################### 2 | # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. # 3 | # # 4 | # Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance # 5 | # with the License. You may obtain a copy of the License at # 6 | # # 7 | # http://www.apache.org/licenses/LICENSE-2.0 # 8 | # # 9 | # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed # 10 | # on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for # 11 | # the specific language governing permissions and limitations under the License. # 12 | # ##################################################################################################################### 13 | -------------------------------------------------------------------------------- /source/cdk_solution_helper_py/helpers_cdk/aws_solutions/cdk/aws_lambda/cfn_custom_resources/resource_name/src/custom_resources/requirements.txt: -------------------------------------------------------------------------------- 1 | crhelper==2.0.11 -------------------------------------------------------------------------------- /source/cdk_solution_helper_py/helpers_cdk/aws_solutions/cdk/aws_lambda/cfn_custom_resources/solutions_metrics/__init__.py: -------------------------------------------------------------------------------- 1 | # ##################################################################################################################### 2 | # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. # 3 | # # 4 | # Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance # 5 | # with the License. You may obtain a copy of the License at # 6 | # # 7 | # http://www.apache.org/licenses/LICENSE-2.0 # 8 | # # 9 | # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed # 10 | # on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for # 11 | # the specific language governing permissions and limitations under the License. # 12 | # ##################################################################################################################### 13 | 14 | from aws_solutions.cdk.aws_lambda.cfn_custom_resources.solutions_metrics.metrics import ( 15 | Metrics, 16 | ) 17 | -------------------------------------------------------------------------------- /source/cdk_solution_helper_py/helpers_cdk/aws_solutions/cdk/aws_lambda/cfn_custom_resources/solutions_metrics/src/__init__.py: -------------------------------------------------------------------------------- 1 | # ##################################################################################################################### 2 | # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. # 3 | # # 4 | # Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance # 5 | # with the License. You may obtain a copy of the License at # 6 | # # 7 | # http://www.apache.org/licenses/LICENSE-2.0 # 8 | # # 9 | # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed # 10 | # on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for # 11 | # the specific language governing permissions and limitations under the License. # 12 | # ##################################################################################################################### 13 | -------------------------------------------------------------------------------- /source/cdk_solution_helper_py/helpers_cdk/aws_solutions/cdk/aws_lambda/cfn_custom_resources/solutions_metrics/src/custom_resources/__init__.py: -------------------------------------------------------------------------------- 1 | # ##################################################################################################################### 2 | # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. # 3 | # # 4 | # Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance # 5 | # with the License. You may obtain a copy of the License at # 6 | # # 7 | # http://www.apache.org/licenses/LICENSE-2.0 # 8 | # # 9 | # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed # 10 | # on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for # 11 | # the specific language governing permissions and limitations under the License. # 12 | # ##################################################################################################################### 13 | -------------------------------------------------------------------------------- /source/cdk_solution_helper_py/helpers_cdk/aws_solutions/cdk/aws_lambda/cfn_custom_resources/solutions_metrics/src/custom_resources/requirements.txt: -------------------------------------------------------------------------------- 1 | crhelper==2.0.11 2 | urllib3==1.26.18 3 | requests==2.31.0 -------------------------------------------------------------------------------- /source/cdk_solution_helper_py/helpers_cdk/aws_solutions/cdk/aws_lambda/cfn_custom_resources/url_downloader/__init__.py: -------------------------------------------------------------------------------- 1 | # ##################################################################################################################### 2 | # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. # 3 | # # 4 | # Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance # 5 | # with the License. You may obtain a copy of the License at # 6 | # # 7 | # http://www.apache.org/licenses/LICENSE-2.0 # 8 | # # 9 | # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed # 10 | # on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for # 11 | # the specific language governing permissions and limitations under the License. # 12 | # ##################################################################################################################### 13 | 14 | from aws_solutions.cdk.aws_lambda.cfn_custom_resources.url_downloader.url_downloader import ( 15 | UrlDownloader, 16 | ) 17 | -------------------------------------------------------------------------------- /source/cdk_solution_helper_py/helpers_cdk/aws_solutions/cdk/aws_lambda/cfn_custom_resources/url_downloader/src/__init__.py: -------------------------------------------------------------------------------- 1 | # ##################################################################################################################### 2 | # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. # 3 | # # 4 | # Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance # 5 | # with the License. You may obtain a copy of the License at # 6 | # # 7 | # http://www.apache.org/licenses/LICENSE-2.0 # 8 | # # 9 | # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed # 10 | # on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for # 11 | # the specific language governing permissions and limitations under the License. # 12 | # ##################################################################################################################### 13 | -------------------------------------------------------------------------------- /source/cdk_solution_helper_py/helpers_cdk/aws_solutions/cdk/aws_lambda/cfn_custom_resources/url_downloader/src/custom_resources/__init__.py: -------------------------------------------------------------------------------- 1 | # ##################################################################################################################### 2 | # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. # 3 | # # 4 | # Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance # 5 | # with the License. You may obtain a copy of the License at # 6 | # # 7 | # http://www.apache.org/licenses/LICENSE-2.0 # 8 | # # 9 | # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed # 10 | # on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for # 11 | # the specific language governing permissions and limitations under the License. # 12 | # ##################################################################################################################### 13 | -------------------------------------------------------------------------------- /source/cdk_solution_helper_py/helpers_cdk/aws_solutions/cdk/aws_lambda/cfn_custom_resources/url_downloader/src/custom_resources/requirements.txt: -------------------------------------------------------------------------------- 1 | crhelper==2.0.11 -------------------------------------------------------------------------------- /source/cdk_solution_helper_py/helpers_cdk/aws_solutions/cdk/aws_lambda/cfn_custom_resources/url_helper/__init__.py: -------------------------------------------------------------------------------- 1 | # ##################################################################################################################### 2 | # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. # 3 | # # 4 | # Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance # 5 | # with the License. You may obtain a copy of the License at # 6 | # # 7 | # http://www.apache.org/licenses/LICENSE-2.0 # 8 | # # 9 | # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed # 10 | # on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for # 11 | # the specific language governing permissions and limitations under the License. # 12 | # ##################################################################################################################### 13 | 14 | from aws_solutions.cdk.aws_lambda.cfn_custom_resources.url_helper.url_helper import ( 15 | UrlHelper, 16 | ) 17 | -------------------------------------------------------------------------------- /source/cdk_solution_helper_py/helpers_cdk/aws_solutions/cdk/aws_lambda/cfn_custom_resources/url_helper/src/__init__.py: -------------------------------------------------------------------------------- 1 | # ##################################################################################################################### 2 | # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. # 3 | # # 4 | # Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance # 5 | # with the License. You may obtain a copy of the License at # 6 | # # 7 | # http://www.apache.org/licenses/LICENSE-2.0 # 8 | # # 9 | # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed # 10 | # on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for # 11 | # the specific language governing permissions and limitations under the License. # 12 | # ##################################################################################################################### 13 | -------------------------------------------------------------------------------- /source/cdk_solution_helper_py/helpers_cdk/aws_solutions/cdk/aws_lambda/cfn_custom_resources/url_helper/src/custom_resources/__init__.py: -------------------------------------------------------------------------------- 1 | # ##################################################################################################################### 2 | # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. # 3 | # # 4 | # Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance # 5 | # with the License. You may obtain a copy of the License at # 6 | # # 7 | # http://www.apache.org/licenses/LICENSE-2.0 # 8 | # # 9 | # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed # 10 | # on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for # 11 | # the specific language governing permissions and limitations under the License. # 12 | # ##################################################################################################################### 13 | -------------------------------------------------------------------------------- /source/cdk_solution_helper_py/helpers_cdk/aws_solutions/cdk/aws_lambda/cfn_custom_resources/url_helper/src/custom_resources/requirements.txt: -------------------------------------------------------------------------------- 1 | crhelper==2.0.11 -------------------------------------------------------------------------------- /source/cdk_solution_helper_py/helpers_cdk/aws_solutions/cdk/aws_lambda/environment_variable.py: -------------------------------------------------------------------------------- 1 | # ###################################################################################################################### 2 | # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. # 3 | # # 4 | # Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance # 5 | # with the License. You may obtain a copy of the License at # 6 | # # 7 | # http://www.apache.org/licenses/LICENSE-2.0 # 8 | # # 9 | # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed # 10 | # on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for # 11 | # the specific language governing permissions and limitations under the License. # 12 | # ###################################################################################################################### 13 | 14 | from dataclasses import dataclass, field 15 | 16 | from aws_cdk.aws_lambda import IFunction 17 | 18 | @dataclass 19 | class EnvironmentVariable: 20 | scope: IFunction 21 | name: str 22 | value: str = field(default="") 23 | 24 | def __post_init__(self): 25 | if not self.value: 26 | self.value = self.scope.node.try_get_context(self.name) 27 | self.scope.add_environment(self.name, self.value) 28 | 29 | def __str__(self): 30 | return self.value 31 | -------------------------------------------------------------------------------- /source/cdk_solution_helper_py/helpers_cdk/aws_solutions/cdk/aws_lambda/java/__init__.py: -------------------------------------------------------------------------------- 1 | # ##################################################################################################################### 2 | # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. # 3 | # # 4 | # Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance # 5 | # with the License. You may obtain a copy of the License at # 6 | # # 7 | # http://www.apache.org/licenses/LICENSE-2.0 # 8 | # # 9 | # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed # 10 | # on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for # 11 | # the specific language governing permissions and limitations under the License. # 12 | # ##################################################################################################################### 13 | -------------------------------------------------------------------------------- /source/cdk_solution_helper_py/helpers_cdk/aws_solutions/cdk/aws_lambda/layers/__init__.py: -------------------------------------------------------------------------------- 1 | # ###################################################################################################################### 2 | # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. # 3 | # # 4 | # Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance # 5 | # with the License. You may obtain a copy of the License at # 6 | # # 7 | # http://www.apache.org/licenses/LICENSE-2.0 # 8 | # # 9 | # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed # 10 | # on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for # 11 | # the specific language governing permissions and limitations under the License. # 12 | # ###################################################################################################################### 13 | -------------------------------------------------------------------------------- /source/cdk_solution_helper_py/helpers_cdk/aws_solutions/cdk/aws_lambda/layers/aws_lambda_powertools/__init__.py: -------------------------------------------------------------------------------- 1 | # ###################################################################################################################### 2 | # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. # 3 | # # 4 | # Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance # 5 | # with the License. You may obtain a copy of the License at # 6 | # # 7 | # http://www.apache.org/licenses/LICENSE-2.0 # 8 | # # 9 | # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed # 10 | # on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for # 11 | # the specific language governing permissions and limitations under the License. # 12 | # ###################################################################################################################### 13 | 14 | from aws_solutions.cdk.aws_lambda.layers.aws_lambda_powertools.layer import ( 15 | PowertoolsLayer, 16 | ) 17 | -------------------------------------------------------------------------------- /source/cdk_solution_helper_py/helpers_cdk/aws_solutions/cdk/aws_lambda/layers/aws_lambda_powertools/layer.py: -------------------------------------------------------------------------------- 1 | # ###################################################################################################################### 2 | # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. # 3 | # # 4 | # Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance # 5 | # with the License. You may obtain a copy of the License at # 6 | # # 7 | # http://www.apache.org/licenses/LICENSE-2.0 # 8 | # # 9 | # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed # 10 | # on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for # 11 | # the specific language governing permissions and limitations under the License. # 12 | # ###################################################################################################################### 13 | 14 | from pathlib import Path 15 | from constructs import Construct 16 | from aws_cdk import Stack 17 | from aws_solutions.cdk.aws_lambda.python.layer import SolutionsPythonLayerVersion 18 | 19 | class PowertoolsLayer(SolutionsPythonLayerVersion): 20 | def __init__(self, scope: Construct, construct_id: str, **kwargs): 21 | requirements_path: Path = Path(__file__).absolute().parent / "requirements" 22 | super().__init__(scope, construct_id, requirements_path, **kwargs) 23 | 24 | @staticmethod 25 | def get_or_create(scope: Construct, **kwargs): 26 | stack = Stack.of(scope) 27 | construct_id = "PowertoolsLayer-8E932F0F-197D-4026-A354-23D184C2A624" 28 | exists = stack.node.try_find_child(construct_id) 29 | if exists: 30 | return exists 31 | return PowertoolsLayer(stack, construct_id, **kwargs) 32 | -------------------------------------------------------------------------------- /source/cdk_solution_helper_py/helpers_cdk/aws_solutions/cdk/aws_lambda/layers/aws_lambda_powertools/requirements/requirements.txt: -------------------------------------------------------------------------------- 1 | aws-lambda-powertools==2.22.0 -------------------------------------------------------------------------------- /source/cdk_solution_helper_py/helpers_cdk/aws_solutions/cdk/aws_lambda/python/__init__.py: -------------------------------------------------------------------------------- 1 | # ##################################################################################################################### 2 | # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. # 3 | # # 4 | # Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance # 5 | # with the License. You may obtain a copy of the License at # 6 | # # 7 | # http://www.apache.org/licenses/LICENSE-2.0 # 8 | # # 9 | # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed # 10 | # on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for # 11 | # the specific language governing permissions and limitations under the License. # 12 | # ##################################################################################################################### 13 | -------------------------------------------------------------------------------- /source/cdk_solution_helper_py/helpers_cdk/aws_solutions/cdk/helpers/__init__.py: -------------------------------------------------------------------------------- 1 | # ##################################################################################################################### 2 | # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. # 3 | # # 4 | # Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance # 5 | # with the License. You may obtain a copy of the License at # 6 | # # 7 | # http://www.apache.org/licenses/LICENSE-2.0 # 8 | # # 9 | # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed # 10 | # on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for # 11 | # the specific language governing permissions and limitations under the License. # 12 | # ##################################################################################################################### 13 | 14 | from aws_solutions.cdk.helpers.copytree import copytree, ignore_globs 15 | -------------------------------------------------------------------------------- /source/cdk_solution_helper_py/helpers_cdk/aws_solutions/cdk/helpers/logger.py: -------------------------------------------------------------------------------- 1 | # ##################################################################################################################### 2 | # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. # 3 | # # 4 | # Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance # 5 | # with the License. You may obtain a copy of the License at # 6 | # # 7 | # http://www.apache.org/licenses/LICENSE-2.0 # 8 | # # 9 | # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed # 10 | # on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for # 11 | # the specific language governing permissions and limitations under the License. # 12 | # ##################################################################################################################### 13 | 14 | import logging 15 | 16 | 17 | class Logger: 18 | """Set up a logger fo this package""" 19 | 20 | @classmethod 21 | def get_logger(cls, name: str) -> logging.Logger: 22 | """ 23 | Gets the current logger for this package 24 | :param name: the name of the logger 25 | :return: the logger 26 | """ 27 | logger = logging.getLogger(name) 28 | if not len(logger.handlers): 29 | logger.setLevel(logging.INFO) 30 | handler = logging.StreamHandler() 31 | formatter = logging.Formatter("[%(levelname)s]\t%(name)s\t%(message)s") 32 | handler.setFormatter(formatter) 33 | logger.addHandler(handler) 34 | logger.propagate = False 35 | return logger 36 | -------------------------------------------------------------------------------- /source/cdk_solution_helper_py/helpers_cdk/aws_solutions/cdk/scripts/__init__.py: -------------------------------------------------------------------------------- 1 | # ##################################################################################################################### 2 | # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. # 3 | # # 4 | # Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance # 5 | # with the License. You may obtain a copy of the License at # 6 | # # 7 | # http://www.apache.org/licenses/LICENSE-2.0 # 8 | # # 9 | # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed # 10 | # on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for # 11 | # the specific language governing permissions and limitations under the License. # 12 | # ##################################################################################################################### 13 | -------------------------------------------------------------------------------- /source/cdk_solution_helper_py/helpers_cdk/aws_solutions/cdk/stepfunctions/__init__.py: -------------------------------------------------------------------------------- 1 | # ###################################################################################################################### 2 | # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. # 3 | # # 4 | # Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance # 5 | # with the License. You may obtain a copy of the License at # 6 | # # 7 | # http://www.apache.org/licenses/LICENSE-2.0 # 8 | # # 9 | # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed # 10 | # on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for # 11 | # the specific language governing permissions and limitations under the License. # 12 | # ###################################################################################################################### 13 | -------------------------------------------------------------------------------- /source/cdk_solution_helper_py/helpers_cdk/aws_solutions/cdk/tools/__init__.py: -------------------------------------------------------------------------------- 1 | # ##################################################################################################################### 2 | # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. # 3 | # # 4 | # Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance # 5 | # with the License. You may obtain a copy of the License at # 6 | # # 7 | # http://www.apache.org/licenses/LICENSE-2.0 # 8 | # # 9 | # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed # 10 | # on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for # 11 | # the specific language governing permissions and limitations under the License. # 12 | # ##################################################################################################################### 13 | 14 | from aws_solutions.cdk.tools.cleaner import Cleaner 15 | -------------------------------------------------------------------------------- /source/cdk_solution_helper_py/helpers_cdk/aws_solutions/cdk/utils/__init__.py: -------------------------------------------------------------------------------- 1 | # ##################################################################################################################### 2 | # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. # 3 | # # 4 | # Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance # 5 | # with the License. You may obtain a copy of the License at # 6 | # # 7 | # http://www.apache.org/licenses/LICENSE-2.0 # 8 | # # 9 | # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed # 10 | # on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for # 11 | # the specific language governing permissions and limitations under the License. # 12 | # ##################################################################################################################### 13 | 14 | from aws_solutions.cdk.utils.is_solution_build import is_solution_build 15 | -------------------------------------------------------------------------------- /source/cdk_solution_helper_py/helpers_cdk/aws_solutions/cdk/utils/is_solution_build.py: -------------------------------------------------------------------------------- 1 | # ##################################################################################################################### 2 | # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. # 3 | # # 4 | # Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance # 5 | # with the License. You may obtain a copy of the License at # 6 | # # 7 | # http://www.apache.org/licenses/LICENSE-2.0 # 8 | # # 9 | # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed # 10 | # on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for # 11 | # the specific language governing permissions and limitations under the License. # 12 | # ##################################################################################################################### 13 | 14 | from constructs import Construct 15 | 16 | def is_solution_build(construct: Construct): 17 | """Detect if this is being run from build-s3-dist.py and should package assets accordingly""" 18 | solutions_assets_regional = construct.node.try_get_context( 19 | "SOLUTIONS_ASSETS_REGIONAL" 20 | ) 21 | solutions_assets_global = construct.node.try_get_context("SOLUTIONS_ASSETS_GLOBAL") 22 | return solutions_assets_regional and solutions_assets_global 23 | -------------------------------------------------------------------------------- /source/cdk_solution_helper_py/helpers_common/aws_solutions/core/__init__.py: -------------------------------------------------------------------------------- 1 | # ##################################################################################################################### 2 | # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. # 3 | # # 4 | # Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance # 5 | # with the License. You may obtain a copy of the License at # 6 | # # 7 | # http://www.apache.org/licenses/LICENSE-2.0 # 8 | # # 9 | # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed # 10 | # on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for # 11 | # the specific language governing permissions and limitations under the License. # 12 | # ##################################################################################################################### 13 | 14 | from aws_solutions.core.config import Config 15 | 16 | config = Config() 17 | 18 | from aws_solutions.core.helpers import ( 19 | get_aws_region, 20 | get_aws_partition, 21 | get_service_client, 22 | get_service_resource, 23 | get_aws_account, 24 | ) 25 | -------------------------------------------------------------------------------- /source/cdk_solution_helper_py/requirements-dev.txt: -------------------------------------------------------------------------------- 1 | aws_cdk_lib==2.88.0 2 | aws-cdk.aws-servicecatalogappregistry-alpha==2.88.0a0 3 | aws_solutions_constructs.aws_lambda_sns==2.41.0 4 | # aws-solutions-python>=2.0.0 5 | black 6 | boto3==1.26.83 7 | requests==2.31.0 8 | crhelper==2.0.11 9 | Click 10 | moto 11 | pipenv 12 | poetry 13 | pytest 14 | pytest-cov>=2.11.1 15 | pytest-mock>=3.5.1 16 | tox 17 | tox-pyenv 18 | -e helpers_cdk 19 | -e helpers_common -------------------------------------------------------------------------------- /source/example/1-defaults/forecast-defaults.yaml: -------------------------------------------------------------------------------- 1 | Default: 2 | DatasetGroup: 3 | Domain: RETAIL 4 | 5 | Datasets: 6 | - Domain: RETAIL 7 | DatasetType: TARGET_TIME_SERIES 8 | DataFrequency: D 9 | TimestampFormat: yyyy-MM-dd 10 | Schema: 11 | Attributes: 12 | - AttributeName: item_id 13 | AttributeType: string 14 | - AttributeName: timestamp 15 | AttributeType: timestamp 16 | - AttributeName: demand 17 | AttributeType: float 18 | 19 | Predictor: 20 | MaxAge: 604800 # one week 21 | PerformAutoML: True 22 | ForecastHorizon: 30 23 | FeaturizationConfig: 24 | ForecastFrequency: D 25 | 26 | Forecast: 27 | ForecastTypes: 28 | - "0.01" 29 | - "0.50" 30 | - "0.99" -------------------------------------------------------------------------------- /source/example/data/demand.metadata.csv: -------------------------------------------------------------------------------- 1 | item_000,category_a,brand_a -------------------------------------------------------------------------------- /source/forecast-shared/setup.py: -------------------------------------------------------------------------------- 1 | # ##################################################################################################################### 2 | # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. # 3 | # # 4 | # Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance # 5 | # with the License. You may obtain a copy of the License at # 6 | # # 7 | # http://www.apache.org/licenses/LICENSE-2.0 # 8 | # # 9 | # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed # 10 | # on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for # 11 | # the specific language governing permissions and limitations under the License. # 12 | # ##################################################################################################################### 13 | 14 | 15 | import setuptools 16 | 17 | 18 | setuptools.setup( 19 | name="shared", 20 | version="1.4.0", 21 | description="Improving Forecast Accuracy with Machine Learhing - Shared Solution Components", 22 | author="AWS Solutions Builders", 23 | packages=setuptools.find_packages(), 24 | package_data={"": ["*.json", "*.yaml"]}, 25 | include_package_data=True, 26 | python_requires=">=3.7", 27 | classifiers=[ 28 | "Development Status :: 4 - Beta", 29 | "Intended Audience :: Developers", 30 | "License :: OSI Approved :: Apache Software License", 31 | "Programming Language :: JavaScript", 32 | "Programming Language :: Python :: 3 :: Only", 33 | "Programming Language :: Python :: 3.7", 34 | "Programming Language :: Python :: 3.8", 35 | "Programming Language :: Python :: 3.9", 36 | "Topic :: Software Development :: Code Generators", 37 | "Topic :: Utilities", 38 | "Typing :: Typed", 39 | ], 40 | ) 41 | -------------------------------------------------------------------------------- /source/forecast-shared/shared/Dataset/__init__.py: -------------------------------------------------------------------------------- 1 | # ##################################################################################################################### 2 | # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. # 3 | # # 4 | # Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance # 5 | # with the License. You may obtain a copy of the License at # 6 | # # 7 | # http://www.apache.org/licenses/LICENSE-2.0 # 8 | # # 9 | # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed # 10 | # on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for # 11 | # the specific language governing permissions and limitations under the License. # 12 | # ##################################################################################################################### 13 | -------------------------------------------------------------------------------- /source/forecast-shared/shared/Dataset/data_timestamp_format.py: -------------------------------------------------------------------------------- 1 | # ##################################################################################################################### 2 | # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. # 3 | # # 4 | # Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance # 5 | # with the License. You may obtain a copy of the License at # 6 | # # 7 | # http://www.apache.org/licenses/LICENSE-2.0 # 8 | # # 9 | # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed # 10 | # on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for # 11 | # the specific language governing permissions and limitations under the License. # 12 | # ##################################################################################################################### 13 | 14 | import re 15 | 16 | 17 | class DataTimestampFormat: 18 | """Used to validate data timestamp formats provided in configuration files.""" 19 | 20 | valid_format = re.compile(r"^(?:yyyy-MM-dd|yyyy-MM-dd HH:mm:ss)$") 21 | 22 | def __init__(self, format): 23 | if not self.valid_format.match(format): 24 | raise ValueError( 25 | f"Invalid timestamp format. Format {format} does not match {self.valid_format.pattern}" 26 | ) 27 | self.format = format 28 | 29 | def __str__(self) -> str: 30 | return self.format 31 | 32 | def __repr__(self) -> str: 33 | return f"DataTimestampFormat(format='{self.format}')" 34 | 35 | def __eq__(self, other): 36 | return self.format == other 37 | -------------------------------------------------------------------------------- /source/forecast-shared/shared/Dataset/dataset_domain.py: -------------------------------------------------------------------------------- 1 | # ##################################################################################################################### 2 | # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. # 3 | # # 4 | # Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance # 5 | # with the License. You may obtain a copy of the License at # 6 | # # 7 | # http://www.apache.org/licenses/LICENSE-2.0 # 8 | # # 9 | # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed # 10 | # on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for # 11 | # the specific language governing permissions and limitations under the License. # 12 | # ##################################################################################################################### 13 | 14 | from enum import Enum, auto 15 | 16 | 17 | class DatasetDomain(Enum): 18 | """Used to validate dataset domains provided in configuration files""" 19 | 20 | RETAIL = auto() 21 | CUSTOM = auto() 22 | INVENTORY_PLANNING = auto() 23 | EC2_CAPACITY = auto() 24 | WORK_FORCE = auto() 25 | WEB_TRAFFIC = auto() 26 | METRICS = auto() 27 | 28 | def __str__(self) -> str: 29 | return self.name 30 | 31 | def __eq__(self, other): 32 | return self.name == other 33 | -------------------------------------------------------------------------------- /source/forecast-shared/shared/Dataset/dataset_type.py: -------------------------------------------------------------------------------- 1 | # ##################################################################################################################### 2 | # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. # 3 | # # 4 | # Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance # 5 | # with the License. You may obtain a copy of the License at # 6 | # # 7 | # http://www.apache.org/licenses/LICENSE-2.0 # 8 | # # 9 | # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed # 10 | # on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for # 11 | # the specific language governing permissions and limitations under the License. # 12 | # ##################################################################################################################### 13 | 14 | from enum import Enum, auto 15 | 16 | 17 | class DatasetType(Enum): 18 | """Used to validate dataset types provided in configuration files""" 19 | 20 | TARGET_TIME_SERIES = auto() 21 | RELATED_TIME_SERIES = auto() 22 | ITEM_METADATA = auto() 23 | 24 | def __str__(self): 25 | return self.name 26 | 27 | def __eq__(self, other): 28 | return self.name == other 29 | 30 | @property 31 | def suffix(self): 32 | if self.name == self.TARGET_TIME_SERIES: 33 | return ".csv" 34 | elif self.name == self.RELATED_TIME_SERIES: 35 | return ".related.csv" 36 | elif self.name == self.ITEM_METADATA: 37 | return ".metadata.csv" 38 | else: 39 | raise ValueError("Invalid Dataset Type") 40 | -------------------------------------------------------------------------------- /source/forecast-shared/shared/DatasetGroup/__init__.py: -------------------------------------------------------------------------------- 1 | # ##################################################################################################################### 2 | # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. # 3 | # # 4 | # Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance # 5 | # with the License. You may obtain a copy of the License at # 6 | # # 7 | # http://www.apache.org/licenses/LICENSE-2.0 # 8 | # # 9 | # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed # 10 | # on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for # 11 | # the specific language governing permissions and limitations under the License. # 12 | # ##################################################################################################################### 13 | -------------------------------------------------------------------------------- /source/forecast-shared/shared/Forecast/__init__.py: -------------------------------------------------------------------------------- 1 | # ##################################################################################################################### 2 | # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. # 3 | # # 4 | # Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance # 5 | # with the License. You may obtain a copy of the License at # 6 | # # 7 | # http://www.apache.org/licenses/LICENSE-2.0 # 8 | # # 9 | # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed # 10 | # on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for # 11 | # the specific language governing permissions and limitations under the License. # 12 | # ##################################################################################################################### 13 | -------------------------------------------------------------------------------- /source/forecast-shared/shared/Predictor/__init__.py: -------------------------------------------------------------------------------- 1 | # ##################################################################################################################### 2 | # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. # 3 | # # 4 | # Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance # 5 | # with the License. You may obtain a copy of the License at # 6 | # # 7 | # http://www.apache.org/licenses/LICENSE-2.0 # 8 | # # 9 | # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed # 10 | # on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for # 11 | # the specific language governing permissions and limitations under the License. # 12 | # ##################################################################################################################### 13 | -------------------------------------------------------------------------------- /source/forecast-shared/shared/Predictor/auto_predictor.py: -------------------------------------------------------------------------------- 1 | # ##################################################################################################################### 2 | # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. # 3 | # # 4 | # Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance # 5 | # with the License. You may obtain a copy of the License at # 6 | # # 7 | # http://www.apache.org/licenses/LICENSE-2.0 # 8 | # # 9 | # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed # 10 | # on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for # 11 | # the specific language governing permissions and limitations under the License. # 12 | # ##################################################################################################################### 13 | from shared.Dataset.dataset_file import DatasetFile 14 | from shared.DatasetGroup.dataset_group import DatasetGroup 15 | from shared.Predictor.predictor import Predictor 16 | 17 | 18 | class AutoPredictor(Predictor): 19 | is_auto_predictor = True 20 | 21 | def __init__( 22 | self, dataset_file: DatasetFile, dataset_group: DatasetGroup, **predictor_config 23 | ): 24 | super().__init__(dataset_file, dataset_group, **predictor_config) 25 | -------------------------------------------------------------------------------- /source/forecast-shared/shared/Tags/__init__.py: -------------------------------------------------------------------------------- 1 | # ##################################################################################################################### 2 | # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. # 3 | # # 4 | # Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance # 5 | # with the License. You may obtain a copy of the License at # 6 | # # 7 | # http://www.apache.org/licenses/LICENSE-2.0 # 8 | # # 9 | # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed # 10 | # on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for # 11 | # the specific language governing permissions and limitations under the License. # 12 | # ##################################################################################################################### 13 | -------------------------------------------------------------------------------- /source/forecast-shared/shared/__init__.py: -------------------------------------------------------------------------------- 1 | # ##################################################################################################################### 2 | # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. # 3 | # # 4 | # Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance # 5 | # with the License. You may obtain a copy of the License at # 6 | # # 7 | # http://www.apache.org/licenses/LICENSE-2.0 # 8 | # # 9 | # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed # 10 | # on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for # 11 | # the specific language governing permissions and limitations under the License. # 12 | # ##################################################################################################################### 13 | -------------------------------------------------------------------------------- /source/forecast-shared/shared/quicksight_custom_resources/__init__.py: -------------------------------------------------------------------------------- 1 | # ##################################################################################################################### 2 | # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. # 3 | # # 4 | # Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance # 5 | # with the License. You may obtain a copy of the License at # 6 | # # 7 | # http://www.apache.org/licenses/LICENSE-2.0 # 8 | # # 9 | # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed # 10 | # on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for # 11 | # the specific language governing permissions and limitations under the License. # 12 | # ##################################################################################################################### 13 | -------------------------------------------------------------------------------- /source/forecast-shared/shared/quicksight_custom_resources/util/__init__.py: -------------------------------------------------------------------------------- 1 | # ##################################################################################################################### 2 | # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. # 3 | # # 4 | # Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance # 5 | # with the License. You may obtain a copy of the License at # 6 | # # 7 | # http://www.apache.org/licenses/LICENSE-2.0 # 8 | # # 9 | # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed # 10 | # on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for # 11 | # the specific language governing permissions and limitations under the License. # 12 | # ##################################################################################################################### 13 | -------------------------------------------------------------------------------- /source/forecast-shared/shared/quicksight_custom_resources/util/config/__init__.py: -------------------------------------------------------------------------------- 1 | # ##################################################################################################################### 2 | # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. # 3 | # # 4 | # Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance # 5 | # with the License. You may obtain a copy of the License at # 6 | # # 7 | # http://www.apache.org/licenses/LICENSE-2.0 # 8 | # # 9 | # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed # 10 | # on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for # 11 | # the specific language governing permissions and limitations under the License. # 12 | # ##################################################################################################################### 13 | -------------------------------------------------------------------------------- /source/forecast-shared/shared/quicksight_custom_resources/util/config/analysis-main.config.json: -------------------------------------------------------------------------------- 1 | { 2 | "SourceEntity": { 3 | "SourceTemplate": { 4 | "DataSetReferences": [ 5 | { 6 | "DataSetPlaceholder": "forecast", 7 | "DataSetArn": "arn:{Aws.PARTITION}:quicksight:{Aws.REGION}:{Aws.ACCOUNT_ID}:dataset/forecast" 8 | } 9 | ], 10 | "Arn": "{self.source_template_arn}" 11 | } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /source/forecast-shared/shared/quicksight_custom_resources/util/config/config.yaml: -------------------------------------------------------------------------------- 1 | dashboard: 2 | id: SO0123-v1_1_0_Dashboard 3 | name: SO0123-v1_1_0_Dashboard 4 | analysis: 5 | id: 5474c34d-e711-49f7-9225-62d67b52b8d4 6 | name: SO0123-v1_1_0_Analysis 7 | dataset: 8 | forecast: 9 | id: 08a7bf97-c085-47cf-a7fe-aaf9a6987d08 10 | name: export_ts_2020_10_19_16_28_06 11 | datasource: 12 | id: f0484c42-00be-4f91-a2aa-1711a8f9ff15 13 | name: Forecast -------------------------------------------------------------------------------- /source/forecast-shared/shared/quicksight_custom_resources/util/config/dashboard-main.config.json: -------------------------------------------------------------------------------- 1 | { 2 | "SourceEntity": { 3 | "SourceTemplate": { 4 | "DataSetReferences": [ 5 | { 6 | "DataSetPlaceholder": "forecast", 7 | "DataSetArn": "arn:{Aws.PARTITION}:quicksight:{Aws.REGION}:{Aws.ACCOUNT_ID}:dataset/forecast" 8 | } 9 | ], 10 | "Arn": "{self.source_template_arn}" 11 | } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /source/forecast-shared/shared/quicksight_custom_resources/util/config/template-main.config.json: -------------------------------------------------------------------------------- 1 | { 2 | "SourceEntity": { 3 | "SourceAnalysis": { 4 | "DataSetReferences": [ 5 | { 6 | "DataSetPlaceholder": "forecast", 7 | "DataSetArn": "arn:{Aws.PARTITION}:quicksight:{Aws.REGION}:{Aws.ACCOUNT_ID}:dataset/forecast" 8 | } 9 | ], 10 | "Arn": "{self.source_template_arn}" 11 | } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /source/forecast-shared/shared/s3/__init__.py: -------------------------------------------------------------------------------- 1 | # ##################################################################################################################### 2 | # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. # 3 | # # 4 | # Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance # 5 | # with the License. You may obtain a copy of the License at # 6 | # # 7 | # http://www.apache.org/licenses/LICENSE-2.0 # 8 | # # 9 | # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed # 10 | # on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for # 11 | # the specific language governing permissions and limitations under the License. # 12 | # ##################################################################################################################### 13 | -------------------------------------------------------------------------------- /source/forecast-shared/shared/s3/exceptions.py: -------------------------------------------------------------------------------- 1 | # ##################################################################################################################### 2 | # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. # 3 | # # 4 | # Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance # 5 | # with the License. You may obtain a copy of the License at # 6 | # # 7 | # http://www.apache.org/licenses/LICENSE-2.0 # 8 | # # 9 | # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed # 10 | # on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for # 11 | # the specific language governing permissions and limitations under the License. # 12 | # ##################################################################################################################### 13 | 14 | 15 | class BucketNotFound(Exception): 16 | def __init__(self, *args, **kwargs): 17 | msg = "Could not get the S3 event notification bucket. Was this an Amazon S3 event notification?" 18 | if args or kwargs: 19 | super().__init__(*args, **kwargs) 20 | else: 21 | super().__init__(msg) 22 | 23 | 24 | class RecordNotFound(Exception): 25 | def __init__(self, *args, **kwargs): 26 | msg = "Could not get the S3 event notification record. Was this an Amazon S3 event notification?" 27 | if args or kwargs: 28 | super().__init__(*args, **kwargs) 29 | else: 30 | super().__init__(msg) 31 | 32 | 33 | class RecordNotSupported(Exception): 34 | pass 35 | 36 | 37 | class KeyNotFound(Exception): 38 | def __init__(self, *args, **kwargs): 39 | msg = "Could not get the S3 event notification key. Was this an Amazon S3 event notification?" 40 | if args or kwargs: 41 | super().__init__(*args, **kwargs) 42 | else: 43 | super().__init__(msg) 44 | -------------------------------------------------------------------------------- /source/glue/__init__.py: -------------------------------------------------------------------------------- 1 | # ##################################################################################################################### 2 | # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. # 3 | # # 4 | # Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance # 5 | # with the License. You may obtain a copy of the License at # 6 | # # 7 | # http://www.apache.org/licenses/LICENSE-2.0 # 8 | # # 9 | # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed # 10 | # on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for # 11 | # the specific language governing permissions and limitations under the License. # 12 | # ##################################################################################################################### 13 | -------------------------------------------------------------------------------- /source/glue/jobs/__init__.py: -------------------------------------------------------------------------------- 1 | # ##################################################################################################################### 2 | # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. # 3 | # # 4 | # Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance # 5 | # with the License. You may obtain a copy of the License at # 6 | # # 7 | # http://www.apache.org/licenses/LICENSE-2.0 # 8 | # # 9 | # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed # 10 | # on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for # 11 | # the specific language governing permissions and limitations under the License. # 12 | # ##################################################################################################################### 13 | -------------------------------------------------------------------------------- /source/images/Forecast.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aws-solutions/improving-forecast-accuracy-with-machine-learning/HEAD/source/images/Forecast.jpg -------------------------------------------------------------------------------- /source/infrastructure/aspects/__init__.py: -------------------------------------------------------------------------------- 1 | # ##################################################################################################################### 2 | # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. # 3 | # # 4 | # Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance # 5 | # with the License. You may obtain a copy of the License at # 6 | # # 7 | # http://www.apache.org/licenses/LICENSE-2.0 # 8 | # # 9 | # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed # 10 | # on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for # 11 | # the specific language governing permissions and limitations under the License. # 12 | # ##################################################################################################################### -------------------------------------------------------------------------------- /source/infrastructure/cdk.json: -------------------------------------------------------------------------------- 1 | { 2 | "app": "python3 deploy.py", 3 | "context": { 4 | "SOLUTION_NAME": "Improving Forecast Accuracy with Machine Learning", 5 | "SOLUTION_ID": "SO0123", 6 | "SOLUTION_VERSION": "v1.5.6", 7 | "APP_REG_NAME": "forecast-ml", 8 | "APPLICATION_TYPE": "AWS-Solutions", 9 | "VERSION": "1.5.6", 10 | "@aws-cdk/core:newStyleStackSynthesis": "true" 11 | } 12 | } -------------------------------------------------------------------------------- /source/infrastructure/forecast/__init__.py: -------------------------------------------------------------------------------- 1 | # ##################################################################################################################### 2 | # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. # 3 | # # 4 | # Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance # 5 | # with the License. You may obtain a copy of the License at # 6 | # # 7 | # http://www.apache.org/licenses/LICENSE-2.0 # 8 | # # 9 | # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed # 10 | # on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for # 11 | # the specific language governing permissions and limitations under the License. # 12 | # ##################################################################################################################### 13 | -------------------------------------------------------------------------------- /source/infrastructure/forecast/aws_lambda/__init__.py: -------------------------------------------------------------------------------- 1 | # ##################################################################################################################### 2 | # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. # 3 | # # 4 | # Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance # 5 | # with the License. You may obtain a copy of the License at # 6 | # # 7 | # http://www.apache.org/licenses/LICENSE-2.0 # 8 | # # 9 | # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed # 10 | # on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for # 11 | # the specific language governing permissions and limitations under the License. # 12 | # ##################################################################################################################### 13 | -------------------------------------------------------------------------------- /source/infrastructure/forecast/aws_lambda/functions/__init__.py: -------------------------------------------------------------------------------- 1 | # ##################################################################################################################### 2 | # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. # 3 | # # 4 | # Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance # 5 | # with the License. You may obtain a copy of the License at # 6 | # # 7 | # http://www.apache.org/licenses/LICENSE-2.0 # 8 | # # 9 | # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed # 10 | # on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for # 11 | # the specific language governing permissions and limitations under the License. # 12 | # ##################################################################################################################### 13 | 14 | from forecast.aws_lambda.functions.create_dataset_group import CreateDatasetGroup 15 | from forecast.aws_lambda.functions.create_dataset_import_job import ( 16 | CreateDatasetImportJob, 17 | ) 18 | from forecast.aws_lambda.functions.create_forecast import CreateForecast 19 | from forecast.aws_lambda.functions.create_forecast_export import CreateForecastExport 20 | from forecast.aws_lambda.functions.create_glue_table_name import CreateGlueTableName 21 | from forecast.aws_lambda.functions.create_predictor import CreatePredictor 22 | from forecast.aws_lambda.functions.create_predictor_backtest_export import ( 23 | CreatePredictorBacktestExport, 24 | ) 25 | from forecast.aws_lambda.functions.create_quicksight_analysis import ( 26 | CreateQuickSightAnalysis, 27 | ) 28 | from forecast.aws_lambda.functions.s3_event import S3EventHandler 29 | from forecast.aws_lambda.functions.sns import Notifications 30 | -------------------------------------------------------------------------------- /source/infrastructure/forecast/aws_lambda/functions/base.py: -------------------------------------------------------------------------------- 1 | # ##################################################################################################################### 2 | # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. # 3 | # # 4 | # Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance # 5 | # with the License. You may obtain a copy of the License at # 6 | # # 7 | # http://www.apache.org/licenses/LICENSE-2.0 # 8 | # # 9 | # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed # 10 | # on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for # 11 | # the specific language governing permissions and limitations under the License. # 12 | # ##################################################################################################################### 13 | from pathlib import Path 14 | from constructs import Construct 15 | 16 | from aws_solutions.cdk.stepfunctions.solutionstep import SolutionStep 17 | 18 | 19 | class Base(SolutionStep): 20 | def __init__( 21 | self, 22 | scope: Construct, 23 | id: str, 24 | name: str, 25 | handler="handler.py", 26 | function=None, 27 | layers=None, 28 | **kwargs, 29 | ): 30 | if not function: 31 | function = name # NOSONAR - allow for variable name for argument consistency 32 | 33 | super().__init__( 34 | scope, 35 | id, 36 | layers=layers, 37 | entrypoint=( 38 | Path(__file__).absolute().parents[4] / "lambdas" / name / handler 39 | ), 40 | function=function, 41 | **kwargs, 42 | ) 43 | 44 | def _set_permissions(self) -> None: 45 | pass # NOSONAR (python:S1186) - no permissions required by default 46 | -------------------------------------------------------------------------------- /source/infrastructure/forecast/aws_lambda/functions/create_dataset_group.py: -------------------------------------------------------------------------------- 1 | # ##################################################################################################################### 2 | # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. # 3 | # # 4 | # Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance # 5 | # with the License. You may obtain a copy of the License at # 6 | # # 7 | # http://www.apache.org/licenses/LICENSE-2.0 # 8 | # # 9 | # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed # 10 | # on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for # 11 | # the specific language governing permissions and limitations under the License. # 12 | # ##################################################################################################################### 13 | 14 | from constructs import Construct 15 | from forecast.aws_lambda.functions.base import Base 16 | 17 | class CreateDatasetGroup(Base): 18 | def __init__(self, scope: Construct, id: str, **kwargs): 19 | super().__init__(scope, id, name="createdatasetgroup", **kwargs) 20 | -------------------------------------------------------------------------------- /source/infrastructure/forecast/aws_lambda/functions/create_dataset_import_job.py: -------------------------------------------------------------------------------- 1 | # ##################################################################################################################### 2 | # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. # 3 | # # 4 | # Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance # 5 | # with the License. You may obtain a copy of the License at # 6 | # # 7 | # http://www.apache.org/licenses/LICENSE-2.0 # 8 | # # 9 | # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed # 10 | # on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for # 11 | # the specific language governing permissions and limitations under the License. # 12 | # ##################################################################################################################### 13 | 14 | from constructs import Construct 15 | from forecast.aws_lambda.functions.base import Base 16 | 17 | class CreateDatasetImportJob(Base): 18 | def __init__(self, scope: Construct, id: str, **kwargs): 19 | super().__init__(scope, id, name="createdatasetimportjob", **kwargs) 20 | -------------------------------------------------------------------------------- /source/infrastructure/forecast/aws_lambda/functions/create_forecast.py: -------------------------------------------------------------------------------- 1 | # ##################################################################################################################### 2 | # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. # 3 | # # 4 | # Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance # 5 | # with the License. You may obtain a copy of the License at # 6 | # # 7 | # http://www.apache.org/licenses/LICENSE-2.0 # 8 | # # 9 | # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed # 10 | # on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for # 11 | # the specific language governing permissions and limitations under the License. # 12 | # ##################################################################################################################### 13 | 14 | from constructs import Construct 15 | from forecast.aws_lambda.functions.base import Base 16 | 17 | class CreateForecast(Base): 18 | def __init__(self, scope: Construct, id: str, **kwargs): 19 | super().__init__( 20 | scope, 21 | id, 22 | name="createforecast", 23 | handler="create_forecast.py", 24 | function="handler", 25 | **kwargs 26 | ) 27 | -------------------------------------------------------------------------------- /source/infrastructure/forecast/aws_lambda/functions/create_forecast_export.py: -------------------------------------------------------------------------------- 1 | # ##################################################################################################################### 2 | # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. # 3 | # # 4 | # Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance # 5 | # with the License. You may obtain a copy of the License at # 6 | # # 7 | # http://www.apache.org/licenses/LICENSE-2.0 # 8 | # # 9 | # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed # 10 | # on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for # 11 | # the specific language governing permissions and limitations under the License. # 12 | # ##################################################################################################################### 13 | 14 | from constructs import Construct 15 | from forecast.aws_lambda.functions.base import Base 16 | 17 | class CreateForecastExport(Base): 18 | def __init__(self, scope: Construct, id: str, **kwargs): 19 | super().__init__( 20 | scope, 21 | id, 22 | name="createforecast", 23 | handler="create_forecast_export.py", 24 | function="handler", 25 | **kwargs 26 | ) 27 | -------------------------------------------------------------------------------- /source/infrastructure/forecast/aws_lambda/functions/create_glue_table_name.py: -------------------------------------------------------------------------------- 1 | # ##################################################################################################################### 2 | # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. # 3 | # # 4 | # Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance # 5 | # with the License. You may obtain a copy of the License at # 6 | # # 7 | # http://www.apache.org/licenses/LICENSE-2.0 # 8 | # # 9 | # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed # 10 | # on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for # 11 | # the specific language governing permissions and limitations under the License. # 12 | # ##################################################################################################################### 13 | 14 | from constructs import Construct 15 | from forecast.aws_lambda.functions.base import Base 16 | 17 | class CreateGlueTableName(Base): 18 | def __init__(self, scope: Construct, id: str, **kwargs): 19 | super().__init__(scope, id, name="creategluetablename", **kwargs) 20 | -------------------------------------------------------------------------------- /source/infrastructure/forecast/aws_lambda/functions/create_predictor.py: -------------------------------------------------------------------------------- 1 | # ##################################################################################################################### 2 | # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. # 3 | # # 4 | # Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance # 5 | # with the License. You may obtain a copy of the License at # 6 | # # 7 | # http://www.apache.org/licenses/LICENSE-2.0 # 8 | # # 9 | # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed # 10 | # on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for # 11 | # the specific language governing permissions and limitations under the License. # 12 | # ##################################################################################################################### 13 | 14 | from constructs import Construct 15 | from forecast.aws_lambda.functions.base import Base 16 | 17 | class CreatePredictor(Base): 18 | def __init__(self, scope: Construct, id: str, **kwargs): 19 | super().__init__( 20 | scope, 21 | id, 22 | name="createpredictor", 23 | handler="create_predictor.py", 24 | function="handler", 25 | **kwargs 26 | ) 27 | -------------------------------------------------------------------------------- /source/infrastructure/forecast/aws_lambda/functions/create_predictor_backtest_export.py: -------------------------------------------------------------------------------- 1 | # ##################################################################################################################### 2 | # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. # 3 | # # 4 | # Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance # 5 | # with the License. You may obtain a copy of the License at # 6 | # # 7 | # http://www.apache.org/licenses/LICENSE-2.0 # 8 | # # 9 | # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed # 10 | # on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for # 11 | # the specific language governing permissions and limitations under the License. # 12 | # ##################################################################################################################### 13 | 14 | from constructs import Construct 15 | from forecast.aws_lambda.functions.base import Base 16 | 17 | class CreatePredictorBacktestExport(Base): 18 | def __init__(self, scope: Construct, id: str, **kwargs): 19 | super().__init__( 20 | scope, 21 | id, 22 | name="createpredictor", 23 | handler="create_predictor_backtest_export.py", 24 | function="handler", 25 | **kwargs 26 | ) 27 | -------------------------------------------------------------------------------- /source/infrastructure/forecast/aws_lambda/functions/create_quicksight_analysis.py: -------------------------------------------------------------------------------- 1 | # ##################################################################################################################### 2 | # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. # 3 | # # 4 | # Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance # 5 | # with the License. You may obtain a copy of the License at # 6 | # # 7 | # http://www.apache.org/licenses/LICENSE-2.0 # 8 | # # 9 | # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed # 10 | # on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for # 11 | # the specific language governing permissions and limitations under the License. # 12 | # ##################################################################################################################### 13 | 14 | from constructs import Construct 15 | from forecast.aws_lambda.functions.base import Base 16 | 17 | class CreateQuickSightAnalysis(Base): 18 | def __init__(self, scope: Construct, id: str, **kwargs): 19 | super().__init__(scope, id, name="createquicksightanalysis", **kwargs) 20 | -------------------------------------------------------------------------------- /source/infrastructure/forecast/aws_lambda/layers/__init__.py: -------------------------------------------------------------------------------- 1 | # ##################################################################################################################### 2 | # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. # 3 | # # 4 | # Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance # 5 | # with the License. You may obtain a copy of the License at # 6 | # # 7 | # http://www.apache.org/licenses/LICENSE-2.0 # 8 | # # 9 | # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed # 10 | # on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for # 11 | # the specific language governing permissions and limitations under the License. # 12 | # ##################################################################################################################### 13 | 14 | from forecast.aws_lambda.layers.forecast_solution.layer import ( 15 | Layer as ForecastSolutionLayer, 16 | ) 17 | -------------------------------------------------------------------------------- /source/infrastructure/forecast/aws_lambda/layers/forecast_solution/__init__.py: -------------------------------------------------------------------------------- 1 | # ##################################################################################################################### 2 | # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. # 3 | # # 4 | # Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance # 5 | # with the License. You may obtain a copy of the License at # 6 | # # 7 | # http://www.apache.org/licenses/LICENSE-2.0 # 8 | # # 9 | # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed # 10 | # on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for # 11 | # the specific language governing permissions and limitations under the License. # 12 | # ##################################################################################################################### 13 | -------------------------------------------------------------------------------- /source/infrastructure/forecast/aws_lambda/layers/forecast_solution/layer.py: -------------------------------------------------------------------------------- 1 | # ##################################################################################################################### 2 | # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. # 3 | # # 4 | # Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance # 5 | # with the License. You may obtain a copy of the License at # 6 | # # 7 | # http://www.apache.org/licenses/LICENSE-2.0 # 8 | # # 9 | # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed # 10 | # on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for # 11 | # the specific language governing permissions and limitations under the License. # 12 | # ##################################################################################################################### 13 | 14 | from pathlib import Path 15 | 16 | from constructs import Construct 17 | from aws_cdk import Stack 18 | from aws_solutions.cdk.aws_lambda.python.layer import SolutionsPythonLayerVersion 19 | 20 | class Layer(SolutionsPythonLayerVersion): 21 | def __init__(self, scope: Construct, construct_id: str, **kwargs): 22 | requirements_path: Path = Path(__file__).absolute().parent / "requirements" 23 | super().__init__(scope, construct_id, requirements_path, **kwargs) 24 | 25 | @staticmethod 26 | def get_or_create(scope: Construct, **kwargs): 27 | stack = Stack.of(scope) 28 | construct_id = "SolutionsLayer-355B263A-3783-4189-9BF9-B7081E35B44F" 29 | exists = stack.node.try_find_child(construct_id) 30 | if exists: 31 | return exists 32 | return Layer(stack, construct_id, **kwargs) 33 | -------------------------------------------------------------------------------- /source/infrastructure/forecast/aws_lambda/layers/forecast_solution/requirements/requirements.txt: -------------------------------------------------------------------------------- 1 | PyYAML==6.0.0 2 | packaging==23.0 3 | boto3==1.26.83 4 | tenacity==8.2.2 5 | ../../../../../../forecast-shared -------------------------------------------------------------------------------- /source/infrastructure/forecast/aws_lambda/policies/__init__.py: -------------------------------------------------------------------------------- 1 | # ##################################################################################################################### 2 | # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. # 3 | # # 4 | # Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance # 5 | # with the License. You may obtain a copy of the License at # 6 | # # 7 | # http://www.apache.org/licenses/LICENSE-2.0 # 8 | # # 9 | # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed # 10 | # on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for # 11 | # the specific language governing permissions and limitations under the License. # 12 | # ##################################################################################################################### 13 | 14 | from forecast.aws_lambda.policies.factory import PolicyFactory 15 | -------------------------------------------------------------------------------- /source/infrastructure/forecast/buckets/__init__.py: -------------------------------------------------------------------------------- 1 | # ##################################################################################################################### 2 | # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. # 3 | # # 4 | # Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance # 5 | # with the License. You may obtain a copy of the License at # 6 | # # 7 | # http://www.apache.org/licenses/LICENSE-2.0 # 8 | # # 9 | # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed # 10 | # on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for # 11 | # the specific language governing permissions and limitations under the License. # 12 | # ##################################################################################################################### 13 | 14 | from forecast.buckets.access_logs_bucket import AccessLogsBucket 15 | from forecast.buckets.athena_bucket import AthenaBucket 16 | from forecast.buckets.data_bucket import DataBucket 17 | -------------------------------------------------------------------------------- /source/infrastructure/forecast/buckets/access_logs_bucket.py: -------------------------------------------------------------------------------- 1 | # ##################################################################################################################### 2 | # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. # 3 | # # 4 | # Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance # 5 | # with the License. You may obtain a copy of the License at # 6 | # # 7 | # http://www.apache.org/licenses/LICENSE-2.0 # 8 | # # 9 | # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed # 10 | # on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for # 11 | # the specific language governing permissions and limitations under the License. # 12 | # ##################################################################################################################### 13 | from constructs import Construct 14 | from aws_solutions.cdk.cfn_nag import CfnNagSuppression 15 | from aws_solutions.cdk.utils.secure_bucket import SecureBucket 16 | 17 | class AccessLogsBucket(SecureBucket): 18 | def __init__(self, scope: Construct, **kwargs): 19 | super().__init__( 20 | scope, 21 | "AccessLogsBucket", 22 | suppress=[ 23 | CfnNagSuppression( 24 | "W35", 25 | "This bucket is used as the logging destination for personalization data processing", 26 | ) 27 | ], 28 | **kwargs, 29 | ) 30 | -------------------------------------------------------------------------------- /source/infrastructure/forecast/buckets/athena_bucket.py: -------------------------------------------------------------------------------- 1 | # ##################################################################################################################### 2 | # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. # 3 | # # 4 | # Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance # 5 | # with the License. You may obtain a copy of the License at # 6 | # # 7 | # http://www.apache.org/licenses/LICENSE-2.0 # 8 | # # 9 | # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed # 10 | # on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for # 11 | # the specific language governing permissions and limitations under the License. # 12 | # ##################################################################################################################### 13 | 14 | from constructs import Construct 15 | from aws_solutions.cdk.utils.secure_bucket import SecureBucket 16 | 17 | class AthenaBucket(SecureBucket): 18 | def __init__(self, scope: Construct, **kwargs): 19 | super().__init__(scope, "AthenaBucket", **kwargs) 20 | -------------------------------------------------------------------------------- /source/infrastructure/forecast/buckets/data_bucket.py: -------------------------------------------------------------------------------- 1 | # ##################################################################################################################### 2 | # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. # 3 | # # 4 | # Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance # 5 | # with the License. You may obtain a copy of the License at # 6 | # # 7 | # http://www.apache.org/licenses/LICENSE-2.0 # 8 | # # 9 | # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed # 10 | # on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for # 11 | # the specific language governing permissions and limitations under the License. # 12 | # ##################################################################################################################### 13 | 14 | from constructs import Construct 15 | from aws_cdk.aws_s3 import LifecycleRule 16 | from aws_cdk import Duration 17 | 18 | from aws_solutions.cdk.utils.secure_bucket import SecureBucket 19 | 20 | class DataBucket(SecureBucket): 21 | def __init__(self, scope: Construct, **kwargs): 22 | super().__init__( 23 | scope, 24 | "ForecastBucket", 25 | lifecycle_rules=[ 26 | LifecycleRule( 27 | abort_incomplete_multipart_upload_after=Duration.days(3), 28 | enabled=True, 29 | ), 30 | LifecycleRule(expiration=Duration.days(1), prefix="raw/", enabled=True), 31 | ], 32 | **kwargs 33 | ) 34 | -------------------------------------------------------------------------------- /source/infrastructure/forecast/etl/__init__.py: -------------------------------------------------------------------------------- 1 | # ##################################################################################################################### 2 | # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. # 3 | # # 4 | # Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance # 5 | # with the License. You may obtain a copy of the License at # 6 | # # 7 | # http://www.apache.org/licenses/LICENSE-2.0 # 8 | # # 9 | # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed # 10 | # on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for # 11 | # the specific language governing permissions and limitations under the License. # 12 | # ##################################################################################################################### 13 | 14 | from forecast.etl.athena import Athena 15 | from forecast.etl.glue import Glue 16 | -------------------------------------------------------------------------------- /source/infrastructure/forecast/forecast/__init__.py: -------------------------------------------------------------------------------- 1 | # ##################################################################################################################### 2 | # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. # 3 | # # 4 | # Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance # 5 | # with the License. You may obtain a copy of the License at # 6 | # # 7 | # http://www.apache.org/licenses/LICENSE-2.0 # 8 | # # 9 | # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed # 10 | # on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for # 11 | # the specific language governing permissions and limitations under the License. # 12 | # ##################################################################################################################### 13 | -------------------------------------------------------------------------------- /source/infrastructure/forecast/sagemaker/__init__.py: -------------------------------------------------------------------------------- 1 | # ##################################################################################################################### 2 | # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. # 3 | # # 4 | # Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance # 5 | # with the License. You may obtain a copy of the License at # 6 | # # 7 | # http://www.apache.org/licenses/LICENSE-2.0 # 8 | # # 9 | # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed # 10 | # on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for # 11 | # the specific language governing permissions and limitations under the License. # 12 | # ##################################################################################################################### 13 | -------------------------------------------------------------------------------- /source/infrastructure/forecast/sns/__init__.py: -------------------------------------------------------------------------------- 1 | # ##################################################################################################################### 2 | # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. # 3 | # # 4 | # Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance # 5 | # with the License. You may obtain a copy of the License at # 6 | # # 7 | # http://www.apache.org/licenses/LICENSE-2.0 # 8 | # # 9 | # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed # 10 | # on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for # 11 | # the specific language governing permissions and limitations under the License. # 12 | # ##################################################################################################################### 13 | -------------------------------------------------------------------------------- /source/infrastructure/pytest.ini: -------------------------------------------------------------------------------- 1 | [pytest] 2 | norecursedirs = cdk.out -------------------------------------------------------------------------------- /source/infrastructure/quicksight/__init__.py: -------------------------------------------------------------------------------- 1 | # ##################################################################################################################### 2 | # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. # 3 | # # 4 | # Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance # 5 | # with the License. You may obtain a copy of the License at # 6 | # # 7 | # http://www.apache.org/licenses/LICENSE-2.0 # 8 | # # 9 | # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed # 10 | # on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for # 11 | # the specific language governing permissions and limitations under the License. # 12 | # ##################################################################################################################### 13 | 14 | from quicksight.template_source import TemplateSource 15 | -------------------------------------------------------------------------------- /source/infrastructure/tests/__init__.py: -------------------------------------------------------------------------------- 1 | # ##################################################################################################################### 2 | # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. # 3 | # # 4 | # Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance # 5 | # with the License. You may obtain a copy of the License at # 6 | # # 7 | # http://www.apache.org/licenses/LICENSE-2.0 # 8 | # # 9 | # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed # 10 | # on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for # 11 | # the specific language governing permissions and limitations under the License. # 12 | # ##################################################################################################################### 13 | -------------------------------------------------------------------------------- /source/infrastructure/tests/assets/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /source/lambdas/__init__.py: -------------------------------------------------------------------------------- 1 | # ##################################################################################################################### 2 | # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. # 3 | # # 4 | # Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance # 5 | # with the License. You may obtain a copy of the License at # 6 | # # 7 | # http://www.apache.org/licenses/LICENSE-2.0 # 8 | # # 9 | # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed # 10 | # on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for # 11 | # the specific language governing permissions and limitations under the License. # 12 | # ##################################################################################################################### 13 | -------------------------------------------------------------------------------- /source/lambdas/createdatasetgroup/__init__.py: -------------------------------------------------------------------------------- 1 | # ##################################################################################################################### 2 | # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. # 3 | # # 4 | # Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance # 5 | # with the License. You may obtain a copy of the License at # 6 | # # 7 | # http://www.apache.org/licenses/LICENSE-2.0 # 8 | # # 9 | # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed # 10 | # on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for # 11 | # the specific language governing permissions and limitations under the License. # 12 | # ##################################################################################################################### 13 | -------------------------------------------------------------------------------- /source/lambdas/createdatasetimportjob/__init__.py: -------------------------------------------------------------------------------- 1 | # ##################################################################################################################### 2 | # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. # 3 | # # 4 | # Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance # 5 | # with the License. You may obtain a copy of the License at # 6 | # # 7 | # http://www.apache.org/licenses/LICENSE-2.0 # 8 | # # 9 | # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed # 10 | # on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for # 11 | # the specific language governing permissions and limitations under the License. # 12 | # ##################################################################################################################### 13 | -------------------------------------------------------------------------------- /source/lambdas/createdatasetimportjob/handler.py: -------------------------------------------------------------------------------- 1 | # ##################################################################################################################### 2 | # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. # 3 | # # 4 | # Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance # 5 | # with the License. You may obtain a copy of the License at # 6 | # # 7 | # http://www.apache.org/licenses/LICENSE-2.0 # 8 | # # 9 | # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed # 10 | # on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for # 11 | # the specific language governing permissions and limitations under the License. # 12 | # ##################################################################################################################### 13 | 14 | from shared.Dataset.dataset_file import DatasetFile 15 | from shared.config import Config 16 | from shared.helpers import step_function_step 17 | from shared.status import Status 18 | 19 | 20 | @step_function_step 21 | def createdatasetimportjob(event, context) -> (Status, str): 22 | """ 23 | Create/ monitor Amazon Forecast dataset import job creation 24 | :param event: lambda event 25 | :param context: lambda context 26 | :return: dataset import job status and dataset ARN 27 | """ 28 | config = Config.from_sfn(event) 29 | dataset_file = DatasetFile(event.get("dataset_file"), event.get("bucket")) 30 | 31 | dataset_import = config.dataset_import_job(dataset_file) 32 | if dataset_import.status == Status.DOES_NOT_EXIST: 33 | dataset_import.create() 34 | 35 | return dataset_import.status, dataset_import.arn 36 | -------------------------------------------------------------------------------- /source/lambdas/createforecast/__init__.py: -------------------------------------------------------------------------------- 1 | # ##################################################################################################################### 2 | # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. # 3 | # # 4 | # Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance # 5 | # with the License. You may obtain a copy of the License at # 6 | # # 7 | # http://www.apache.org/licenses/LICENSE-2.0 # 8 | # # 9 | # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed # 10 | # on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for # 11 | # the specific language governing permissions and limitations under the License. # 12 | # ##################################################################################################################### 13 | -------------------------------------------------------------------------------- /source/lambdas/createforecast/create_forecast.py: -------------------------------------------------------------------------------- 1 | # ##################################################################################################################### 2 | # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. # 3 | # # 4 | # Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance # 5 | # with the License. You may obtain a copy of the License at # 6 | # # 7 | # http://www.apache.org/licenses/LICENSE-2.0 # 8 | # # 9 | # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed # 10 | # on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for # 11 | # the specific language governing permissions and limitations under the License. # 12 | # ##################################################################################################################### 13 | 14 | from shared.Dataset.dataset_file import DatasetFile 15 | from shared.config import Config 16 | from shared.helpers import step_function_step 17 | from shared.logging import get_logger 18 | from shared.status import Status 19 | 20 | logger = get_logger(__name__) 21 | 22 | 23 | @step_function_step 24 | def handler(event, context): 25 | """ 26 | Create/ monitor Amazon Forecast forecast creation 27 | :param event: lambda event 28 | :param context: lambda context 29 | :return: forecast / forecast export status and forecast ARN 30 | """ 31 | config = Config.from_sfn(event) 32 | dataset_file = DatasetFile(event.get("dataset_file"), event.get("bucket")) 33 | dataset_group_name = event.get("dataset_group_name") 34 | predictor_arn = event.get("PredictorArn") 35 | 36 | forecast = config.forecast(dataset_file, dataset_group_name, predictor_arn) 37 | 38 | if forecast.status == Status.DOES_NOT_EXIST: 39 | logger.info("Creating forecast for %s" % dataset_group_name) 40 | forecast.create() 41 | 42 | return forecast.status, forecast.arn 43 | -------------------------------------------------------------------------------- /source/lambdas/createforecast/create_forecast_export.py: -------------------------------------------------------------------------------- 1 | # ##################################################################################################################### 2 | # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. # 3 | # # 4 | # Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance # 5 | # with the License. You may obtain a copy of the License at # 6 | # # 7 | # http://www.apache.org/licenses/LICENSE-2.0 # 8 | # # 9 | # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed # 10 | # on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for # 11 | # the specific language governing permissions and limitations under the License. # 12 | # ##################################################################################################################### 13 | 14 | from shared.Dataset.dataset_file import DatasetFile 15 | from shared.config import Config 16 | from shared.helpers import step_function_step 17 | from shared.logging import get_logger 18 | from shared.status import Status 19 | 20 | logger = get_logger(__name__) 21 | 22 | 23 | @step_function_step 24 | def handler(event, context) -> (Status, str): 25 | config = Config.from_sfn(event) 26 | dataset_file = DatasetFile(event.get("dataset_file"), event.get("bucket")) 27 | dataset_group_name = event.get("dataset_group_name") 28 | predictor_arn = event.get("PredictorArn") 29 | 30 | forecast = config.forecast(dataset_file, dataset_group_name, predictor_arn) 31 | 32 | if forecast.status == Status.ACTIVE: 33 | logger.info("Creating forecast export for %s" % dataset_file.prefix) 34 | export = forecast.export(dataset_file) 35 | else: 36 | raise ValueError("forecast status must be ACTIVE to export a forecast") 37 | 38 | return export.status, forecast.arn 39 | -------------------------------------------------------------------------------- /source/lambdas/creategluetablename/__init__.py: -------------------------------------------------------------------------------- 1 | # ##################################################################################################################### 2 | # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. # 3 | # # 4 | # Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance # 5 | # with the License. You may obtain a copy of the License at # 6 | # # 7 | # http://www.apache.org/licenses/LICENSE-2.0 # 8 | # # 9 | # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed # 10 | # on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for # 11 | # the specific language governing permissions and limitations under the License. # 12 | # ##################################################################################################################### 13 | -------------------------------------------------------------------------------- /source/lambdas/creategluetablename/handler.py: -------------------------------------------------------------------------------- 1 | # ##################################################################################################################### 2 | # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. # 3 | # # 4 | # Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance # 5 | # with the License. You may obtain a copy of the License at # 6 | # # 7 | # http://www.apache.org/licenses/LICENSE-2.0 # 8 | # # 9 | # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed # 10 | # on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for # 11 | # the specific language governing permissions and limitations under the License. # 12 | # ##################################################################################################################### 13 | 14 | from datetime import datetime 15 | 16 | from shared.logging import get_logger 17 | 18 | logger = get_logger(__name__) 19 | 20 | 21 | def creategluetablename(event, context): # NOSONAR - context is a required argument for this function 22 | # Removing context could potentially cause breaking changes in deployment 23 | dataset_group_name = event.get("dataset_group_name") 24 | timestamp = datetime.now().strftime("%Y_%m_%d_%H_%M_%S") 25 | glue_table_name = f"{dataset_group_name}_{timestamp}" 26 | 27 | logger.info("glue table name for this forecast: %s" % glue_table_name) 28 | return glue_table_name 29 | -------------------------------------------------------------------------------- /source/lambdas/createpredictor/__init__.py: -------------------------------------------------------------------------------- 1 | # ##################################################################################################################### 2 | # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. # 3 | # # 4 | # Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance # 5 | # with the License. You may obtain a copy of the License at # 6 | # # 7 | # http://www.apache.org/licenses/LICENSE-2.0 # 8 | # # 9 | # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed # 10 | # on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for # 11 | # the specific language governing permissions and limitations under the License. # 12 | # ##################################################################################################################### 13 | -------------------------------------------------------------------------------- /source/lambdas/createpredictor/create_predictor.py: -------------------------------------------------------------------------------- 1 | # ##################################################################################################################### 2 | # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. # 3 | # # 4 | # Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance # 5 | # with the License. You may obtain a copy of the License at # 6 | # # 7 | # http://www.apache.org/licenses/LICENSE-2.0 # 8 | # # 9 | # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed # 10 | # on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for # 11 | # the specific language governing permissions and limitations under the License. # 12 | # ##################################################################################################################### 13 | 14 | from shared.Dataset.dataset_file import DatasetFile 15 | from shared.config import Config 16 | from shared.helpers import step_function_step 17 | from shared.logging import get_logger 18 | from shared.status import Status 19 | 20 | logger = get_logger(__name__) 21 | 22 | 23 | @step_function_step 24 | def handler(event, context) -> (Status, str): 25 | """ 26 | Create/ monitor Amazon Forecast predictor creation 27 | :param event: lambda event 28 | :param context: lambda context 29 | :return: predictor status and dataset ARN 30 | """ 31 | config = Config.from_sfn(event) 32 | dataset_file = DatasetFile(event.get("dataset_file"), event.get("bucket")) 33 | dataset_group_name = event.get("dataset_group_name") 34 | 35 | predictor = config.predictor(dataset_file, dataset_group_name) 36 | 37 | if predictor.status == Status.DOES_NOT_EXIST: 38 | logger.info("Creating predictor for %s" % dataset_file.prefix) 39 | predictor.create() 40 | 41 | return predictor.status, predictor.arn 42 | -------------------------------------------------------------------------------- /source/lambdas/createpredictor/create_predictor_backtest_export.py: -------------------------------------------------------------------------------- 1 | # ##################################################################################################################### 2 | # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. # 3 | # # 4 | # Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance # 5 | # with the License. You may obtain a copy of the License at # 6 | # # 7 | # http://www.apache.org/licenses/LICENSE-2.0 # 8 | # # 9 | # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed # 10 | # on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for # 11 | # the specific language governing permissions and limitations under the License. # 12 | # ##################################################################################################################### 13 | 14 | from shared.Dataset.dataset_file import DatasetFile 15 | from shared.config import Config 16 | from shared.helpers import step_function_step 17 | from shared.logging import get_logger 18 | from shared.status import Status 19 | 20 | logger = get_logger(__name__) 21 | 22 | 23 | @step_function_step 24 | def handler(event, context) -> (Status, str): 25 | config = Config.from_sfn(event) 26 | dataset_file = DatasetFile(event.get("dataset_file"), event.get("bucket")) 27 | dataset_group_name = event.get("dataset_group_name") 28 | 29 | predictor = config.predictor(dataset_file, dataset_group_name) 30 | 31 | if predictor.status == Status.ACTIVE: 32 | logger.info("Creating predictor backtest export for %s" % dataset_file.prefix) 33 | export = predictor.export(dataset_file) 34 | else: 35 | raise ValueError("predictor status must be ACTIVE to export a predictor") 36 | 37 | return export.status, predictor.arn 38 | -------------------------------------------------------------------------------- /source/lambdas/createquicksightanalysis/__init__.py: -------------------------------------------------------------------------------- 1 | # ##################################################################################################################### 2 | # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. # 3 | # # 4 | # Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance # 5 | # with the License. You may obtain a copy of the License at # 6 | # # 7 | # http://www.apache.org/licenses/LICENSE-2.0 # 8 | # # 9 | # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed # 10 | # on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for # 11 | # the specific language governing permissions and limitations under the License. # 12 | # ##################################################################################################################### 13 | -------------------------------------------------------------------------------- /source/lambdas/lambda_datasetutils/requirements.txt: -------------------------------------------------------------------------------- 1 | PyYAML==6.0.0 2 | packaging==23.0 3 | boto3==1.26.83 4 | tenacity==8.2.2 -------------------------------------------------------------------------------- /source/lambdas/lambda_dependencies/requirements.txt: -------------------------------------------------------------------------------- 1 | PyYAML==6.0.0 2 | packaging==23.0 3 | boto3==1.26.83 -------------------------------------------------------------------------------- /source/lambdas/notification/__init__.py: -------------------------------------------------------------------------------- 1 | # ##################################################################################################################### 2 | # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. # 3 | # # 4 | # Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance # 5 | # with the License. You may obtain a copy of the License at # 6 | # # 7 | # http://www.apache.org/licenses/LICENSE-2.0 # 8 | # # 9 | # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed # 10 | # on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for # 11 | # the specific language governing permissions and limitations under the License. # 12 | # ##################################################################################################################### 13 | -------------------------------------------------------------------------------- /source/lambdas/sns/__init__.py: -------------------------------------------------------------------------------- 1 | # ##################################################################################################################### 2 | # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. # 3 | # # 4 | # Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance # 5 | # with the License. You may obtain a copy of the License at # 6 | # # 7 | # http://www.apache.org/licenses/LICENSE-2.0 # 8 | # # 9 | # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed # 10 | # on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for # 11 | # the specific language governing permissions and limitations under the License. # 12 | # ##################################################################################################################### 13 | -------------------------------------------------------------------------------- /source/notebook/__init__.py: -------------------------------------------------------------------------------- 1 | # ##################################################################################################################### 2 | # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. # 3 | # # 4 | # Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance # 5 | # with the License. You may obtain a copy of the License at # 6 | # # 7 | # http://www.apache.org/licenses/LICENSE-2.0 # 8 | # # 9 | # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed # 10 | # on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for # 11 | # the specific language governing permissions and limitations under the License. # 12 | # ##################################################################################################################### 13 | -------------------------------------------------------------------------------- /source/pytest.ini: -------------------------------------------------------------------------------- 1 | [pytest] 2 | env = 3 | MOTO_ACCOUNT_ID=abcdefghijkl 4 | SOLUTION_NAME=Improving Forecast Accuracy with Machine Learning 5 | SOLUTION_VERSION=v99.99.99 6 | SOLUTION_ID=SO0123Test 7 | AWS_REGION=us-east-1 8 | AWS_DEFAULT_REGION=us-east-1 9 | norecursedirs = infrastructure -------------------------------------------------------------------------------- /source/requirements-build-and-test.txt: -------------------------------------------------------------------------------- 1 | aws_cdk_lib==2.88.0 2 | aws-cdk.aws-servicecatalogappregistry-alpha==2.88.0a0 3 | aws_solutions_constructs.aws_lambda_sns==2.41.0 4 | black 5 | boto3==1.26.83 6 | click==8.1.3 7 | coverage 8 | crhelper==2.0.11 9 | docker==6.0.1 10 | flaky==3.7.0 11 | freezegun==1.2.2 12 | matplotlib==3.7.1 13 | moto 14 | numpy==1.24.2 15 | pytest>=7.3.1 16 | pytest-cov 17 | pytest-env 18 | pytest-mock==3.10.0 19 | PyYAML==6.0.0 20 | requests==2.31.0 21 | requests-mock==1.10.0 22 | responses==0.23.1 23 | tenacity==8.2.2 24 | -e cdk_solution_helper_py/helpers_cdk 25 | -e cdk_solution_helper_py/helpers_common 26 | -e infrastructure 27 | -e forecast-shared 28 | -------------------------------------------------------------------------------- /source/synthetic/__init__.py: -------------------------------------------------------------------------------- 1 | # ##################################################################################################################### 2 | # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. # 3 | # # 4 | # Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance # 5 | # with the License. You may obtain a copy of the License at # 6 | # # 7 | # http://www.apache.org/licenses/LICENSE-2.0 # 8 | # # 9 | # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed # 10 | # on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for # 11 | # the specific language governing permissions and limitations under the License. # 12 | # ##################################################################################################################### 13 | -------------------------------------------------------------------------------- /source/tests/__init__.py: -------------------------------------------------------------------------------- 1 | # ##################################################################################################################### 2 | # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. # 3 | # # 4 | # Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance # 5 | # with the License. You may obtain a copy of the License at # 6 | # # 7 | # http://www.apache.org/licenses/LICENSE-2.0 # 8 | # # 9 | # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed # 10 | # on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for # 11 | # the specific language governing permissions and limitations under the License. # 12 | # ##################################################################################################################### 13 | -------------------------------------------------------------------------------- /source/tests/glue/__init__.py: -------------------------------------------------------------------------------- 1 | # ##################################################################################################################### 2 | # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. # 3 | # # 4 | # Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance # 5 | # with the License. You may obtain a copy of the License at # 6 | # # 7 | # http://www.apache.org/licenses/LICENSE-2.0 # 8 | # # 9 | # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed # 10 | # on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for # 11 | # the specific language governing permissions and limitations under the License. # 12 | # ##################################################################################################################### 13 | -------------------------------------------------------------------------------- /source/tests/lambdas/__init__.py: -------------------------------------------------------------------------------- 1 | # ##################################################################################################################### 2 | # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. # 3 | # # 4 | # Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance # 5 | # with the License. You may obtain a copy of the License at # 6 | # # 7 | # http://www.apache.org/licenses/LICENSE-2.0 # 8 | # # 9 | # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed # 10 | # on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for # 11 | # the specific language governing permissions and limitations under the License. # 12 | # ##################################################################################################################### 13 | -------------------------------------------------------------------------------- /source/tests/lambdas/createdataset/__init__.py: -------------------------------------------------------------------------------- 1 | # ##################################################################################################################### 2 | # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. # 3 | # # 4 | # Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance # 5 | # with the License. You may obtain a copy of the License at # 6 | # # 7 | # http://www.apache.org/licenses/LICENSE-2.0 # 8 | # # 9 | # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed # 10 | # on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for # 11 | # the specific language governing permissions and limitations under the License. # 12 | # ##################################################################################################################### 13 | -------------------------------------------------------------------------------- /source/tests/lambdas/createdataset/test_handler.py: -------------------------------------------------------------------------------- 1 | # ##################################################################################################################### 2 | # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. # 3 | # # 4 | # Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance # 5 | # with the License. You may obtain a copy of the License at # 6 | # # 7 | # http://www.apache.org/licenses/LICENSE-2.0 # 8 | # # 9 | # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed # 10 | # on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for # 11 | # the specific language governing permissions and limitations under the License. # 12 | # ##################################################################################################################### 13 | -------------------------------------------------------------------------------- /source/tests/lambdas/createdatasetgroup/__init__.py: -------------------------------------------------------------------------------- 1 | # ##################################################################################################################### 2 | # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. # 3 | # # 4 | # Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance # 5 | # with the License. You may obtain a copy of the License at # 6 | # # 7 | # http://www.apache.org/licenses/LICENSE-2.0 # 8 | # # 9 | # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed # 10 | # on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for # 11 | # the specific language governing permissions and limitations under the License. # 12 | # ##################################################################################################################### 13 | -------------------------------------------------------------------------------- /source/tests/lambdas/createdatasetimportjob/__init__.py: -------------------------------------------------------------------------------- 1 | # ##################################################################################################################### 2 | # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. # 3 | # # 4 | # Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance # 5 | # with the License. You may obtain a copy of the License at # 6 | # # 7 | # http://www.apache.org/licenses/LICENSE-2.0 # 8 | # # 9 | # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed # 10 | # on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for # 11 | # the specific language governing permissions and limitations under the License. # 12 | # ##################################################################################################################### 13 | -------------------------------------------------------------------------------- /source/tests/lambdas/createdatasetimportjob/test_handler.py: -------------------------------------------------------------------------------- 1 | # ##################################################################################################################### 2 | # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. # 3 | # # 4 | # Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance # 5 | # with the License. You may obtain a copy of the License at # 6 | # # 7 | # http://www.apache.org/licenses/LICENSE-2.0 # 8 | # # 9 | # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed # 10 | # on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for # 11 | # the specific language governing permissions and limitations under the License. # 12 | # ##################################################################################################################### 13 | 14 | from moto import mock_sts 15 | 16 | from lambdas.createdatasetimportjob.handler import createdatasetimportjob 17 | from shared.status import Status 18 | 19 | 20 | @mock_sts 21 | def test_createdatasetimportjob(sfn_configuration_data, mocker): 22 | sfn_configuration_data["dataset_file"] = "train/RetailDemandTRMProphet.csv" 23 | 24 | dataset_import_job_mock = mocker.MagicMock() 25 | type(dataset_import_job_mock.return_value).status = mocker.PropertyMock( 26 | side_effect=[Status.DOES_NOT_EXIST, Status.ACTIVE] 27 | ) 28 | mocker.patch( 29 | "lambdas.createdatasetimportjob.handler.Config.dataset_import_job", 30 | dataset_import_job_mock, 31 | ) 32 | 33 | createdatasetimportjob(sfn_configuration_data, None) 34 | assert dataset_import_job_mock.return_value.create.called 35 | -------------------------------------------------------------------------------- /source/tests/lambdas/createforecast/__init__.py: -------------------------------------------------------------------------------- 1 | # ##################################################################################################################### 2 | # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. # 3 | # # 4 | # Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance # 5 | # with the License. You may obtain a copy of the License at # 6 | # # 7 | # http://www.apache.org/licenses/LICENSE-2.0 # 8 | # # 9 | # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed # 10 | # on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for # 11 | # the specific language governing permissions and limitations under the License. # 12 | # ##################################################################################################################### 13 | -------------------------------------------------------------------------------- /source/tests/lambdas/creategluetablename/__init__.py: -------------------------------------------------------------------------------- 1 | # ##################################################################################################################### 2 | # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. # 3 | # # 4 | # Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance # 5 | # with the License. You may obtain a copy of the License at # 6 | # # 7 | # http://www.apache.org/licenses/LICENSE-2.0 # 8 | # # 9 | # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed # 10 | # on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for # 11 | # the specific language governing permissions and limitations under the License. # 12 | # ##################################################################################################################### 13 | -------------------------------------------------------------------------------- /source/tests/lambdas/creategluetablename/test_handler.py: -------------------------------------------------------------------------------- 1 | # ##################################################################################################################### 2 | # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. # 3 | # # 4 | # Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance # 5 | # with the License. You may obtain a copy of the License at # 6 | # # 7 | # http://www.apache.org/licenses/LICENSE-2.0 # 8 | # # 9 | # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed # 10 | # on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for # 11 | # the specific language governing permissions and limitations under the License. # 12 | # ##################################################################################################################### 13 | 14 | import datetime 15 | 16 | from lambdas.creategluetablename.handler import creategluetablename 17 | 18 | 19 | def test_create_table_name(mocker, monkeypatch): 20 | datetime_mock = mocker.MagicMock(wraps=datetime.datetime) 21 | datetime_mock.now.return_value = datetime.datetime(2000, 1, 2, 3, 4, 5) 22 | monkeypatch.setattr("lambdas.creategluetablename.handler.datetime", datetime_mock) 23 | 24 | evt = {"dataset_group_name": "testing_123"} 25 | 26 | assert creategluetablename(evt, None) == "testing_123_2000_01_02_03_04_05" 27 | -------------------------------------------------------------------------------- /source/tests/lambdas/createpredictor/__init__.py: -------------------------------------------------------------------------------- 1 | # ##################################################################################################################### 2 | # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. # 3 | # # 4 | # Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance # 5 | # with the License. You may obtain a copy of the License at # 6 | # # 7 | # http://www.apache.org/licenses/LICENSE-2.0 # 8 | # # 9 | # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed # 10 | # on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for # 11 | # the specific language governing permissions and limitations under the License. # 12 | # ##################################################################################################################### 13 | -------------------------------------------------------------------------------- /source/tests/lambdas/createquicksightanalysis/__init__.py: -------------------------------------------------------------------------------- 1 | # ##################################################################################################################### 2 | # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. # 3 | # # 4 | # Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance # 5 | # with the License. You may obtain a copy of the License at # 6 | # # 7 | # http://www.apache.org/licenses/LICENSE-2.0 # 8 | # # 9 | # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed # 10 | # on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for # 11 | # the specific language governing permissions and limitations under the License. # 12 | # ##################################################################################################################### 13 | -------------------------------------------------------------------------------- /source/tests/lambdas/createquicksightanalysis/test_handler.py: -------------------------------------------------------------------------------- 1 | # ##################################################################################################################### 2 | # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. # 3 | # # 4 | # Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance # 5 | # with the License. You may obtain a copy of the License at # 6 | # # 7 | # http://www.apache.org/licenses/LICENSE-2.0 # 8 | # # 9 | # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed # 10 | # on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for # 11 | # the specific language governing permissions and limitations under the License. # 12 | # ##################################################################################################################### 13 | 14 | from moto import mock_sts 15 | 16 | from lambdas.createquicksightanalysis.handler import createquicksightanalysis 17 | 18 | 19 | @mock_sts 20 | def test_prepare_export(sfn_configuration_data, mocker): 21 | config_mock = mocker.MagicMock() 22 | mocker.patch("lambdas.createquicksightanalysis.handler.QuickSight", config_mock) 23 | 24 | createquicksightanalysis(sfn_configuration_data, None) 25 | 26 | assert config_mock.called 27 | assert config_mock.return_value.create_data_source.called 28 | assert config_mock.return_value.create_data_set.called 29 | assert config_mock.return_value.create_analysis.called 30 | -------------------------------------------------------------------------------- /source/tests/lambdas/notification/__init__.py: -------------------------------------------------------------------------------- 1 | # ##################################################################################################################### 2 | # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. # 3 | # # 4 | # Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance # 5 | # with the License. You may obtain a copy of the License at # 6 | # # 7 | # http://www.apache.org/licenses/LICENSE-2.0 # 8 | # # 9 | # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed # 10 | # on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for # 11 | # the specific language governing permissions and limitations under the License. # 12 | # ##################################################################################################################### 13 | -------------------------------------------------------------------------------- /source/tests/lambdas/sns/__init__.py: -------------------------------------------------------------------------------- 1 | # ##################################################################################################################### 2 | # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. # 3 | # # 4 | # Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance # 5 | # with the License. You may obtain a copy of the License at # 6 | # # 7 | # http://www.apache.org/licenses/LICENSE-2.0 # 8 | # # 9 | # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed # 10 | # on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for # 11 | # the specific language governing permissions and limitations under the License. # 12 | # ##################################################################################################################### 13 | -------------------------------------------------------------------------------- /source/tests/notebook/__init__.py: -------------------------------------------------------------------------------- 1 | # ##################################################################################################################### 2 | # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. # 3 | # # 4 | # Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance # 5 | # with the License. You may obtain a copy of the License at # 6 | # # 7 | # http://www.apache.org/licenses/LICENSE-2.0 # 8 | # # 9 | # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed # 10 | # on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for # 11 | # the specific language governing permissions and limitations under the License. # 12 | # ##################################################################################################################### 13 | -------------------------------------------------------------------------------- /source/tests/shared/__init__.py: -------------------------------------------------------------------------------- 1 | # ##################################################################################################################### 2 | # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. # 3 | # # 4 | # Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance # 5 | # with the License. You may obtain a copy of the License at # 6 | # # 7 | # http://www.apache.org/licenses/LICENSE-2.0 # 8 | # # 9 | # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed # 10 | # on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for # 11 | # the specific language governing permissions and limitations under the License. # 12 | # ##################################################################################################################### 13 | -------------------------------------------------------------------------------- /source/tests/shared/test_dataset_domain.py: -------------------------------------------------------------------------------- 1 | # ##################################################################################################################### 2 | # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. # 3 | # # 4 | # Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance # 5 | # with the License. You may obtain a copy of the License at # 6 | # # 7 | # http://www.apache.org/licenses/LICENSE-2.0 # 8 | # # 9 | # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed # 10 | # on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for # 11 | # the specific language governing permissions and limitations under the License. # 12 | # ##################################################################################################################### 13 | 14 | import pytest 15 | 16 | from shared.Dataset.dataset_domain import DatasetDomain 17 | 18 | 19 | def test_dataset_domain_valid(): 20 | valid_domains = "RETAIL | CUSTOM | INVENTORY_PLANNING | EC2_CAPACITY | WORK_FORCE | WEB_TRAFFIC | METRICS".replace( 21 | " ", "" 22 | ).split( 23 | "|" 24 | ) 25 | for domain in valid_domains: 26 | enum = DatasetDomain[domain] 27 | assert enum == domain 28 | 29 | 30 | def test_dataset_domain_invalid(): 31 | with pytest.raises(KeyError): 32 | DatasetDomain["NOT_REAL"] 33 | 34 | 35 | def test_dataset_domain_equality(): 36 | domain = DatasetDomain["RETAIL"] 37 | assert domain == "RETAIL" 38 | assert DatasetDomain.RETAIL == domain 39 | -------------------------------------------------------------------------------- /source/tests/shared/test_dataset_name.py: -------------------------------------------------------------------------------- 1 | # ##################################################################################################################### 2 | # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. # 3 | # # 4 | # Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance # 5 | # with the License. You may obtain a copy of the License at # 6 | # # 7 | # http://www.apache.org/licenses/LICENSE-2.0 # 8 | # # 9 | # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed # 10 | # on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for # 11 | # the specific language governing permissions and limitations under the License. # 12 | # ##################################################################################################################### 13 | 14 | import pytest 15 | 16 | from shared.Dataset.dataset_name import DatasetName 17 | 18 | 19 | def test_dataset_name_valid(): 20 | dsn = DatasetName("some_retail_dataset_name") 21 | assert dsn == "some_retail_dataset_name" 22 | 23 | 24 | def test_dataset_name_repr(): 25 | dsn = DatasetName("some_retail_dataset_name") 26 | assert repr(dsn) == "DatasetName(name='some_retail_dataset_name')" 27 | 28 | 29 | def test_dataset_name_invalid(): 30 | with pytest.raises(ValueError) as ex: 31 | DatasetName("Invalid-Name") 32 | 33 | assert ( 34 | str(ex.value) 35 | == "Dataset name (Invalid-Name) must match ^[a-zA-Z]\\w{0,62}$" 36 | ) 37 | 38 | 39 | def test_dataset_name_invalid_len(): 40 | name = "a" * 64 41 | with pytest.raises(ValueError) as ex: 42 | DatasetName(name) 43 | 44 | assert ( 45 | str(ex.value) 46 | == f"Dataset name ({name}) is longer than the allowed maximum length (63)" 47 | ) 48 | 49 | 50 | def test_dataset_name_equality(): 51 | name = "some_test_name" 52 | dsn = DatasetName(name) 53 | assert dsn == name 54 | --------------------------------------------------------------------------------