diff --git a/lambda_layers/dependencies/python/managers/stack_manager.py b/lambda_layers/dependencies/python/managers/stack_manager.py index 5f112e1..904a1df 100644 --- a/lambda_layers/dependencies/python/managers/stack_manager.py +++ b/lambda_layers/dependencies/python/managers/stack_manager.py @@ -84,14 +84,6 @@ def list_stacks(self, keys): def create_stack(self, stack_name, payload): """ Creates a new stack. - - Args: - type: (app|pipeline|service) - stack_name: - payload: - Basic Usage: - Returns: - List: List of .. """ params = self._generate_params(payload) @@ -177,14 +169,7 @@ def describe_stack(self): return stacks def update_stack(self, payload): - """ - Args: - type: (app|pipeline|service) - stack_name: - payload: - Basic Usage: - Returns: - List: List of .. + """ Updates a CloudFormation stack. """ stack_name = transform_utils.add_prefix(self._params['name']) LOGGER.debug( @@ -249,12 +234,6 @@ def update_stack(self, payload): def delete_stack(self): """ Deletes a CloudFormation stack. - - Args: - name (string): Name of the CloudFormation Stack - Basic Usage: - Returns: - List: List of JSON objects containing stack information """ stack_name = transform_utils.add_prefix(self._params['name']) LOGGER.debug( diff --git a/lambda_layers/dependencies/python/template_generator.py b/lambda_layers/dependencies/python/template_generator.py index 47b343c..b606520 100644 --- a/lambda_layers/dependencies/python/template_generator.py +++ b/lambda_layers/dependencies/python/template_generator.py @@ -28,10 +28,9 @@ def generate_template_url(stack_type, payload): elif stack_type == 'service': prefix_path = 'services' - template_url = 'https://s3.amazonaws.com/{}/{}/{}-{}-{}.yaml'.format( + template_url = 'https://s3.amazonaws.com/{}/{}/{}/{}.yaml'.format( platform_config.PLATFORM_BUCKET, prefix_path, - stack_type, payload['subtype'], payload['version'] ) diff --git a/src/apps/create_app.py b/src/apps/create_app.py index 7748d57..eafb651 100644 --- a/src/apps/create_app.py +++ b/src/apps/create_app.py @@ -43,7 +43,7 @@ def post(event, _context): name = transform_utils.add_prefix(payload['name']) if 'subtype' not in payload: - payload['subtype'] = 'shared-lb' + payload['subtype'] = 'ecs-fargate' if 'version' not in payload: payload['version'] = 'latest' diff --git a/src/pipelines/create_pipeline.py b/src/pipelines/create_pipeline.py index 8f7ef3c..2d3708f 100644 --- a/src/pipelines/create_pipeline.py +++ b/src/pipelines/create_pipeline.py @@ -42,7 +42,7 @@ def post(event, _context): # Configure default values if not present if 'subtype' not in payload: - payload['subtype'] = 'github' + payload['subtype'] = 'github/cfn' if 'version' not in payload: payload['version'] = 'latest' diff --git a/src/services/create_service.py b/src/services/create_service.py index 5127cf7..ef2f94f 100644 --- a/src/services/create_service.py +++ b/src/services/create_service.py @@ -11,6 +11,7 @@ import json +from exceptions import AlreadyExists from aws_xray_sdk.core import patch_all from logger import configure_logger @@ -36,6 +37,9 @@ def post(event, _context): data['services'] = [] payload = json.loads(event['body-json'][0]) + LOGGER.debug( + 'Received payload: %s', + payload) # Configure default values if not present @@ -51,7 +55,13 @@ def post(event, _context): name, payload ) + except AlreadyExists: + return response_builder.error('A service with that name already exists.', 409) except Exception as ex: + LOGGER.debug( + 'Exception: %s', + ex, + exc_info=True) return response_builder.error('Unknown Error: {}'.format(ex)) else: data['services'] = resp diff --git a/src/services/name/update_service.py b/src/services/name/update_service.py index 500d60b..814b310 100644 --- a/src/services/name/update_service.py +++ b/src/services/name/update_service.py @@ -11,7 +11,7 @@ import json -from exceptions import NoSuchObject, PermissionDenied +from exceptions import NoSuchObject, PermissionDenied, UnknownParameter from aws_xray_sdk.core import patch_all from logger import configure_logger @@ -34,15 +34,19 @@ def patch(event, _context): payload = json.loads(event['body-json'][0]) + # Configure default values if not present if 'subtype' not in payload: payload['subtype'] = 's3' if 'version' not in payload: payload['version'] = 'latest' - bindings = payload['service_bindings'].split(',') - for binding in bindings: - if not sm.has_permissions(binding): - return response_builder.error('{} doesn\'t exist or not enough permissions.'.format(binding), 400) + try: + bindings = payload['ServiceBindings'].split(',') + for binding in bindings: + if not sm.has_permissions(binding): + return response_builder.error('{} doesn\'t exist or not enough permissions.'.format(binding), 400) + except KeyError: + return response_builder.error('ServiceBindings not provided in payload.', 400) try: resp = sm.update_stack( @@ -52,6 +56,8 @@ def patch(event, _context): return response_builder.error('No such service.', 400) except PermissionDenied: return response_builder.error('Permission denied.', 401) + except UnknownParameter as ex: + return response_builder.error('{}'.format(ex), 400) except Exception as ex: return response_builder.error('Unknown Error: {}'.format(ex)) else: diff --git a/src/template.yaml b/src/template.yaml index dd5f928..cfa04ce 100644 --- a/src/template.yaml +++ b/src/template.yaml @@ -683,6 +683,7 @@ Resources: - 'cloudformation:CreateStack' - 'cloudformation:ListExports' - 'iam:PassRole' + - 'ssm:GetParametersByPath' Resource: - '*' @@ -799,3 +800,19 @@ Resources: Type: "String" Value: !Sub "https://${ApiGatewayApi}.execute-api.${AWS::Region}.amazonaws.com/v1/" Description: "API Endpoint for the API." + + APIDeploymentRoleArn: + Type: "AWS::SSM::Parameter" + Properties: + Name: "/gurum/api/deployment-role-arn" + Type: "String" + Value: !GetAtt DeploymentRole.Arn + Description: "IAM ARN to the Deployment Role." + + GurumProductsBucket: + Type: "AWS::SSM::Parameter" + Properties: + Name: "/gurum/products/bucket" + Type: "String" + Value: !Ref ProductsBucket + Description: "S3 Bucket holding the Gurum Products."