Skip to content

Instantly share code, notes, and snippets.

View nathanpeck's full-sized avatar
📦
Bin packing containers onto hosts

Nathan Peck nathanpeck

📦
Bin packing containers onto hosts
View GitHub Profile
FROM node:9 AS build
WORKDIR /srv
ADD package.json .
RUN npm install
FROM node:9-slim
COPY --from=build /srv .
ADD . .
EXPOSE 3000
CMD ["node", "index.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
}
const cluster = require('cluster');
const numWorkers = 4;
let totalTrials = 0;
const numOpsToRunPerTrial = 5000000;
if (cluster.isMaster) {
console.log(`Master ${process.pid} is running`);
// Fork workers.
for (let i = 0; i < numWorkers; i++) {
{
"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": [
"arn:aws:ecs:us-east-2:209640446841:task/344b1ff0-b9c8-43d6-b7ba-73eccaae0f66"
<template>
<div class="hello">
<h1>Tasks</h1>
<div class="task-list" v-if="tasks">
<div v-for="task in tasks.items" v-bind:key='task.id'>
{{ task.clusterArn }} <br />
{{ task.id }} <br /><br />
{{ task.lastStatus }} <br /><br />
{{ task.desiredStatus }} <br /><br />
</div>
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) {
chunked_arr.push([array[i]]);
} else {
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);
TargetGroup:
Type: AWS::ElasticLoadBalancingV2::TargetGroup
Properties:
HealthCheckIntervalSeconds: 6
HealthCheckPath: /
HealthCheckProtocol: HTTP
HealthCheckTimeoutSeconds: 5
HealthyThresholdCount: 2
TargetType: ip
Name: !Ref 'ServiceName'
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) {

The information below was written in Oct 2017. In August 2019 AWS launched official support for multiple target groups per AWS ECS service. Please use that feature instead!


Unfortunately as of writing this (Oct 18, 2017) there is no built in integration for multiple target groups per AWS ECS service. Here are a few things you can try:

  1. If your application just serves port 80 (HTTP) & port 443 (HTTPS) then you should consider using the application load balancer and terminating SSL at the load balancer. This will allow your application to function using just port 80.