in rdk/rdk.py [0:0]
def undeploy(self):
self.__parse_deploy_args(ForceArgument=True)
if not self.args.force:
confirmation = False
while not confirmation:
my_input = input("Delete specified Rules and Lambda Functions from your AWS Account? (y/N): ")
if my_input.lower() == "y":
confirmation = True
if my_input.lower() == "n" or my_input == "":
sys.exit(0)
#get the rule names
rule_names = self.__get_rule_list_for_command()
#create custom session based on whatever credentials are available to us.
my_session = self.__get_boto_session()
print(f"[{my_session.region_name}]: Running un-deploy!")
#Collect a list of all of the CloudFormation templates that we delete. We'll need it at the end to make sure everything worked.
deleted_stacks = []
cfn_client = my_session.client('cloudformation')
if self.args.functions_only:
try:
cfn_client.delete_stack(StackName=self.args.stack_name)
deleted_stacks.append(self.args.stack_name)
except ClientError as ce:
print(f"[{my_session.region_name}]: Client Error encountered attempting to delete CloudFormation stack for Lambda Functions: " + str(ce))
except Exception as e:
print(f"[{my_session.region_name}]: Exception encountered attempting to delete CloudFormation stack for Lambda Functions: " + str(e))
return
for rule_name in rule_names:
try:
cfn_client.delete_stack(StackName=self.__get_stack_name_from_rule_name(rule_name))
deleted_stacks.append(self.__get_stack_name_from_rule_name(rule_name))
except ClientError as ce:
print(f"[{my_session.region_name}]: Client Error encountered attempting to delete CloudFormation stack for Rule: " + str(ce))
except Exception as e:
print(f"[{my_session.region_name}]: Exception encountered attempting to delete CloudFormation stack for Rule: " + str(e))
print(f"[{my_session.region_name}]: Rule removal initiated. Waiting for Stack Deletion to complete.")
for stack_name in deleted_stacks:
self.__wait_for_cfn_stack(cfn_client, stack_name)
print(f"[{my_session.region_name}]: Rule removal complete, but local files have been preserved.")
print(f"[{my_session.region_name}]: To re-deploy, use the 'deploy' command.")