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
@nathanpeck
nathanpeck / uninstall-ecs-anywhere.sh
Created August 16, 2021 22:05
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/*
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
@nathanpeck
nathanpeck / speed-ecs-deploy.ts
Created August 29, 2019 15:00
An AWS CDK deployment to AWS Fargte, optimized for speed
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
IMAGE_URL="httpd:2.4"
CPU=256
MEMORY=512
export TASK_DEFINITION=$(cat << EOF
{
"containerDefinitions": [
{
"command": [
"/bin/sh -c \"echo '<html> <head> <title>Amazon ECS Sample App</title> <style>body {margin-top: 40px; background-color: #333;} </style> </head><body> <div style=color:white;text-align:center> <h1>Amazon ECS Sample App</h1> <h2>Congratulations!</h2> <p>Your application is now running on a container in Amazon ECS.</p> </div></body></html>' > /usr/local/apache2/htdocs/index.html && httpd-foreground\""
TaskDefinition:
Type: AWS::ECS::TaskDefinition
Properties:
Family: nginx-ingress
Cpu: 256
Memory: 128
ContainerDefinitions:
- Name: nginx
Image: public.ecr.aws/nginx/nginx:mainline
EntryPoint:
// ==UserScript==
// @name Twitter L's
// @namespace http://tampermonkey.net/
// @version 0.1
// @description Replace Twitter Verified badge with a fat L
// @author You
// @match https://twitter.com/*
// @icon
// @grant none
// ==/UserScript==
TaskDefinition:
Type: AWS::ECS::TaskDefinition
Properties:
Family: !Ref 'ServiceName'
Cpu: !Ref 'ContainerCpu'
Memory: !Ref 'ContainerMemory'
NetworkMode: awsvpc
RequiresCompatibilities:
- FARGATE
ExecutionRoleArn:
@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
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;
TaskDefinition:
Type: AWS::ECS::TaskDefinition
Properties:
Family: my-app
Cpu: 512
Memory: 1024
NetworkMode: awsvpc
RequiresCompatibilities:
- FARGATE
ExecutionRoleArn: <execution role>