Skip to content

Instantly share code, notes, and snippets.

Bin packing containers onto hosts

Nathan Peck nathanpeck

Bin packing containers onto hosts
Block or report user

Report or block nathanpeck

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
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 />
View sample-ecs-event.json
"version": "0",
"id": "16bd6507-21ed-3ab0-78d1-f0c546ba54c2",
"detail-type": "ECS Task State Change",
"source": "aws.ecs",
"account": "209640446841",
"time": "2019-05-31T19:17:34Z",
"region": "us-east-2",
"resources": [
View gist.js
export class MyEcsConstructStack extends cdk.Stack {
constructor(scope: cdk.App, id: string, props?: cdk.StackProps) {
super(scope, id, props);
const vpc = new ec2.VpcNetwork(this, 'MyVpc', {
maxAZs: 3 // Default is all AZs in region
const cluster = new ecs.Cluster(this, 'MyCluster', {
vpc: vpc
View sample-cdk.js
// Create a lambda that recrawls changelogs discovered in the past
const recrawlLambda = new lambda.Function(this, 'recrawl', {
runtime: lambda.Runtime.NodeJS810,
handler: 'recrawl.handle',
code: lambda.Code.asset('./app/recrawl'),
timeout: 360,
environment: {
CHANGELOGS_TABLE_NAME: props.changelogsTable.tableName,
DISCOVERED_TOPIC_NAME: props.toCrawlTopic.topicArn
View perf.js
const cluster = require('cluster');
const numWorkers = 4;
let totalTrials = 0;
const numOpsToRunPerTrial = 5000000;
if (cluster.isMaster) {
console.log(`Master ${} is running`);
// Fork workers.
for (let i = 0; i < numWorkers; i++) {
You can’t perform that action at this time.