예제 #1
0
 def estimate_cost(self, template_name=None, stack_params=None):
     template_body = self._load_template(template_name)
     # Get url to cost estimate calculator
     cfn_conn = utility.get_boto_client(self.config, 'cloudformation')
     estimate_cost_url = cfn_conn.estimate_template_cost(
         TemplateBody=template_body, Parameters=stack_params).get('Url')
     print estimate_cost_url
 def estimate_cost(self, template_name=None, stack_params=None):
     template_body = self._load_template(template_name)
     # Get url to cost estimate calculator
     cfn_conn = utility.get_boto_client(self.config, 'cloudformation')
     estimate_cost_url = cfn_conn.estimate_template_cost(
         TemplateBody=template_body,
         Parameters=stack_params).get('Url')
     print estimate_cost_url
    def delete_action(self):
        """
        Default delete_action invoked by CLI
        """
        cfn_conn = utility.get_boto_client(self.config, 'cloudformation')
        stack_name = self.config['global']['environment_name']

        cfn_conn.delete_stack(StackName=stack_name)
        print "Successfully issued delete stack command for %s\n" % stack_name
예제 #4
0
    def delete_action(self):
        """
        Default delete_action invoked by CLI
        """
        cfn_conn = utility.get_boto_client(self.config, 'cloudformation')
        stack_name = self.config['global']['environment_name']

        cfn_conn.delete_stack(StackName=stack_name)
        print "Successfully issued delete stack command for %s\n" % stack_name
    def delete_action(self):
        """
        Default delete_action invoked by CLI
        Loads and validates config, then issues the delete stack command to the root stack
        Override the delete_hook in your environment to intercept the delete process with your own code
        This can be useful for deleting any resources that were created outside of cloudformation
        """
        self.load_config()
        self.delete_hook()

        cfn_conn = utility.get_boto_client(self.config, 'cloudformation')
        stack_name = self.config['global']['environment_name']

        cfn_conn.delete_stack(StackName=stack_name)
        print "\nSuccessfully issued delete stack command for %s\n" % stack_name
    def delete_action(self):
        """
        Default delete_action invoked by CLI
        Loads and validates config, then issues the delete stack command to the root stack
        Override the delete_hook in your environment to intercept the delete process with your own code
        This can be useful for deleting any resources that were created outside of cloudformation
        """
        self.load_config()
        self.delete_hook()

        cfn_conn = utility.get_boto_client(self.config, 'cloudformation')
        stack_name = self.config['global']['environment_name']

        cfn_conn.delete_stack(StackName=stack_name)
        print "\nSuccessfully issued delete stack command for %s\n" % stack_name
    def estimate_cost(self, template_name=None, template_url=None, stack_params=None):
        cfn_conn = utility.get_boto_client(self.config, 'cloudformation')

        if not template_url:
            return None

        estimate_cost_url = cfn_conn.estimate_template_cost(
            TemplateURL=template_url,
            Parameters=stack_params)
        # else:
        #     template_body = self._load_template(template_name)
        #     estimate_cost_url = cfn_conn.estimate_template_cost(
        #         TemplateBody=template_body,
        #         Parameters=stack_params)

        return estimate_cost_url.get('Url')
    def estimate_cost(self, template_name=None, template_url=None, stack_params=None):
        cfn_conn = utility.get_boto_client(self.config, 'cloudformation')

        if not template_url:
            return None

        estimate_cost_url = cfn_conn.estimate_template_cost(
            TemplateURL=template_url,
            Parameters=stack_params)
        # else:
        #     template_body = self._load_template(template_name)
        #     estimate_cost_url = cfn_conn.estimate_template_cost(
        #         TemplateBody=template_body,
        #         Parameters=stack_params)

        return estimate_cost_url.get('Url')
    def _ensure_stack_is_deployed(self,
                                  stack_name='UnnamedStack',
                                  sns_topic=None,
                                  stack_params=[]):
        """
        Deploys the root template to cloudformation using boto
        First attempts to issue an update stack command
        If this fails because the stack does not yet exist, then issues a create stack command
        """
        is_successful = False
        notification_arns = []

        if sns_topic:
            notification_arns.append(sns_topic.arn)

        template_url = self._root_template_url()

        cfn_conn = utility.get_boto_client(self.config, 'cloudformation')
        try:
            cfn_conn.update_stack(StackName=stack_name,
                                  TemplateURL=template_url,
                                  Parameters=stack_params,
                                  NotificationARNs=notification_arns,
                                  Capabilities=['CAPABILITY_IAM'])
            is_successful = True
            print "\nSuccessfully issued update stack command for %s\n" % stack_name

        # Else stack doesn't currently exist, create a new stack
        except botocore.exceptions.ClientError as update_e:
            if "does not exist" in update_e.message:
                try:
                    cfn_conn.create_stack(StackName=stack_name,
                                          TemplateURL=template_url,
                                          Parameters=stack_params,
                                          NotificationARNs=notification_arns,
                                          Capabilities=['CAPABILITY_IAM'],
                                          DisableRollback=True,
                                          TimeoutInMinutes=TIMEOUT)
                    is_successful = True
                    print "\nSuccessfully issued create stack command for %s\n" % stack_name
                except botocore.exceptions.ClientError as create_e:
                    print "Deploy failed: \n\n%s\n" % create_e.message
            else:
                raise

        return is_successful
    def _ensure_stack_is_deployed(self, stack_name='UnnamedStack', sns_topic=None, stack_params=[]):
        """
        Deploys the root template to cloudformation using boto
        First attempts to issue an update stack command
        If this fails because the stack does not yet exist, then issues a create stack command
        """
        is_successful = False
        notification_arns = []

        if sns_topic:
            notification_arns.append(sns_topic.arn)

        template_url = self._root_template_url()

        cfn_conn = utility.get_boto_client(self.config, 'cloudformation')
        try:
            cfn_conn.update_stack(
                StackName=stack_name,
                TemplateURL=template_url,
                Parameters=stack_params,
                NotificationARNs=notification_arns,
                Capabilities=['CAPABILITY_IAM'])
            is_successful = True
            print "\nSuccessfully issued update stack command for %s\n" % stack_name

        # Else stack doesn't currently exist, create a new stack
        except botocore.exceptions.ClientError as update_e:
            if "does not exist" in update_e.message:
                try:
                    cfn_conn.create_stack(
                        StackName=stack_name,
                        TemplateURL=template_url,
                        Parameters=stack_params,
                        NotificationARNs=notification_arns,
                        Capabilities=['CAPABILITY_IAM'],
                        DisableRollback=True,
                        TimeoutInMinutes=TIMEOUT)
                    is_successful = True
                    print "\nSuccessfully issued create stack command for %s\n" % stack_name
                except botocore.exceptions.ClientError as create_e:
                    print "Deploy failed: \n\n%s\n" % create_e.message
            else:
                raise

        return is_successful
예제 #11
0
    def _ensure_stack_is_deployed(self,
                                  stack_name='UnnamedStack',
                                  sns_topic=None,
                                  stack_params=[]):
        is_successful = False
        notification_arns = []

        if sns_topic:
            notification_arns.append(sns_topic.arn)

        stack_url = self._load_template_stack_url()
        cfn_conn = utility.get_boto_client(self.config, 'cloudformation')
        try:
            cfn_conn.update_stack(StackName=stack_name,
                                  TemplateURL=stack_url,
                                  Parameters=stack_params,
                                  NotificationARNs=notification_arns,
                                  Capabilities=['CAPABILITY_IAM'])
            is_successful = True
            print "Successfully issued update stack command for %s\n" % stack_name

        # Else stack doesn't currently exist, create a new stack
        # This excepted exception is too broad, pls narrow it as you come accross
        # exceptions that should be raised up
        except botocore.exceptions.ClientError as update_error:
            try:
                cfn_conn.create_stack(StackName=stack_name,
                                      TemplateURL=stack_url,
                                      Parameters=stack_params,
                                      NotificationARNs=notification_arns,
                                      Capabilities=['CAPABILITY_IAM'],
                                      DisableRollback=True,
                                      TimeoutInMinutes=TIMEOUT)
                is_successful = True
                print "Successfully issued create stack command for %s\n" % stack_name
            except botocore.exceptions.ClientError as create_error:
                logging.error("Create failed: \n\n{!s}\n".format(create_error))
                # Raise update_error because that one is more likely to explain why the
                # entire operation failed.
                raise update_error

        return is_successful
    def _ensure_stack_is_deployed(self, stack_name='UnnamedStack', sns_topic=None, stack_params=[]):
        is_successful = False
        notification_arns = []

        if sns_topic:
            notification_arns.append(sns_topic.arn)

        stack_url = self._load_template_stack_url()
        cfn_conn = utility.get_boto_client(self.config, 'cloudformation')
        try:
            cfn_conn.update_stack(
                StackName=stack_name,
                TemplateURL=stack_url,
                Parameters=stack_params,
                NotificationARNs=notification_arns,
                Capabilities=['CAPABILITY_IAM'])
            is_successful = True
            print "Successfully issued update stack command for %s\n" % stack_name

        # Else stack doesn't currently exist, create a new stack
        # This excepted exception is too broad, pls narrow it as you come accross 
        # exceptions that should be raised up
        except botocore.exceptions.ClientError as update_error:
            try:
                cfn_conn.create_stack(
                    StackName=stack_name,
                    TemplateURL=stack_url,
                    Parameters=stack_params,
                    NotificationARNs=notification_arns,
                    Capabilities=['CAPABILITY_IAM'],
                    DisableRollback=True,
                    TimeoutInMinutes=TIMEOUT)
                is_successful = True
                print "Successfully issued create stack command for %s\n" % stack_name
            except botocore.exceptions.ClientError as create_error:
                logging.error("Create failed: \n\n{!s}\n".format(create_error))
                # Raise update_error because that one is more likely to explain why the 
                # entire operation failed. 
                raise update_error

        return is_successful