Created
August 30, 2024 14:15
-
-
Save trylix/d0ab2f1a7ed301d52c33f898eacc40cb to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| import boto3 | |
| ecs_client = boto3.client('ecs') | |
| elbv2_client = boto3.client('elbv2') | |
| def lambda_handler(event, context): | |
| branch_name = event['branch_name'] | |
| cluster_name = event['cluster_name'] | |
| service_name = f"my-service-{branch_name}" | |
| listener_arn = event['listener_arn'] | |
| # Deletar Serviço ECS | |
| ecs_client.update_service( | |
| cluster=cluster_name, | |
| service=service_name, | |
| desiredCount=0 | |
| ) | |
| ecs_client.delete_service( | |
| cluster=cluster_name, | |
| service=service_name, | |
| force=True | |
| ) | |
| # Deletar Regras ALB | |
| rules = elbv2_client.describe_rules( | |
| ListenerArn=listener_arn | |
| ) | |
| for rule in rules['Rules']: | |
| for condition in rule['Conditions']: | |
| if 'Values' in condition and f"/{branch_name}/*" in condition['Values']: | |
| elbv2_client.delete_rule( | |
| RuleArn=rule['RuleArn'] | |
| ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment