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
AWSTemplateFormatVersion: '2010-09-09'
Description: Deploy a service into an ECS cluster with service discovery endpoint
Parameters:
EnvironmentName:
Type: String
Default: production
Description: The name of the environment to add this service to
ServiceName:
Type: String
Default: nginx
<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>
{
"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"
@nathanpeck
nathanpeck / gist.js
Last active December 28, 2021 11:49
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
// 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++) {
const quargo = require('quargo');
const request = require('request');
const aw = require('awaitify-stream');
const byline = require('byline');
const MongoClient = require('mongodb').MongoClient;
var argv = require('minimist')(process.argv.slice(2));
// Read in the certificate authority file.
var ca = [require('fs').readFileSync(process.cwd() + '/connection/rds-ca-beta-2015-root.pem')];
# This is a Nginx sidecar. This is needed because Consul Connect proxy
# binds to localhost and doesn't accept direct traffic from the public.
# This Nginx container does though and can serve as a proxy to the proxy.
- Name: !Sub ${ServiceName}-nginx
Image: nginx
EntryPoint:
- '/bin/sh'
- '-c'
Command:
- >
const span = tracer.startSpan('ws');
span.setTag('service.name', 'frontend-ws');
span.setTag('resource.name', 'new message');
// Must call this otherwise asychronous trace spans don't show up under the overall span.
tracer.scopeManager().activate(span);
// Asynchronous code starts here.
// At some point in the future, right before the callback
TaskDefinition:
Type: AWS::ECS::TaskDefinition
Properties:
Family: my-app
Cpu: 512
Memory: 1024
NetworkMode: awsvpc
RequiresCompatibilities:
- FARGATE
ExecutionRoleArn: <execution role>