Skip to content

Instantly share code, notes, and snippets.

@trylix
Created August 30, 2024 14:15
Show Gist options
  • Select an option

  • Save trylix/d0ab2f1a7ed301d52c33f898eacc40cb to your computer and use it in GitHub Desktop.

Select an option

Save trylix/d0ab2f1a7ed301d52c33f898eacc40cb to your computer and use it in GitHub Desktop.
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