├── .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 ├── SECURITY.md ├── deployment └── run-unit-tests.sh └── source ├── .coveragerc ├── aws_lambda ├── __init__.py ├── create_batch_inference_job │ ├── __init__.py │ └── handler.py ├── create_batch_segment_job │ ├── __init__.py │ └── handler.py ├── create_campaign │ ├── __init__.py │ └── handler.py ├── create_config │ ├── __init__.py │ └── handler.py ├── create_dataset │ ├── __init__.py │ └── handler.py ├── create_dataset_group │ ├── __init__.py │ └── handler.py ├── create_dataset_import_job │ ├── __init__.py │ └── handler.py ├── create_event_tracker │ ├── __init__.py │ └── handler.py ├── create_filter │ ├── __init__.py │ └── handler.py ├── create_recommender │ ├── __init__.py │ └── handler.py ├── create_schema │ ├── __init__.py │ └── handler.py ├── create_solution │ ├── __init__.py │ └── handler.py ├── create_solution_version │ ├── __init__.py │ └── handler.py ├── create_timestamp │ ├── __init__.py │ └── handler.py ├── prepare_input │ ├── __init__.py │ └── handler.py ├── s3_event │ ├── __init__.py │ └── handler.py ├── shared │ ├── __init__.py │ ├── date_helpers.py │ ├── events.py │ ├── exceptions.py │ ├── notifiers │ │ ├── __init__.py │ │ ├── base.py │ │ └── notify_eventbridge.py │ ├── personalize │ │ ├── __init__.py │ │ └── service_model.py │ ├── personalize_service.py │ ├── resource │ │ ├── __init__.py │ │ ├── base.py │ │ ├── batch_inference_job.py │ │ ├── batch_segment_job.py │ │ ├── campaign.py │ │ ├── dataset.py │ │ ├── dataset_group.py │ │ ├── dataset_import_job.py │ │ ├── event_tracker.py │ │ ├── filter.py │ │ ├── name.py │ │ ├── recommender.py │ │ ├── schema.py │ │ ├── solution.py │ │ └── solution_version.py │ ├── s3.py │ └── sfn_middleware.py └── sns_notification │ ├── __init__.py │ └── handler.py ├── cdk_solution_helper_py ├── CHANGELOG.md ├── README.md ├── helpers_cdk │ ├── aws_solutions │ │ └── 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 │ │ │ ├── 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 │ │ │ │ ├── function.py │ │ │ │ ├── hash_utils.py │ │ │ │ └── layer.py │ │ │ ├── cfn_guard.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 │ └── setup.py ├── helpers_common │ ├── aws_solutions │ │ └── core │ │ │ ├── __init__.py │ │ │ ├── config.py │ │ │ ├── helpers.py │ │ │ └── logging.py │ └── setup.py └── requirements-dev.txt ├── images └── solution-architecture.png ├── infrastructure ├── __init__.py ├── aspects │ ├── __init__.py │ └── app_registry.py ├── cdk.json ├── deploy.py ├── personalize │ ├── __init__.py │ ├── aws_lambda │ │ ├── __init__.py │ │ ├── functions │ │ │ ├── __init__.py │ │ │ ├── create_batch_inference_job.py │ │ │ ├── create_batch_segment_job.py │ │ │ ├── create_campaign.py │ │ │ ├── create_config.py │ │ │ ├── create_dataset.py │ │ │ ├── create_dataset_group.py │ │ │ ├── create_dataset_import_job.py │ │ │ ├── create_event_tracker.py │ │ │ ├── create_filter.py │ │ │ ├── create_recommender.py │ │ │ ├── create_scheduled_task.py │ │ │ ├── create_schema.py │ │ │ ├── create_solution.py │ │ │ ├── create_solution_version.py │ │ │ ├── create_timestamp.py │ │ │ ├── environment.py │ │ │ ├── prepare_input.py │ │ │ └── s3_event.py │ │ └── layers │ │ │ ├── __init__.py │ │ │ └── aws_solutions │ │ │ ├── __init__.py │ │ │ ├── layer.py │ │ │ └── requirements │ │ │ └── requirements.txt │ ├── cloudwatch │ │ ├── __init__.py │ │ └── dashboard.py │ ├── s3 │ │ ├── __init__.py │ │ ├── access_logs_bucket.py │ │ ├── data_bucket.py │ │ └── utils.py │ ├── sns │ │ ├── __init__.py │ │ └── notifications.py │ ├── stack.py │ └── step_functions │ │ ├── __init__.py │ │ ├── batch_inference_jobs_fragment.py │ │ ├── batch_segment_jobs_fragment.py │ │ ├── dataset_import_fragment.py │ │ ├── dataset_imports_fragment.py │ │ ├── event_tracker_fragment.py │ │ ├── failure_fragment.py │ │ ├── filter_fragment.py │ │ ├── personalization_fragment.py │ │ ├── scheduled_dataset_import.py │ │ ├── scheduled_solution_maintenance.py │ │ ├── scheduler_fragment.py │ │ ├── schedules.py │ │ └── solution_fragment.py └── setup.py ├── pytest.ini ├── requirements-dev.txt ├── scheduler ├── CHANGELOG.md ├── README.md ├── cdk │ ├── aws_solutions │ │ └── scheduler │ │ │ └── cdk │ │ │ ├── __init__.py │ │ │ ├── aws_lambda │ │ │ ├── __init__.py │ │ │ ├── create_scheduled_task.py │ │ │ ├── delete_scheduled_task.py │ │ │ ├── get_next_scheduled_event │ │ │ │ ├── build.gradle │ │ │ │ ├── gradle │ │ │ │ │ └── wrapper │ │ │ │ │ │ ├── gradle-wrapper.jar │ │ │ │ │ │ └── gradle-wrapper.properties │ │ │ │ ├── gradlew │ │ │ │ ├── settings.gradle │ │ │ │ └── src │ │ │ │ │ ├── main │ │ │ │ │ └── java │ │ │ │ │ │ └── com │ │ │ │ │ │ └── amazonaws │ │ │ │ │ │ └── solutions │ │ │ │ │ │ └── schedule_sfn_task │ │ │ │ │ │ ├── HandleScheduleEvent.java │ │ │ │ │ │ ├── ScheduleEvent.java │ │ │ │ │ │ └── ScheduleException.java │ │ │ │ │ └── test │ │ │ │ │ └── java │ │ │ │ │ └── com │ │ │ │ │ └── amazonaws │ │ │ │ │ └── solutions │ │ │ │ │ └── schedule_sfn_task │ │ │ │ │ └── HandleScheduleEventTest.java │ │ │ ├── read_scheduled_task.py │ │ │ ├── scheduler │ │ │ │ ├── __init__.py │ │ │ │ ├── handler.py │ │ │ │ └── requirements.txt │ │ │ └── update_scheduled_task.py │ │ │ ├── construct.py │ │ │ └── scheduler_fragment.py │ └── setup.py └── common │ ├── aws_solutions │ └── scheduler │ │ └── common │ │ ├── __init__.py │ │ ├── base.py │ │ ├── schedule.py │ │ ├── scripts │ │ ├── __init__.py │ │ └── scheduler_cli.py │ │ ├── task.py │ │ └── task_resource.py │ └── setup.py └── tests ├── __init__.py ├── aspects ├── __init__.py └── test_personalize_app_stack.py ├── aws_lambda ├── __init__.py ├── create_batch_inference_job │ ├── __init__.py │ └── test_batch_inference_job_handler.py ├── create_batch_segment_job │ ├── __init__.py │ └── test_batch_segment_job_handler.py ├── create_campaign │ ├── __init__.py │ └── test_create_campaign_handler.py ├── create_config │ ├── __init__.py │ └── test_create_config_handler.py ├── create_dataset │ ├── __init__.py │ └── test_dataset_handler.py ├── create_dataset_group │ ├── __init__.py │ └── test_dataset_group_handler.py ├── create_dataset_import_job │ ├── __init__.py │ └── test_dataset_import_job_handler.py ├── create_event_tracker │ ├── __init__.py │ └── test_create_event_tracker_handler.py ├── create_filter │ ├── __init__.py │ └── test_create_filter_handler.py ├── create_recommender │ ├── __init__.py │ └── test_create_recommender_handler.py ├── create_schema │ ├── __init__.py │ └── create_schema_handler.py ├── create_solution │ ├── __init__.py │ └── test_create_solution_handler.py ├── create_solution_version │ ├── __init__.py │ └── test_create_solution_version_handler.py ├── s3_event │ └── test_s3_event_handler.py ├── sns_notification │ └── test_sns_notification.py ├── test_events.py ├── test_personalize_service.py └── test_sfn_middleware.py ├── cdk_solution_helper ├── __init__.py ├── aws_lambda │ ├── cfn_custom_resources │ │ ├── resource_hash │ │ │ ├── test_resource_name.py │ │ │ └── test_resource_name_cdk.py │ │ ├── resource_name │ │ │ ├── test_resource_hash.py │ │ │ └── test_resource_hash_cdk.py │ │ └── solution_metrics │ │ │ ├── test_metrics_cdk.py │ │ │ └── test_metrics_resource.py │ ├── java │ │ ├── fixtures │ │ │ └── java_sample │ │ │ │ ├── build.gradle │ │ │ │ ├── gradle │ │ │ │ └── wrapper │ │ │ │ │ ├── gradle-wrapper.jar │ │ │ │ │ └── gradle-wrapper.properties │ │ │ │ ├── gradlew │ │ │ │ ├── settings.gradle │ │ │ │ └── src │ │ │ │ ├── main │ │ │ │ ├── java │ │ │ │ │ └── example │ │ │ │ │ │ ├── Handler.java │ │ │ │ │ │ └── UserData.java │ │ │ │ └── main.iml │ │ │ │ └── test │ │ │ │ ├── java │ │ │ │ └── example │ │ │ │ │ └── HandlerTest.java │ │ │ │ └── test1.iml │ │ └── test_java_function.py │ └── python │ │ ├── fixtures │ │ ├── Pipfile │ │ ├── hash_fixture │ │ │ ├── a │ │ │ │ └── z.txt │ │ │ ├── c.txt │ │ │ └── z │ │ │ │ └── a.txt │ │ ├── lambda │ │ │ └── package │ │ │ │ ├── minimal │ │ │ │ └── __init__.py │ │ │ │ └── setup.py │ │ ├── packages │ │ │ └── package2 │ │ │ │ ├── minimal2 │ │ │ │ └── __init__.py │ │ │ │ └── setup.py │ │ ├── pyproject.toml │ │ └── requirements.txt │ │ ├── test_function.py │ │ └── test_layer_version.py ├── helpers │ ├── test_load_cdk_app.py │ └── test_logger.py ├── test_aspects.py ├── test_build_s3_cdk_dist.py ├── test_cdk_context.py ├── test_cdk_interfaces.py ├── test_cfn_nag_suppressions.py ├── test_helpers.py ├── test_interfaces.py ├── test_logging.py ├── test_mappings.py ├── test_solution_config.py ├── test_stack.py ├── test_synthesizers.py └── tools │ └── test_cleaner.py ├── conftest.py ├── fixtures └── config │ ├── interactions.csv │ ├── sample_config.json │ ├── sample_config_root_tags.json │ ├── sample_config_wtags.json │ └── users.csv ├── test_deploy.py ├── test_notifies.py ├── test_personalize_stack.py ├── test_resources.py ├── test_scheduler.py └── test_scheduler_cli.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. v0.0.1] 21 | 22 | To get the version of the solution, you can look at the description of the created CloudFormation stack. For example, "(SO0170) Maintaining Personalized Experiences with Machine Learning [...]". 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 sevices 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 | .python-version 24 | pyvenv.cfg 25 | 26 | ## Python Testing 27 | **/.pytest_cache 28 | **/.coverage 29 | **/coverage-reports/ 30 | .coverage.* 31 | 32 | # linting, scanning configurations, sonarqube 33 | .scannerwork/ 34 | 35 | ### VisualStudioCode ### 36 | .vscode/* 37 | 38 | ### IntelliJ/ PyCharm ### 39 | **/.idea/* 40 | 41 | # System Files 42 | **/.DS_Store 43 | 44 | # CDK 45 | **/cdk.out 46 | 47 | # Glue 48 | .glue/* 49 | 50 | # Generated test assets 51 | source/infrastructure/tests/assets/* 52 | !source/infrastructure/tests/assets/.keep 53 | source/scheduler/cdk/aws_solutions/scheduler/cdk/aws_lambda/get_next_scheduled_event/build 54 | source/scheduler/cdk/aws_solutions/scheduler/cdk/aws_lambda/get_next_scheduled_event/.gradle 55 | source/scheduler/cdk/aws_solutions/scheduler/cdk/aws_lambda/get_next_scheduled_event/.idea 56 | 57 | # gradle build files 58 | **/.gradle/* 59 | 60 | # java build files 61 | **/java/**/build 62 | 63 | # python build files 64 | source/cdk_solution_helper_py/helpers_cdk/build/* 65 | source/cdk_solution_helper_py/helpers_common/build/* 66 | source/scheduler/common/build/* 67 | source/scheduler/cdk/build/* 68 | -------------------------------------------------------------------------------- /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. -------------------------------------------------------------------------------- /SECURITY.md: -------------------------------------------------------------------------------- 1 | ## Reporting Security Issues 2 | 3 | We take all security reports seriously. When we receive such reports, 4 | we will investigate and subsequently address any potential vulnerabilities as 5 | quickly as possible. If you discover a potential security issue in this project, 6 | please notify AWS/Amazon Security via our [vulnerability reporting page] 7 | (http://aws.amazon.com/security/vulnerability-reporting/) or directly via email 8 | to [AWS Security](mailto:aws-security@amazon.com). 9 | Please do *not* create a public GitHub issue in this project. -------------------------------------------------------------------------------- /source/.coveragerc: -------------------------------------------------------------------------------- 1 | [run] 2 | omit = 3 | infrastructure/setup.py 4 | infrastructure/cdk.out/* 5 | tests/* 6 | source = 7 | infrastructure 8 | aws_lambda 9 | cdk_solution_helper_py 10 | scheduler 11 | 12 | [report] 13 | fail_under = 80.0 -------------------------------------------------------------------------------- /source/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/aws_lambda/create_batch_inference_job/__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/aws_lambda/create_batch_segment_job/__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/aws_lambda/create_campaign/__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/aws_lambda/create_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/aws_lambda/create_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/aws_lambda/create_dataset_group/__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/aws_lambda/create_dataset_import_job/__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/aws_lambda/create_event_tracker/__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/aws_lambda/create_filter/__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/aws_lambda/create_recommender/__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/aws_lambda/create_schema/__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/aws_lambda/create_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/aws_lambda/create_solution_version/__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/aws_lambda/create_timestamp/__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/aws_lambda/create_timestamp/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 | from typing import Dict, Any 16 | 17 | from aws_lambda_powertools import Logger, Tracer 18 | from aws_lambda_powertools.utilities.typing import LambdaContext 19 | 20 | logger = Logger() 21 | tracer = Tracer() 22 | 23 | 24 | @tracer.capture_lambda_handler 25 | def lambda_handler(event: Dict[str, Any], context: LambdaContext) -> str: 26 | """Create a timestamp matching YYYY_mm_dd_HH_MM_SS 27 | :param event: AWS Lambda Event 28 | :param context: AWS Lambda Context 29 | :return: the timestamp (string) 30 | """ 31 | return datetime.datetime.now().strftime("%Y_%m_%d_%H_%M_%S") 32 | -------------------------------------------------------------------------------- /source/aws_lambda/prepare_input/__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/aws_lambda/prepare_input/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 typing import Dict, Any 15 | 16 | from aws_lambda_powertools import Logger, Tracer, Metrics 17 | from aws_lambda_powertools.utilities.typing import LambdaContext 18 | 19 | from shared.sfn_middleware import set_workflow_config 20 | 21 | logger = Logger() 22 | tracer = Tracer() 23 | metrics = Metrics() 24 | 25 | 26 | def lambda_handler(event: Dict[str, Any], _) -> Dict: 27 | """Add timeStarted to the workflowConfig of all items 28 | :param event: AWS Lambda Event 29 | :param context: AWS Lambda Context 30 | :return: the modified input 31 | """ 32 | config = set_workflow_config(event) 33 | return config 34 | -------------------------------------------------------------------------------- /source/aws_lambda/s3_event/__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/aws_lambda/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/aws_lambda/shared/date_helpers.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 | import parsedatetime as pdt 17 | from aws_lambda_powertools import Logger 18 | 19 | logger = Logger() 20 | 21 | 22 | def parse_datetime(tm: str) -> int: 23 | if "month" in tm: 24 | logger.warning("while months are supported, they are based off of the calendar of the start of year 1 CE") 25 | if "year" in tm: 26 | logger.warning("while years are supported, they are based off of the calendar of the start of year 1 CE") 27 | 28 | start_of_time = datetime.datetime.min 29 | cal = pdt.Calendar(version=pdt.VERSION_CONTEXT_STYLE) 30 | timedelta = cal.parseDT(tm, sourceTime=start_of_time)[0] - start_of_time 31 | return int(timedelta.total_seconds()) 32 | -------------------------------------------------------------------------------- /source/aws_lambda/shared/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 ResourcePending(Exception): 16 | pass 17 | 18 | 19 | class SolutionVersionPending(Exception): 20 | pass 21 | 22 | 23 | class ResourceFailed(Exception): 24 | pass 25 | 26 | 27 | class ResourceInvalid(Exception): 28 | pass 29 | 30 | 31 | class ResourceNeedsUpdate(Exception): 32 | pass 33 | 34 | 35 | class NotificationError(Exception): 36 | pass 37 | -------------------------------------------------------------------------------- /source/aws_lambda/shared/notifiers/__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 shared.notifiers.notify_eventbridge import NotifyEventBridge 15 | -------------------------------------------------------------------------------- /source/aws_lambda/shared/personalize/__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/aws_lambda/shared/resource/batch_inference_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 | from shared.resource.base import Resource 14 | 15 | 16 | class BatchInferenceJob(Resource): 17 | pass 18 | -------------------------------------------------------------------------------- /source/aws_lambda/shared/resource/batch_segment_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 | from shared.resource.base import Resource 14 | 15 | 16 | class BatchSegmentJob(Resource): 17 | pass 18 | -------------------------------------------------------------------------------- /source/aws_lambda/shared/resource/campaign.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.resource.base import Resource 14 | 15 | 16 | class Campaign(Resource): 17 | pass 18 | -------------------------------------------------------------------------------- /source/aws_lambda/shared/resource/dataset.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.resource.base import Resource 14 | from shared.resource.dataset_import_job import DatasetImportJob 15 | 16 | 17 | class Dataset(Resource): 18 | children = [DatasetImportJob()] 19 | allowed_types = {"INTERACTIONS", "ITEMS", "USERS"} 20 | -------------------------------------------------------------------------------- /source/aws_lambda/shared/resource/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 | from shared.resource.base import Resource 14 | from shared.resource.dataset import Dataset 15 | from shared.resource.event_tracker import EventTracker 16 | from shared.resource.filter import Filter 17 | from shared.resource.recommender import Recommender 18 | from shared.resource.solution import Solution 19 | 20 | 21 | class DatasetGroup(Resource): 22 | children = [Dataset(), Filter(), Solution(), Recommender(), EventTracker()] 23 | -------------------------------------------------------------------------------- /source/aws_lambda/shared/resource/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 | from shared.resource.base import Resource 14 | 15 | 16 | class DatasetImportJob(Resource): 17 | has_soft_limit = True 18 | -------------------------------------------------------------------------------- /source/aws_lambda/shared/resource/event_tracker.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.resource.base import Resource 14 | 15 | 16 | class EventTracker(Resource): 17 | pass 18 | -------------------------------------------------------------------------------- /source/aws_lambda/shared/resource/filter.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.resource.base import Resource 14 | 15 | 16 | class Filter(Resource): 17 | pass 18 | -------------------------------------------------------------------------------- /source/aws_lambda/shared/resource/recommender.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.resource.base import Resource 14 | from shared.resource.batch_inference_job import BatchInferenceJob 15 | from shared.resource.batch_segment_job import BatchSegmentJob 16 | 17 | 18 | class Recommender(Resource): 19 | children = [BatchInferenceJob(), BatchSegmentJob()] 20 | -------------------------------------------------------------------------------- /source/aws_lambda/shared/resource/schema.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.resource import Resource 14 | 15 | 16 | class Schema(Resource): 17 | pass 18 | -------------------------------------------------------------------------------- /source/aws_lambda/shared/resource/solution.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.resource.base import Resource 14 | from shared.resource.campaign import Campaign 15 | from shared.resource.solution_version import SolutionVersion 16 | 17 | 18 | class Solution(Resource): 19 | children = [Campaign(), SolutionVersion()] 20 | -------------------------------------------------------------------------------- /source/aws_lambda/shared/resource/solution_version.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.resource.base import Resource 14 | from shared.resource.batch_inference_job import BatchInferenceJob 15 | from shared.resource.batch_segment_job import BatchSegmentJob 16 | 17 | 18 | class SolutionVersion(Resource): 19 | children = [BatchInferenceJob(), BatchSegmentJob()] 20 | has_soft_limit = True 21 | -------------------------------------------------------------------------------- /source/aws_lambda/sns_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/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 | ## [2.0.0] - 2022-01-31 8 | ### Changed 9 | - support for CDK 2.x added, support for CDK 1.x removed 10 | 11 | ## [1.0.0] - 2021-09-23 12 | ### Added 13 | - initial release 14 | 15 | -------------------------------------------------------------------------------- /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 aws_cdk import CfnCondition, IAspect 15 | from constructs import IConstruct 16 | 17 | 18 | @jsii.implements(IAspect) 19 | class ConditionalResources: 20 | """Mark any CDK construct as conditional (this is useful to apply to stacks and L2+ constructs)""" 21 | 22 | def __init__(self, condition: CfnCondition): 23 | self.condition = condition 24 | 25 | def visit(self, node: IConstruct): 26 | if "is_cfn_element" in dir(node) and node.is_cfn_element(node): 27 | node.cfn_options.condition = self.condition 28 | elif "is_cfn_element" in dir(node.node.default_child): 29 | node.node.default_child.cfn_options.condition = self.condition 30 | -------------------------------------------------------------------------------- /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 | requests==2.32.0 2 | urllib3==1.26.19 3 | crhelper==2.0.11 4 | -------------------------------------------------------------------------------- /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 | 19 | @dataclass 20 | class EnvironmentVariable: 21 | scope: IFunction 22 | name: str 23 | value: str = field(default="") 24 | 25 | def __post_init__(self): 26 | if not self.value: 27 | self.value = self.scope.node.try_get_context(self.name) 28 | self.scope.add_environment(self.name, self.value) 29 | 30 | def __str__(self): 31 | return self.value 32 | -------------------------------------------------------------------------------- /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 | 16 | from aws_cdk import Stack 17 | from constructs import Construct 18 | 19 | from aws_solutions.cdk.aws_lambda.python.layer import SolutionsPythonLayerVersion 20 | 21 | 22 | class PowertoolsLayer(SolutionsPythonLayerVersion): 23 | def __init__(self, scope: Construct, construct_id: str, **kwargs): 24 | requirements_path: Path = Path(__file__).absolute().parent / "requirements" 25 | super().__init__(scope, construct_id, requirements_path, **kwargs) 26 | 27 | @staticmethod 28 | def get_or_create(scope: Construct, **kwargs): 29 | stack = Stack.of(scope) 30 | construct_id = "PowertoolsLayer-8E932F0F-197D-4026-A354-23D184C2A624" 31 | exists = stack.node.try_find_child(construct_id) 32 | if exists: 33 | return exists 34 | return PowertoolsLayer(stack, construct_id, **kwargs) 35 | -------------------------------------------------------------------------------- /source/cdk_solution_helper_py/helpers_cdk/aws_solutions/cdk/aws_lambda/layers/aws_lambda_powertools/requirements/requirements.txt: -------------------------------------------------------------------------------- 1 | aws-lambda-powertools==2.15.0 2 | aws-xray-sdk==2.12.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/cfn_guard.py: -------------------------------------------------------------------------------- 1 | # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | # SPDX-License-Identifier: Apache-2.0 3 | 4 | from dataclasses import dataclass 5 | from typing import List 6 | 7 | import jsii 8 | from aws_cdk import CfnResource, IAspect 9 | from constructs import IConstruct 10 | 11 | 12 | def add_cfn_guard_suppressions( 13 | resource: CfnResource, suppressions: List[str] 14 | ): 15 | if resource.node.default_child: 16 | resource.node.default_child.add_metadata( 17 | "guard", 18 | { 19 | "SuppressedRules": suppressions 20 | }, 21 | ) 22 | else: 23 | resource.add_metadata( 24 | "guard", 25 | { 26 | "SuppressedRules": suppressions 27 | }, 28 | ) 29 | 30 | @jsii.implements(IAspect) 31 | class CfnGuardSuppressResourceList: 32 | """Suppress certain cfn_guard warnings that can be ignored by this solution""" 33 | 34 | def __init__(self, resource_suppressions: dict): 35 | self.resource_suppressions = resource_suppressions 36 | 37 | def visit(self, node: IConstruct): 38 | if "is_cfn_element" in dir(node) and \ 39 | node.is_cfn_element(node) and \ 40 | getattr(node, "cfn_resource_type", None) is not None and \ 41 | node.cfn_resource_type in self.resource_suppressions: 42 | add_cfn_guard_suppressions(node, self.resource_suppressions[node.cfn_resource_type]) 43 | elif "is_cfn_element" in dir(node.node.default_child) and \ 44 | getattr(node.node.default_child, "cfn_resource_type", None) is not None and \ 45 | node.node.default_child.cfn_resource_type in self.resource_suppressions: 46 | add_cfn_guard_suppressions(node.node.default_child, self.resource_suppressions[node.node.default_child.cfn_resource_type]) -------------------------------------------------------------------------------- /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_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 | black 4 | boto3==1.26.47 5 | requests==2.32.0 6 | crhelper==2.0.11 7 | Click==8.1.3 8 | moto==2.3.0 9 | pipenv 10 | poetry==1.6.1 11 | pytest==7.4.4 12 | pytest-cov==4.1.0 13 | pytest-mock==3.12.0 14 | tox==4.11.4 15 | tox-pyenv 16 | -e ./source/cdk_solution_helper_py/helpers_cdk 17 | -e ./source/cdk_solution_helper_py/helpers_common 18 | -------------------------------------------------------------------------------- /source/images/solution-architecture.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aws-solutions/maintaining-personalized-experiences-with-machine-learning/5f170385f706eea36472dee57593c112f679c30f/source/images/solution-architecture.png -------------------------------------------------------------------------------- /source/infrastructure/__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/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 | # ##################################################################################################################### 13 | -------------------------------------------------------------------------------- /source/infrastructure/cdk.json: -------------------------------------------------------------------------------- 1 | { 2 | "app": "python3 deploy.py", 3 | "context": { 4 | "SOLUTION_NAME": "Maintaining Personalized Experiences with Machine Learning", 5 | "SOLUTION_ID": "SO0170", 6 | "SOLUTION_VERSION": "v1.4.5", 7 | "APP_REGISTRY_NAME": "personalized-experiences-ML", 8 | "APPLICATION_TYPE": "AWS-Solutions", 9 | "@aws-cdk/aws-s3:serverAccessLogsUseBucketPolicy": true 10 | } 11 | } -------------------------------------------------------------------------------- /source/infrastructure/personalize/__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/personalize/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/personalize/aws_lambda/functions/create_scheduled_task.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 | 15 | from constructs import Construct 16 | 17 | from aws_solutions.cdk.stepfunctions.solutionstep import SolutionStep 18 | from aws_solutions.cdk.cfn_guard import add_cfn_guard_suppressions 19 | 20 | class CreateScheduledTask(SolutionStep): 21 | def __init__( 22 | self, 23 | scope: Construct, 24 | id: str, 25 | layers=None, 26 | ): 27 | super().__init__( 28 | scope, 29 | id, 30 | layers=layers, 31 | entrypoint=(Path(__file__).absolute().parents[4] / "aws_lambda" / "create_scheduled_task" / "handler.py"), 32 | libraries=[Path(__file__).absolute().parents[4] / "aws_lambda" / "shared"], 33 | ) 34 | 35 | add_cfn_guard_suppressions( 36 | self.function.role.node.try_find_child("Resource"), 37 | ["IAM_NO_INLINE_POLICY_CHECK"] 38 | ) 39 | 40 | def _set_permissions(self): 41 | pass # NOSONAR (python:S1186) - no permissions required 42 | -------------------------------------------------------------------------------- /source/infrastructure/personalize/aws_lambda/functions/create_timestamp.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 | 15 | from constructs import Construct 16 | 17 | from aws_solutions.cdk.stepfunctions.solutionstep import SolutionStep 18 | from aws_solutions.cdk.cfn_guard import add_cfn_guard_suppressions 19 | 20 | 21 | class CreateTimestamp(SolutionStep): 22 | def __init__( 23 | self, 24 | scope: Construct, 25 | id: str, 26 | layers=None, 27 | ): 28 | super().__init__( 29 | scope, 30 | id, 31 | layers=layers, 32 | entrypoint=(Path(__file__).absolute().parents[4] / "aws_lambda" / "create_timestamp" / "handler.py"), 33 | ) 34 | 35 | add_cfn_guard_suppressions( 36 | self.function.role.node.try_find_child("Resource"), 37 | ["IAM_NO_INLINE_POLICY_CHECK"] 38 | ) 39 | 40 | def _set_permissions(self): 41 | pass # NOSONAR (python:S1186) - no permissions required 42 | -------------------------------------------------------------------------------- /source/infrastructure/personalize/aws_lambda/functions/prepare_input.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 | 18 | from aws_solutions.cdk.stepfunctions.solutionstep import SolutionStep 19 | from aws_solutions.cdk.cfn_guard import add_cfn_guard_suppressions 20 | 21 | class PrepareInput(SolutionStep): 22 | def __init__( 23 | self, 24 | scope: Construct, 25 | id: str, 26 | layers=None, 27 | ): 28 | super().__init__( 29 | scope, 30 | id, 31 | layers=layers, 32 | entrypoint=(Path(__file__).absolute().parents[4] / "aws_lambda" / "prepare_input" / "handler.py"), 33 | libraries=[Path(__file__).absolute().parents[4] / "aws_lambda" / "shared"], 34 | ) 35 | 36 | add_cfn_guard_suppressions( 37 | self.function.role.node.try_find_child("Resource"), 38 | ["IAM_NO_INLINE_POLICY_CHECK"] 39 | ) 40 | 41 | def _set_permissions(self): 42 | pass # NOSONAR (python:S1186) - no permissions required 43 | -------------------------------------------------------------------------------- /source/infrastructure/personalize/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 personalize.aws_lambda.layers.aws_solutions.layer import SolutionsLayer 15 | -------------------------------------------------------------------------------- /source/infrastructure/personalize/aws_lambda/layers/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/infrastructure/personalize/aws_lambda/layers/aws_solutions/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 aws_cdk import Stack 17 | from constructs import Construct 18 | 19 | from aws_solutions.cdk.aws_lambda.python.layer import SolutionsPythonLayerVersion 20 | 21 | 22 | class SolutionsLayer(SolutionsPythonLayerVersion): 23 | def __init__(self, scope: Construct, construct_id: str, **kwargs): 24 | requirements_path: Path = Path(__file__).absolute().parent / "requirements" 25 | super().__init__(scope, construct_id, requirements_path, **kwargs) 26 | 27 | @staticmethod 28 | def get_or_create(scope: Construct, **kwargs): 29 | stack = Stack.of(scope) 30 | construct_id = "SolutionsLayer-DAE8E12F-3DEA-43FB-A4AA-E55AC50BD2E9" 31 | exists = stack.node.try_find_child(construct_id) 32 | if exists: 33 | return exists 34 | return SolutionsLayer(stack, construct_id, **kwargs) 35 | -------------------------------------------------------------------------------- /source/infrastructure/personalize/aws_lambda/layers/aws_solutions/requirements/requirements.txt: -------------------------------------------------------------------------------- 1 | ../../../../../../cdk_solution_helper_py/helpers_common 2 | ../../../../../../scheduler/common 3 | avro==1.11.3 4 | cronex==0.1.3.1 5 | jmespath==1.0.1 6 | parsedatetime==2.6 7 | boto3==1.26.47 8 | -------------------------------------------------------------------------------- /source/infrastructure/personalize/cloudwatch/__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/personalize/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 | 14 | from personalize.s3.access_logs_bucket import AccessLogsBucket 15 | from personalize.s3.data_bucket import DataBucket 16 | -------------------------------------------------------------------------------- /source/infrastructure/personalize/s3/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 | 14 | from personalize.s3.utils import SecureBucket 15 | 16 | 17 | class AccessLogsBucket(SecureBucket): 18 | pass 19 | -------------------------------------------------------------------------------- /source/infrastructure/personalize/s3/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 personalize.s3.utils import SecureBucket 15 | 16 | 17 | class DataBucket(SecureBucket): 18 | pass 19 | -------------------------------------------------------------------------------- /source/infrastructure/personalize/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/personalize/step_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 | -------------------------------------------------------------------------------- /source/infrastructure/personalize/step_functions/dataset_imports_fragment.py: -------------------------------------------------------------------------------- 1 | from typing import List 2 | 3 | from aws_cdk.aws_stepfunctions import ( 4 | StateMachineFragment, 5 | Chain, 6 | Parallel, 7 | JsonPath, 8 | State, 9 | INextable, 10 | ) 11 | from constructs import Construct 12 | 13 | from personalize.aws_lambda.functions import ( 14 | CreateSchema, 15 | CreateDataset, 16 | CreateDatasetImportJob, 17 | ) 18 | from personalize.step_functions.dataset_import_fragment import DatasetImportFragment 19 | 20 | 21 | class DatasetImportsFragment(StateMachineFragment): 22 | def __init__( 23 | self, 24 | scope: Construct, 25 | construct_id: str, 26 | create_schema: CreateSchema, 27 | create_dataset: CreateDataset, 28 | create_dataset_import_job: CreateDatasetImportJob, 29 | ): 30 | super().__init__(scope, construct_id) 31 | 32 | dataset_management_functions = { 33 | "create_schema": create_schema, 34 | "create_dataset": create_dataset, 35 | "create_dataset_import_job": create_dataset_import_job, 36 | } 37 | 38 | self.chain = Chain.start( 39 | Parallel(self, "Create and Import Datasets", result_path=JsonPath.DISCARD) 40 | .branch(DatasetImportFragment(self, "Interactions", **dataset_management_functions)) 41 | .branch(DatasetImportFragment(self, "Users", **dataset_management_functions)) 42 | .branch(DatasetImportFragment(self, "Items", **dataset_management_functions)) 43 | ) 44 | 45 | @property 46 | def start_state(self) -> State: 47 | return self.chain.start_state 48 | 49 | @property 50 | def end_states(self) -> List[INextable]: 51 | return self.chain.end_states 52 | -------------------------------------------------------------------------------- /source/infrastructure/personalize/step_functions/schedules.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 15 | 16 | from aws_cdk.aws_stepfunctions import StateMachineFragment 17 | 18 | 19 | @dataclass 20 | class Schedules: 21 | dataset_import: StateMachineFragment 22 | -------------------------------------------------------------------------------- /source/pytest.ini: -------------------------------------------------------------------------------- 1 | [pytest] 2 | env = 3 | MOTO_ACCOUNT_ID=111111111111 4 | POWERTOOLS_TRACE_DISABLED=1 5 | SOLUTION_ID=SO0170test 6 | SOLUTION_VERSION=v99.99.99 7 | SOLUTION_NAME=Maintaining Personalized Experiences with Machine Learning 8 | APP_REGISTRY_NAME=personalized-experiences-ML 9 | APPLICATION_TYPE=AWS-Solutions 10 | AWS_REGION=us-east-1 11 | AWS_DEFAULT_REGION=us-east-1 12 | DDB_SCHEDULES_TABLE=scheduler 13 | DDB_SCHEDULER_STEPFUNCTION=arn:aws:states:us-east-1:111111111111:stateMachine:personalizestack-personalize-scheduler 14 | POWERTOOLS_SERVICE_NAME=personalize_solution_teststack 15 | POWERTOOLS_METRICS_NAMESPACE=personalize_solution_teststack 16 | norecursedirs = cdk.out* 17 | markers= 18 | no_cdk_lambda_mock: marks test that need to build AWS Lambda Functions or Layers with CDK -------------------------------------------------------------------------------- /source/requirements-dev.txt: -------------------------------------------------------------------------------- 1 | avro==1.11.3 2 | black==24.3.0 3 | boto3==1.26.47 4 | aws_cdk_lib==2.88.0 5 | aws_solutions_constructs.aws_lambda_sns==2.41.0 6 | aws-cdk.aws-servicecatalogappregistry-alpha==2.88.0a0 7 | cdk-nag==2.27.107 8 | requests==2.32.0 9 | crhelper==2.0.11 10 | cronex==0.1.3.1 11 | moto==2.3.0 12 | parsedatetime==2.6 13 | pytest==7.4.4 14 | pytest-cov==4.1.0 15 | pytest-env==1.1.3 16 | pytest-mock==3.12.0 17 | pyyaml==6.0.2 18 | responses==0.17.0 19 | tenacity==8.0.1 20 | -e cdk_solution_helper_py/helpers_cdk 21 | -e cdk_solution_helper_py/helpers_common 22 | -e scheduler/cdk 23 | -e scheduler/common 24 | docker==6.0.0 25 | -e infrastructure -------------------------------------------------------------------------------- /source/scheduler/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 | ## [2.0.0] - 2022-01-31 8 | ### Changed 9 | - support for CDK 2.x added, support for CDK 1.x removed 10 | 11 | ## [1.1.0] - 2021-11-11 12 | ### Added 13 | - initial release 14 | 15 | -------------------------------------------------------------------------------- /source/scheduler/cdk/aws_solutions/scheduler/cdk/__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/scheduler/cdk/aws_solutions/scheduler/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 | 14 | from aws_solutions.scheduler.cdk.aws_lambda.create_scheduled_task import ( 15 | CreateScheduledTask, 16 | ) 17 | from aws_solutions.scheduler.cdk.aws_lambda.delete_scheduled_task import ( 18 | DeleteScheduledTask, 19 | ) 20 | from aws_solutions.scheduler.cdk.aws_lambda.read_scheduled_task import ReadScheduledTask 21 | from aws_solutions.scheduler.cdk.aws_lambda.update_scheduled_task import ( 22 | UpdateScheduledTask, 23 | ) 24 | -------------------------------------------------------------------------------- /source/scheduler/cdk/aws_solutions/scheduler/cdk/aws_lambda/get_next_scheduled_event/build.gradle: -------------------------------------------------------------------------------- 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 | plugins { 15 | id 'java' 16 | id 'jacoco' 17 | id 'org.sonarqube' version '3.3' 18 | } 19 | 20 | group 'com.amazonaws.solutions' 21 | version '1.0-SNAPSHOT' 22 | 23 | repositories { 24 | mavenCentral() 25 | } 26 | 27 | dependencies { 28 | testImplementation 'org.junit.jupiter:junit-jupiter-api:5.7.0' 29 | testImplementation 'org.junit.jupiter:junit-jupiter-params:5.7.0' 30 | testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.7.0' 31 | implementation 'com.amazonaws:aws-lambda-java-core:1.2.1' 32 | implementation platform('com.amazonaws:aws-java-sdk-bom:1.11.1000') 33 | implementation 'org.quartz-scheduler:quartz:2.3.2' 34 | } 35 | 36 | java { 37 | sourceCompatibility = JavaVersion.VERSION_11 38 | targetCompatibility = JavaVersion.VERSION_11 39 | } 40 | 41 | jacocoTestReport { 42 | reports { 43 | xml.enabled true 44 | csv.enabled false 45 | html.enabled false 46 | } 47 | } 48 | 49 | test { 50 | useJUnitPlatform() 51 | } 52 | test.finalizedBy jacocoTestReport 53 | 54 | sonarqube { 55 | properties { 56 | property "sonar.sourceEncoding", "UTF-8" 57 | } 58 | } 59 | 60 | tasks.named('sonarqube').configure { 61 | dependsOn test 62 | } 63 | 64 | task buildZip(type: Zip) { 65 | from compileJava 66 | from processResources 67 | into('lib') { 68 | from configurations.runtimeClasspath 69 | } 70 | } 71 | 72 | build.dependsOn buildZip -------------------------------------------------------------------------------- /source/scheduler/cdk/aws_solutions/scheduler/cdk/aws_lambda/get_next_scheduled_event/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aws-solutions/maintaining-personalized-experiences-with-machine-learning/5f170385f706eea36472dee57593c112f679c30f/source/scheduler/cdk/aws_solutions/scheduler/cdk/aws_lambda/get_next_scheduled_event/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /source/scheduler/cdk/aws_solutions/scheduler/cdk/aws_lambda/get_next_scheduled_event/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-bin.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /source/scheduler/cdk/aws_solutions/scheduler/cdk/aws_lambda/get_next_scheduled_event/settings.gradle: -------------------------------------------------------------------------------- 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 | rootProject.name = 'sfn-schedule-task' -------------------------------------------------------------------------------- /source/scheduler/cdk/aws_solutions/scheduler/cdk/aws_lambda/get_next_scheduled_event/src/main/java/com/amazonaws/solutions/schedule_sfn_task/ScheduleEvent.java: -------------------------------------------------------------------------------- 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 | package com.amazonaws.solutions.schedule_sfn_task; 15 | 16 | public class ScheduleEvent { 17 | private String schedule; 18 | private String next; 19 | 20 | public String getNext() { 21 | return next; 22 | } 23 | 24 | public String setNext(String next) { 25 | this.next = next; 26 | return next; 27 | } 28 | 29 | public void setSchedule(String schedule) { 30 | /* 31 | cron schedules have 7 fields (seconds, minutes, hours, day-of-month month day-of-week and year), we use only the 32 | last 6 fields (omitting seconds). To do this, we always set seconds to 0, and keep the remainder of the provided 33 | schedule. When generating a next scheduled time, we use a random number of seconds in the minute to avoid hot 34 | spots at the start of each minute. An example string schedule provided might look like * * * * ? * (e.g. every 35 | minute) 36 | */ 37 | schedule = validateSchedule(schedule); 38 | this.schedule = "0 " + schedule; 39 | } 40 | 41 | public String getSchedule() { 42 | return schedule; 43 | } 44 | 45 | private String validateSchedule(String schedule) { 46 | schedule = schedule 47 | .replace("cron(", "") 48 | .replace(")", ""); 49 | 50 | String[] fields = schedule.split("\\s+"); 51 | 52 | if(fields.length != 6) { 53 | throw new ScheduleException("schedule " + schedule + " is not a valid schedule (requires 6 fields)"); 54 | } 55 | return schedule; 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /source/scheduler/cdk/aws_solutions/scheduler/cdk/aws_lambda/get_next_scheduled_event/src/main/java/com/amazonaws/solutions/schedule_sfn_task/ScheduleException.java: -------------------------------------------------------------------------------- 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 | package com.amazonaws.solutions.schedule_sfn_task; 15 | 16 | public class ScheduleException extends RuntimeException { 17 | public ScheduleException(String message) { 18 | super(message); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /source/scheduler/cdk/aws_solutions/scheduler/cdk/aws_lambda/get_next_scheduled_event/src/test/java/com/amazonaws/solutions/schedule_sfn_task/HandleScheduleEventTest.java: -------------------------------------------------------------------------------- 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 | package com.amazonaws.solutions.schedule_sfn_task; 15 | 16 | import org.junit.jupiter.api.Assertions; 17 | import org.junit.jupiter.api.BeforeEach; 18 | import org.junit.jupiter.api.DisplayName; 19 | import org.junit.jupiter.api.Test; 20 | import org.junit.jupiter.params.ParameterizedTest; 21 | import org.junit.jupiter.params.provider.ValueSource; 22 | 23 | import java.text.DateFormat; 24 | import java.text.SimpleDateFormat; 25 | 26 | 27 | class HandleScheduleEventTest { 28 | private ScheduleEvent event; 29 | private HandleScheduleEvent handler; 30 | 31 | @BeforeEach 32 | public void setUp() { 33 | event = new ScheduleEvent(); 34 | handler = new HandleScheduleEvent(); 35 | } 36 | 37 | @Test 38 | @DisplayName("returns ISO 8601 in UTC with seconds") 39 | public void testScheduleEventOutput() { 40 | this.event.setSchedule("cron(* * * * ? *)"); 41 | String result = handler.handleRequest(this.event, null); 42 | 43 | DateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'"); 44 | Assertions.assertDoesNotThrow(() -> { 45 | sdf.parse(result); 46 | }); 47 | } 48 | 49 | @ParameterizedTest 50 | @ValueSource(strings = {"cron(1)", "* * * * * *", "* * *", "* * * * *"}) 51 | @DisplayName("com.amazonaws.solutions.schedule_sfn_task.ScheduleEvent invalid representation raises com.amazonaws.solutions.schedule_sfn_task.ScheduleException") 52 | public void testScheduleEventInvalid(String schedule) { 53 | Assertions.assertThrows(ScheduleException.class, () -> { 54 | this.event.setSchedule(schedule); 55 | handler.handleRequest(this.event, null); 56 | }); 57 | } 58 | } -------------------------------------------------------------------------------- /source/scheduler/cdk/aws_solutions/scheduler/cdk/aws_lambda/scheduler/__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/scheduler/cdk/aws_solutions/scheduler/cdk/aws_lambda/scheduler/requirements.txt: -------------------------------------------------------------------------------- 1 | avro==1.11.3 2 | cronex==0.1.3.1 3 | jmespath==1.0.1 4 | parsedatetime==2.6 5 | ../../../../../../../scheduler/common 6 | ../../../../../../../cdk_solution_helper_py/helpers_common 7 | -------------------------------------------------------------------------------- /source/scheduler/common/aws_solutions/scheduler/common/__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 | TASK_PK = "name" 15 | TASK_SK = "version" 16 | CRON_ANY_WILDCARD = "?" 17 | CRON_MIN_MAX_YEAR = (1970, 2199) 18 | 19 | 20 | from aws_solutions.scheduler.common.base import Scheduler 21 | from aws_solutions.scheduler.common.schedule import Schedule, ScheduleError 22 | from aws_solutions.scheduler.common.task import Task 23 | from aws_solutions.scheduler.common.task_resource import TaskResource 24 | -------------------------------------------------------------------------------- /source/scheduler/common/aws_solutions/scheduler/common/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/scheduler/common/aws_solutions/scheduler/common/task_resource.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 dataclasses 15 | import functools 16 | 17 | from aws_solutions.scheduler.common.schedule import Schedule 18 | from aws_solutions.scheduler.common.task import Task 19 | 20 | 21 | class TaskResource: 22 | """Used as a decorator on AWS Lambda Functions to transform the AWS Lambda Event input as a Task""" 23 | 24 | def __init__(self, func): 25 | functools.update_wrapper(self, func) 26 | self.func = func 27 | 28 | def __call__(self, *args, **kwargs): 29 | task: Task = Task(**args[0]) 30 | task: Task = self.func(task, args[1], **kwargs) 31 | 32 | if not task: 33 | return None 34 | else: 35 | # convert the schedule into a string 36 | if isinstance(task.schedule, Schedule): 37 | task.schedule = task.schedule.expression 38 | return dataclasses.asdict(task) 39 | -------------------------------------------------------------------------------- /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/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 | # ###################################################################################################################### 13 | -------------------------------------------------------------------------------- /source/tests/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/tests/aws_lambda/create_batch_inference_job/__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/aws_lambda/create_batch_segment_job/__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/aws_lambda/create_campaign/__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/aws_lambda/create_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/tests/aws_lambda/create_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/tests/aws_lambda/create_dataset_group/__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/aws_lambda/create_dataset_import_job/__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/aws_lambda/create_event_tracker/__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/aws_lambda/create_filter/__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/aws_lambda/create_recommender/__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/aws_lambda/create_schema/__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/aws_lambda/create_schema/create_schema_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 pytest 15 | from aws_lambda.create_schema.handler import CONFIG, RESOURCE, lambda_handler 16 | 17 | 18 | def test_create_schema_handler(validate_handler_config): 19 | validate_handler_config(RESOURCE, CONFIG) 20 | with pytest.raises(ValueError): 21 | lambda_handler({}, None) 22 | -------------------------------------------------------------------------------- /source/tests/aws_lambda/create_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/tests/aws_lambda/create_solution_version/__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/cdk_solution_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 | -------------------------------------------------------------------------------- /source/tests/cdk_solution_helper/aws_lambda/java/fixtures/java_sample/build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'java' 3 | } 4 | 5 | repositories { 6 | mavenCentral() 7 | } 8 | 9 | dependencies { 10 | implementation 'com.amazonaws:aws-lambda-java-core:1.2.1' 11 | implementation 'com.amazonaws:aws-lambda-java-events:3.1.0' 12 | runtimeOnly 'com.amazonaws:aws-lambda-java-log4j2:1.2.0' 13 | testImplementation 'org.junit.jupiter:junit-jupiter-api:5.7.0' 14 | testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.7.0' 15 | } 16 | 17 | test { 18 | useJUnitPlatform() 19 | } 20 | 21 | task packageFat(type: Zip) { 22 | from compileJava 23 | from processResources 24 | into('lib') { 25 | from configurations.runtimeClasspath 26 | } 27 | dirMode = 0755 28 | fileMode = 0755 29 | } 30 | 31 | task packageLibs(type: Zip) { 32 | into('java/lib') { 33 | from configurations.runtimeClasspath 34 | } 35 | dirMode = 0755 36 | fileMode = 0755 37 | } 38 | 39 | task packageSkinny(type: Zip) { 40 | from compileJava 41 | from processResources 42 | } 43 | 44 | java { 45 | sourceCompatibility = JavaVersion.VERSION_11 46 | targetCompatibility = JavaVersion.VERSION_11 47 | } 48 | 49 | build.dependsOn packageSkinny -------------------------------------------------------------------------------- /source/tests/cdk_solution_helper/aws_lambda/java/fixtures/java_sample/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aws-solutions/maintaining-personalized-experiences-with-machine-learning/5f170385f706eea36472dee57593c112f679c30f/source/tests/cdk_solution_helper/aws_lambda/java/fixtures/java_sample/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /source/tests/cdk_solution_helper/aws_lambda/java/fixtures/java_sample/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-bin.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /source/tests/cdk_solution_helper/aws_lambda/java/fixtures/java_sample/settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name = 'java_sample' 2 | 3 | -------------------------------------------------------------------------------- /source/tests/cdk_solution_helper/aws_lambda/java/fixtures/java_sample/src/main/java/example/Handler.java: -------------------------------------------------------------------------------- 1 | package example; 2 | 3 | import com.amazonaws.services.lambda.runtime.Context; 4 | import com.amazonaws.services.lambda.runtime.RequestHandler; 5 | 6 | public class Handler implements RequestHandler { 7 | 8 | @Override 9 | public UserData handleRequest(UserData input, Context context) { 10 | UserData output = input; 11 | output.setGreeting("Hello there " + input.getName()); 12 | return output; 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /source/tests/cdk_solution_helper/aws_lambda/java/fixtures/java_sample/src/main/java/example/UserData.java: -------------------------------------------------------------------------------- 1 | package example; 2 | 3 | public class UserData { 4 | public UserData() { 5 | } 6 | 7 | public UserData(String name) { 8 | this.name = name; 9 | } 10 | 11 | public String getName() { 12 | return name; 13 | } 14 | 15 | public void setName(String name) { 16 | this.name = name; 17 | } 18 | 19 | private String name = ""; 20 | 21 | public String getGreeting() { 22 | return greeting; 23 | } 24 | 25 | public void setGreeting(String greeting) { 26 | this.greeting = greeting; 27 | } 28 | 29 | private String greeting = ""; 30 | } 31 | -------------------------------------------------------------------------------- /source/tests/cdk_solution_helper/aws_lambda/java/fixtures/java_sample/src/main/main.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 14 | -------------------------------------------------------------------------------- /source/tests/cdk_solution_helper/aws_lambda/java/fixtures/java_sample/src/test/java/example/HandlerTest.java: -------------------------------------------------------------------------------- 1 | package example; 2 | 3 | import org.junit.jupiter.api.BeforeEach; 4 | import org.junit.jupiter.api.Test; 5 | 6 | import static org.junit.jupiter.api.Assertions.*; 7 | 8 | class HandlerTest { 9 | Handler handler; 10 | UserData userData; 11 | 12 | @BeforeEach 13 | void setUp() { 14 | handler = new Handler(); 15 | userData = new UserData("AWS Solutions"); 16 | } 17 | 18 | @Test 19 | void handleRequest() { 20 | UserData result = this.handler.handleRequest(userData, null); 21 | assert result.getGreeting().equals("Hello there AWS Solutions"); 22 | } 23 | } -------------------------------------------------------------------------------- /source/tests/cdk_solution_helper/aws_lambda/java/fixtures/java_sample/src/test/test1.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 14 | -------------------------------------------------------------------------------- /source/tests/cdk_solution_helper/aws_lambda/python/fixtures/Pipfile: -------------------------------------------------------------------------------- 1 | [packages] 2 | minimal = {path = "./package"} -------------------------------------------------------------------------------- /source/tests/cdk_solution_helper/aws_lambda/python/fixtures/hash_fixture/a/z.txt: -------------------------------------------------------------------------------- 1 | a -------------------------------------------------------------------------------- /source/tests/cdk_solution_helper/aws_lambda/python/fixtures/hash_fixture/c.txt: -------------------------------------------------------------------------------- 1 | c -------------------------------------------------------------------------------- /source/tests/cdk_solution_helper/aws_lambda/python/fixtures/hash_fixture/z/a.txt: -------------------------------------------------------------------------------- 1 | z -------------------------------------------------------------------------------- /source/tests/cdk_solution_helper/aws_lambda/python/fixtures/lambda/package/minimal/__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 | 15 | def function_in_package(): 16 | return "hello from function_in_package" 17 | -------------------------------------------------------------------------------- /source/tests/cdk_solution_helper/aws_lambda/python/fixtures/lambda/package/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 | from setuptools import setup 15 | 16 | setup( 17 | name="minimal", 18 | version="0.1", 19 | description="a small package for testing", 20 | author="AWS Solutions Builders", 21 | packages=["minimal"], 22 | zip_safe=True, 23 | ) 24 | -------------------------------------------------------------------------------- /source/tests/cdk_solution_helper/aws_lambda/python/fixtures/packages/package2/minimal2/__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 | 15 | def function_in_package(): 16 | return "hello from minimal2 function_in_package" 17 | -------------------------------------------------------------------------------- /source/tests/cdk_solution_helper/aws_lambda/python/fixtures/packages/package2/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 | from setuptools import setup 15 | 16 | setup( 17 | name="minimal2", 18 | version="0.1", 19 | description="a second small package for testing", 20 | author="AWS Solutions Builders", 21 | packages=["minimal2"], 22 | zip_safe=True, 23 | ) 24 | -------------------------------------------------------------------------------- /source/tests/cdk_solution_helper/aws_lambda/python/fixtures/pyproject.toml: -------------------------------------------------------------------------------- 1 | [tool.poetry] 2 | name = "python-bundling" 3 | version = "0.1.0" 4 | description = "" 5 | authors = ["AWS Solutions Builders"] 6 | 7 | [tool.poetry.dependencies] 8 | python = "^3.11" 9 | minimal = {path = "package"} 10 | 11 | [tool.poetry.dev-dependencies] 12 | pytest = "^7.4.2" 13 | 14 | [build-system] 15 | requires = ["poetry-core>=1.2.0"] 16 | build-backend = "poetry.core.masonry.api" -------------------------------------------------------------------------------- /source/tests/cdk_solution_helper/aws_lambda/python/fixtures/requirements.txt: -------------------------------------------------------------------------------- 1 | ./package -------------------------------------------------------------------------------- /source/tests/cdk_solution_helper/helpers/test_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 | from aws_solutions.cdk.helpers.logger import Logger 17 | 18 | 19 | def test_logger(caplog): 20 | logger = Logger.get_logger("test-logger") 21 | logger.propagate = True # for test 22 | 23 | assert logger.level == logging.INFO 24 | 25 | with caplog.at_level(logging.INFO): 26 | logger.critical("CRITICAL") 27 | logger.error("ERROR") 28 | logger.warning("WARNING") 29 | logger.info("INFO") 30 | logging.debug("DEBUG") 31 | 32 | for level in "CRITICAL ERROR WARNING INFO".split(" "): 33 | assert level in caplog.text 34 | -------------------------------------------------------------------------------- /source/tests/cdk_solution_helper/test_cfn_nag_suppressions.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_cdk import CfnResource, App, Stack 15 | 16 | from aws_solutions.cdk.cfn_nag import add_cfn_nag_suppressions, CfnNagSuppression 17 | 18 | 19 | def test_cfn_nag_suppression(): 20 | rule_id = "W10" 21 | reason = "some reason" 22 | sup = CfnNagSuppression(rule_id=rule_id, reason=reason) 23 | 24 | assert sup.rule_id == rule_id 25 | assert sup.reason == reason 26 | 27 | 28 | def test_add_cfn_nag_suppression(): 29 | app = App() 30 | stack = Stack(app) 31 | resource = CfnResource(stack, "test", type="Custom::Test") 32 | 33 | add_cfn_nag_suppressions( 34 | resource, 35 | [ 36 | CfnNagSuppression(rule_id="W1", reason="reason 1"), 37 | CfnNagSuppression("W2", "reason 2"), 38 | ], 39 | ) 40 | 41 | assert resource.get_metadata("cfn_nag") == { 42 | "rules_to_suppress": [ 43 | {"id": "W1", "reason": "reason 1"}, 44 | {"id": "W2", "reason": "reason 2"}, 45 | ] 46 | } 47 | -------------------------------------------------------------------------------- /source/tests/cdk_solution_helper/test_mappings.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 pytest 14 | from aws_cdk import App, Stack 15 | 16 | from aws_solutions.cdk.mappings import Mappings 17 | 18 | 19 | @pytest.mark.parametrize("send_data,result", [(True, "Yes"), (False, "No")]) 20 | def test_mappings(send_data, result): 21 | solution_id = "SO001" 22 | app = App() 23 | stack = Stack(app) 24 | Mappings(stack, solution_id=solution_id, send_anonymous_usage_data=send_data) 25 | 26 | template = app.synth().stacks[0].template 27 | 28 | assert template["Mappings"]["Solution"]["Data"]["ID"] == solution_id 29 | assert template["Mappings"]["Solution"]["Data"]["Version"] == "%%SOLUTION_VERSION%%" 30 | assert template["Mappings"]["Solution"]["Data"]["SendAnonymousUsageData"] == result 31 | 32 | assert template["Mappings"]["SourceCode"]["General"]["S3Bucket"] == "%%BUCKET_NAME%%" 33 | assert template["Mappings"]["SourceCode"]["General"]["KeyPrefix"] == "%%SOLUTION_NAME%%/%%SOLUTION_VERSION%%" 34 | -------------------------------------------------------------------------------- /source/tests/fixtures/config/users.csv: -------------------------------------------------------------------------------- 1 | USER_ID,AGE,GENDER 2 | 0,71,F 3 | 1,67,M 4 | 2,25,F 5 | 3,70,F 6 | 4,28,F 7 | 5,34,F 8 | 6,66,F 9 | 7,74,F 10 | 8,79,F 11 | 9,57,M 12 | 10,58,M 13 | 11,18,M 14 | 12,88,M 15 | 13,73,F 16 | 14,77,F 17 | 15,23,F 18 | 16,85,M 19 | 17,31,M 20 | 18,48,M 21 | 19,44,M 22 | 20,24,F 23 | 21,63,M 24 | 22,66,F 25 | 23,21,F 26 | 24,81,M 27 | --------------------------------------------------------------------------------