-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
123 changed files
with
4,400 additions
and
506 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ source = | |
infrastructure | ||
aws_lambda | ||
cdk_solution_helper_py | ||
scheduler | ||
|
||
[report] | ||
fail_under = 80.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# ###################################################################################################################### | ||
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. # | ||
# # | ||
# Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance # | ||
# with the License. You may obtain a copy of the License at # | ||
# # | ||
# http://www.apache.org/licenses/LICENSE-2.0 # | ||
# # | ||
# Unless required by applicable law or agreed to in writing, software distributed under the License is distributed # | ||
# on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for # | ||
# the specific language governing permissions and limitations under the License. # | ||
# ###################################################################################################################### | ||
import json | ||
import os | ||
|
||
from aws_lambda_powertools import Logger, Tracer, Metrics | ||
from aws_lambda_powertools.metrics import MetricUnit | ||
from aws_lambda_powertools.utilities.data_classes import S3Event | ||
|
||
from shared.personalize.service_model import ServiceModel | ||
from shared.personalize_service import Personalize | ||
|
||
|
||
logger = Logger() | ||
tracer = Tracer() | ||
metrics = Metrics() | ||
|
||
|
||
@metrics.log_metrics | ||
@tracer.capture_lambda_handler | ||
def lambda_handler(event, context): | ||
"""Generate and return a solution configuration file derived from the properties of a dataset group | ||
:param dict event: AWS Lambda Event (in this case, the dataset group and schedules) | ||
:param context: AWS Lambda Context | ||
:return: Dict | ||
""" | ||
dataset_group_name = event["datasetGroupName"] | ||
schedules = event.get("schedules") | ||
|
||
cli = Personalize() | ||
model = ServiceModel(cli, dataset_group_name=dataset_group_name) | ||
return model.get_config(dataset_group_name=dataset_group_name, schedules=schedules) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# ###################################################################################################################### | ||
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. # | ||
# # | ||
# Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance # | ||
# with the License. You may obtain a copy of the License at # | ||
# # | ||
# http://www.apache.org/licenses/LICENSE-2.0 # | ||
# # | ||
# Unless required by applicable law or agreed to in writing, software distributed under the License is distributed # | ||
# on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for # | ||
# the specific language governing permissions and limitations under the License. # | ||
# ###################################################################################################################### | ||
|
||
from typing import Dict, Any | ||
|
||
from aws_lambda_powertools import Logger, Tracer, Metrics | ||
from aws_lambda_powertools.utilities.typing import LambdaContext | ||
|
||
from shared.sfn_middleware import set_workflow_config | ||
|
||
logger = Logger() | ||
tracer = Tracer() | ||
metrics = Metrics() | ||
|
||
|
||
def lambda_handler(event: Dict[str, Any], context: LambdaContext) -> Dict: | ||
"""Add timeStarted to the workflowConfig of all items | ||
:param event: AWS Lambda Event | ||
:param context: AWS Lambda Context | ||
:return: the modified input | ||
""" | ||
config = set_workflow_config(event) | ||
return config |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
# ###################################################################################################################### | ||
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. # | ||
# # | ||
# Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance # | ||
# with the License. You may obtain a copy of the License at # | ||
# # | ||
# http://www.apache.org/licenses/LICENSE-2.0 # | ||
# # | ||
# Unless required by applicable law or agreed to in writing, software distributed under the License is distributed # | ||
# on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for # | ||
# the specific language governing permissions and limitations under the License. # | ||
# ###################################################################################################################### | ||
from datetime import datetime | ||
from typing import Dict, Optional | ||
|
||
from aws_lambda_powertools import Logger | ||
|
||
from shared.exceptions import ( | ||
NotificationError, | ||
SolutionVersionPending, | ||
) | ||
from shared.notifiers import NotifyEventBridge | ||
from shared.resource import Resource | ||
|
||
logger = Logger() | ||
|
||
|
||
NOTIFY_LIST = [NotifyEventBridge()] | ||
|
||
|
||
class Notifies: | ||
"""Decorates a resource creation or describe call to provide event notifications""" | ||
|
||
def __init__(self, status: str): | ||
self.status = status | ||
|
||
def __call__(self, function): | ||
def wrapper(caller, resource: Resource, **kwargs): | ||
try: | ||
result = function(caller, resource, **kwargs) | ||
except SolutionVersionPending as exc: | ||
# because of how solution versions are handled, we must manually notify and re-raise | ||
self.notify( | ||
resource=resource, | ||
result={ | ||
"solutionVersionArn": str(exc), | ||
"status": "CREATE IN_PROGRESS", | ||
}, | ||
cutoff=None, | ||
) | ||
raise exc | ||
|
||
# run the notifier | ||
cutoff = kwargs.get("timeStarted") | ||
self.notify(resource, result, cutoff) | ||
|
||
return result | ||
|
||
return wrapper | ||
|
||
def notify( | ||
self, resource: Resource, result: Dict, cutoff: Optional[datetime] | ||
) -> None: | ||
""" | ||
Notify each target in the NOTIFY_LIST | ||
:param resource: the subject of the notification | ||
:param result: the description of the subject of the notification | ||
:param cutoff: the cutoff datetime for notifications (UTC required, timezone aware) | ||
:return: None | ||
""" | ||
for notifier in NOTIFY_LIST: | ||
notifier.set_cutoff(cutoff) | ||
try: | ||
notifier.notify(self.status, resource, result) | ||
except NotificationError as exc: | ||
logger.error( | ||
f"notifier {notifier.name} failed: {str(exc)}" | ||
) # log and continue through notifiers |
Oops, something went wrong.