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
TargetGroup:
Type: AWS::ElasticLoadBalancingV2::TargetGroup
Properties:
HealthCheckIntervalSeconds: 6
HealthCheckPath: /
HealthCheckProtocol: HTTP
HealthCheckTimeoutSeconds: 5
HealthyThresholdCount: 2
TargetType: ip
Name: !Ref 'ServiceName'
# Security group to add the Redis cluster to the VPC,
# and to allow the Fargate containers to talk to Redis on port 6379
RedisSecurityGroup:
Type: AWS::EC2::SecurityGroup
Properties:
GroupDescription: "Redis Security Group"
VpcId:
Fn::ImportValue:
!Join [':', [!Ref 'EnvironmentName', 'VPCId']]
RedisIngress:
TaskDefinition:
Type: AWS::ECS::TaskDefinition
Properties:
Family: !Ref 'ServiceName'
Cpu: !Ref 'ContainerCpu'
Memory: !Ref 'ContainerMemory'
NetworkMode: awsvpc
RequiresCompatibilities:
- FARGATE
ExecutionRoleArn:
# Enable autoscaling for the service
ScalableTarget:
Type: AWS::ApplicationAutoScaling::ScalableTarget
DependsOn: Service
Properties:
ServiceNamespace: 'ecs'
ScalableDimension: 'ecs:service:DesiredCount'
ResourceId:
Fn::Join:
- '/'
var store = {
data: {
typing: []
},
addTyper: function(typer) {
this.data.typing.push(typer);
}
};
<div id="content" class="content">
<room-details></room-details>
<messages></messages>
<typing></typing>
</div>
messages = await this.dynamoDB.query({
TableName: this.tableName,
KeyConditionExpression: 'room = :room',
Limit: 20,
ExpressionAttributeValues: {
':room': where.room
},
ExclusiveStartKey: where.message ? where : undefined,
ScanIndexForward: false // Always return newest items first
}).promise();
# A role for the service so it can access the tables
ChatServiceRole:
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Statement:
- Effect: Allow
Principal:
Service: "ecs-tasks.amazonaws.com"
Action: ['sts:AssumeRole']
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"]
$ time docker-compose build client
Building client
Step 1/9 : FROM node:9 AS build
---> 814364d36f69
Step 2/9 : WORKDIR /srv
---> Using cache
---> 031927a1a5ab
Step 3/9 : ADD package.json .
---> Using cache
---> 9cd95ef4d4ce