-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Resolves #286
- Loading branch information
Showing
6 changed files
with
575 additions
and
200 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,90 @@ | ||
""" | ||
Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
SPDX-License-Identifier: MIT-0 | ||
Permission is hereby granted, free of charge, to any person obtaining a copy of this | ||
software and associated documentation files (the "Software"), to deal in the Software | ||
without restriction, including without limitation the rights to use, copy, modify, | ||
merge, publish, distribute, sublicense, and/or sell copies of the Software, and to | ||
permit persons to whom the Software is furnished to do so. | ||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, | ||
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A | ||
PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT | ||
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION | ||
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE | ||
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
""" | ||
|
||
''' | ||
Create/update/delete ParallelCluster cluster and save config to S3 as json and yaml. | ||
''' | ||
import boto3 | ||
import cfnresponse | ||
import json | ||
import logging | ||
from os import environ as environ | ||
from time import sleep | ||
|
||
logger=logging.getLogger(__file__) | ||
logger_formatter = logging.Formatter('%(levelname)s: %(message)s') | ||
logger_streamHandler = logging.StreamHandler() | ||
logger_streamHandler.setFormatter(logger_formatter) | ||
logger.addHandler(logger_streamHandler) | ||
logger.setLevel(logging.INFO) | ||
logger.propagate = False | ||
|
||
def lambda_handler(event, context): | ||
try: | ||
logger.info(f"event:\n{json.dumps(event, indent=4)}") | ||
|
||
# Create sns client so can send notifications on any errors. | ||
sns_client = boto3.client('sns') | ||
|
||
cluster_name = None | ||
requestType = event['RequestType'] | ||
properties = event['ResourceProperties'] | ||
required_properties = [ | ||
] | ||
error_message = "" | ||
for property in required_properties: | ||
try: | ||
value = properties[property] | ||
except: | ||
error_message += f"Missing {property} property. " | ||
if error_message: | ||
logger.info(error_message) | ||
if requestType == 'Delete': | ||
cfnresponse.send(event, context, cfnresponse.SUCCESS, {}, physicalResourceId=cluster_name) | ||
return | ||
else: | ||
raise KeyError(error_message) | ||
|
||
cluster_name = environ['ClusterName'] | ||
cluster_region = environ['Region'] | ||
logger.info(f"{requestType} request for {cluster_name} in {cluster_region}") | ||
|
||
# pcs_client = boto3.client('pcs') | ||
|
||
if requestType == 'Create': | ||
logger.info(f"Creating {cluster_name}") | ||
elif requestType == 'Update': | ||
logger.info(f"Updating {cluster_name}") | ||
elif requestType == 'Delete': | ||
logger.info(f"Deleting {cluster_name}") | ||
|
||
cfnresponse.send(event, context, cfnresponse.SUCCESS, {}, physicalResourceId="resource_id") | ||
return | ||
|
||
except Exception as e: | ||
logger.exception(str(e)) | ||
cfnresponse.send(event, context, cfnresponse.FAILED, {'error': str(e)}, physicalResourceId=cluster_name) | ||
sns_client.publish( | ||
TopicArn = environ['ErrorSnsTopicArn'], | ||
Subject = f"{cluster_name} CreateParallelCluster failed", | ||
Message = str(e) | ||
) | ||
logger.info(f"Published error to {environ['ErrorSnsTopicArn']}") | ||
raise | ||
|
||
cfnresponse.send(event, context, cfnresponse.SUCCESS, {}, physicalResourceId=cluster_name) |
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 @@ | ||
../cfnresponse.py |
88 changes: 88 additions & 0 deletions
88
source/resources/lambdas/PcsComputeNodeGroup/PcsComputeNodeGroup.py
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,88 @@ | ||
""" | ||
Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
SPDX-License-Identifier: MIT-0 | ||
Permission is hereby granted, free of charge, to any person obtaining a copy of this | ||
software and associated documentation files (the "Software"), to deal in the Software | ||
without restriction, including without limitation the rights to use, copy, modify, | ||
merge, publish, distribute, sublicense, and/or sell copies of the Software, and to | ||
permit persons to whom the Software is furnished to do so. | ||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, | ||
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A | ||
PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT | ||
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION | ||
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE | ||
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
""" | ||
|
||
''' | ||
Create/update/delete ParallelCluster cluster and save config to S3 as json and yaml. | ||
''' | ||
import boto3 | ||
import cfnresponse | ||
import json | ||
import logging | ||
from os import environ as environ | ||
from time import sleep | ||
|
||
logger=logging.getLogger(__file__) | ||
logger_formatter = logging.Formatter('%(levelname)s: %(message)s') | ||
logger_streamHandler = logging.StreamHandler() | ||
logger_streamHandler.setFormatter(logger_formatter) | ||
logger.addHandler(logger_streamHandler) | ||
logger.setLevel(logging.INFO) | ||
logger.propagate = False | ||
|
||
def lambda_handler(event, context): | ||
try: | ||
logger.info(f"event:\n{json.dumps(event, indent=4)}") | ||
|
||
# Create sns client so can send notifications on any errors. | ||
sns_client = boto3.client('sns') | ||
|
||
cluster_name = None | ||
requestType = event['RequestType'] | ||
properties = event['ResourceProperties'] | ||
required_properties = [ | ||
] | ||
error_message = "" | ||
for property in required_properties: | ||
try: | ||
value = properties[property] | ||
except: | ||
error_message += f"Missing {property} property. " | ||
if error_message: | ||
logger.info(error_message) | ||
if requestType == 'Delete': | ||
cfnresponse.send(event, context, cfnresponse.SUCCESS, {}, physicalResourceId=cluster_name) | ||
return | ||
else: | ||
raise KeyError(error_message) | ||
|
||
cluster_name = environ['ClusterName'] | ||
cluster_region = environ['Region'] | ||
logger.info(f"{requestType} request for {cluster_name} in {cluster_region}") | ||
|
||
if requestType == 'Create': | ||
logger.info(f"Creating {cluster_name}") | ||
elif requestType == 'Update': | ||
logger.info(f"Updating {cluster_name}") | ||
elif requestType == 'Delete': | ||
logger.info(f"Deleting {cluster_name}") | ||
|
||
cfnresponse.send(event, context, cfnresponse.SUCCESS, {}, physicalResourceId=cluster_name) | ||
return | ||
|
||
except Exception as e: | ||
logger.exception(str(e)) | ||
cfnresponse.send(event, context, cfnresponse.FAILED, {'error': str(e)}, physicalResourceId=cluster_name) | ||
sns_client.publish( | ||
TopicArn = environ['ErrorSnsTopicArn'], | ||
Subject = f"{cluster_name} CreateParallelCluster failed", | ||
Message = str(e) | ||
) | ||
logger.info(f"Published error to {environ['ErrorSnsTopicArn']}") | ||
raise | ||
|
||
cfnresponse.send(event, context, cfnresponse.SUCCESS, {}, physicalResourceId=cluster_name) |
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 @@ | ||
../cfnresponse.py |