Skip to content

Instantly share code, notes, and snippets.

Bin packing containers onto hosts

Nathan Peck nathanpeck

Bin packing containers onto hosts
View GitHub Profile
nathanpeck /
Created Aug 16, 2021
Uninstall ECS Anywhere from a host, for reinstall, or registration with a different account/region/cluster
apt remove -y amazon-ssm-agent amazon-ecs-init
rm -rf /var/lib/amazon/ssm/Vault/Store/RegistrationKey
rm -rf /var/lib/ecs/ecs.config
rm -rf /etc/ecs/ecs.config
rm -rf /var/lib/ecs/data/*
View rough-load-test.js
var request = require('request');
var async = require('async');
var faker = require('faker');
var _ = require('lodash');
if (!process.env.PEAK_PERIOD_MINS) {
process.env.PEAK_PERIOD_MINS = '30';
var PEAK_PERIOD_MINS = parseInt(process.env.PEAK_PERIOD_MINS, 10) * 60 * 1000;
var MAX_CONCURRENT = parseInt(process.env.MAX_CONCURRENT, 10) || 100;
View x-ray-instrument-custom-namespace.js
// This handler function gets called for each SQS message that arrives in my process
mySqsHandler = function(msg) {
var self = this;
if (!msg.Attributes || !msg.Attributes.AWSTraceHeader) {
// This message was not selected for tracing by the sampler in
// a higher level service
runMySqsLogic(msg, function() {
// Noop, no segment to run
View cdk-prepare-method.ts
export class Service extends cdk.Construct implements ServiceInterface {
public addons: Map<string, ServiceAddon>;
protected taskDefinition: ecs.Ec2TaskDefinition;
protected service: ecs.Ec2Service;
readonly scope: cdk.Stack;
readonly id: string;
readonly vpc: ec2.Vpc;
readonly cluster: ecs.Cluster;
constructor(scope: cdk.Stack, id: string, props: ServiceProps) {
View interface-proposal.js
import dynamoStore = require('dynamodb-datastore');
import cdk = require('@aws-cdk/core');
import lambda = require('@aws-cdk/aws-lambda');
const app = new cdk.App();
class MyStack extends cdk.Stack {
constructor(scope: cdk.App, id: string, props?: cdk.StackProps) {
super(scope, id, props);
View desiredCountForService.ts
import AWS = require('aws-sdk');
const ecs_sdk = new AWS.ECS();
function chunk(array: Array<any>, size: number) {
const chunked_arr = [];
for (let i = 0; i < array.length; i++) {
const last = chunked_arr[chunked_arr.length - 1];
if (!last || last.length === size) {
} else {
nathanpeck / speed-ecs-deploy.ts
Created Aug 29, 2019
An AWS CDK deployment to AWS Fargte, optimized for speed
View speed-ecs-deploy.ts
import ec2 = require('@aws-cdk/aws-ec2');
import ecs = require('@aws-cdk/aws-ecs');
import elbv2 = require('@aws-cdk/aws-elasticloadbalancingv2');
import cdk = require('@aws-cdk/core');
class PublicFargateService extends cdk.Stack {
constructor(scope: cdk.App, id: string) {
super(scope, id);
// Create VPC and Fargate Cluster
View sample.yml
# The task definition. This is a simple metadata description of what
# container to run, and what resource requirements it has.
Type: AWS::ECS::TaskDefinition
Family: nginx-ingress
Cpu: 256
Memory: 128
- Name: nginx
View Autoscale an ECS Service.yml
AWSTemplateFormatVersion: '2010-09-09'
Description: Deploy a service into an ECS cluster with service discovery endpoint
Type: String
Default: production
Description: The name of the environment to add this service to
Type: String
Default: nginx
View Tasks.vue
<div class="hello">
<div class="task-list" v-if="tasks">
<div v-for="task in tasks.items" v-bind:key=''>
{{ task.clusterArn }} <br />
{{ }} <br /><br />
{{ task.lastStatus }} <br /><br />
{{ task.desiredStatus }} <br /><br />