in right_size_your_sagemaker_endpoints/api_helper.py [0:0]
def delete_infra(project_name, account_id, rest_api_id, models_list):
"""
Deletes infrastructure created for load testing
"""
try:
iam_client.detach_role_policy(
RoleName=f"LambdaRoleToInvokeSageMakerEndpoint{project_name}",
PolicyArn=f"arn:aws:iam::{account_id}:policy/LambdaSageMakerAccessPolicy{project_name}")
iam_client.delete_policy(
PolicyArn=f"arn:aws:iam::{account_id}:policy/LambdaSageMakerAccessPolicy{project_name}")
print("IAM Policy deleted.")
iam_client.delete_role(
RoleName=f"LambdaRoleToInvokeSageMakerEndpoint{project_name}")
print("IAM Role deleted.")
lambda_client.delete_function(
FunctionName=f'request-predictions-{project_name}')
print(f"Lambda Function request-predictions-{project_name} deleted.")
api_client.delete_rest_api(
restApiId=rest_api_id)
print(f"Rest API with id {rest_api_id} deleted.")
for model_name in models_list:
model_name.delete_model()
print(f"Model {model_name} deleted.")
print("All resources removed.")
except Exception as e:
print(f"Error deleting resources: {e}")
print("Please delete the resources manually to avoid costs.")