Skip to content

Instantly share code, notes, and snippets.

View briancurt's full-sized avatar

Brian Curtich briancurt

View GitHub Profile
@bwhaley
bwhaley / gist:7383803e1dec6bff2ea05d8af634d5cb
Created December 4, 2019 06:34
rolling deployment method
"""Put ECS Instances in DRAINING state so that all ECS Tasks running on them are migrated to other Instances.
Batches into chunks of 10 because of AWS api limitations (An error occurred InvalidParameterException when
calling the UpdateContainerInstancesState operation: instanceIds can have at most 10 items)
"""
def put_container_instances_in_draining_state(ecs_client, cluster_name, container_instance_arns):
batch_size = 10
n_batches = math.ceil(len(container_instance_arns)/batch_size)
for i in range(0, len(container_instance_arns), batch_size):
logger.info('Putting batch %d/%d of container instances %s in cluster %s into DRAINING state', i+1, n_batches, container_instance_arns, cluster_name)
ecs_client.update_container_instances_state(cluster=cluster_name, containerInstances=container_instance_arns[i:i + batch_size], status='DRAINING')
@kevinmehall
kevinmehall / replace_ecs_cluster_instances.py
Last active February 20, 2022 23:24
Script to drain and replace EC2 instances in an ECS cluster auto-scaling group after changing the AMI or instance type
#!/usr/bin/env python3
#
# Script to replace EC2 instances in an ECS cluster's auto-scaling group after
# changing the AMI or instance type in the launch configuration. It
# checks for instances with the incorrect AMI or type, scales up the
# auto-scaling group with replacement instances, then drains the tasks
# from the old instances.
#
# Usage: aws-vault exec profile-name -- python3 replace_ecs_cluster_instances.py --group=asg-name --cluster=ecs-cluster-name --count=3
#
@polaskj
polaskj / deploy.sh
Last active October 27, 2022 10:20 — forked from dfetterman/lambda_function-ECS-cloudwatch-slack.py
Lambda function that takes ECS Cloudwatch events and sends a notification to Slack
#!/bin/bash
# deploy serverless stack
serverless deploy \
--stage "dev" \
--region "us-east-1" \
--service-name "my-service-name" \
--slack-channel "#slack-alerts-example" \
--webhook-url "https://hooks.slack.com/services/12345/12345/abcdefg" \
--ecs-cluster-arn "arn:aws:ecs:us-east-1:123456:cluster/test-cluster"
@CMCDragonkai
CMCDragonkai / http_streaming.md
Last active July 27, 2024 11:07
HTTP Streaming (or Chunked vs Store & Forward)

HTTP Streaming (or Chunked vs Store & Forward)

The standard way of understanding the HTTP protocol is via the request reply pattern. Each HTTP transaction consists of a finitely bounded HTTP request and a finitely bounded HTTP response.

However it's also possible for both parts of an HTTP 1.1 transaction to stream their possibly infinitely bounded data. The advantages is that the sender can send data that is beyond the sender's memory limit, and the receiver can act on