Skip to content

Instantly share code, notes, and snippets.

View omerxx's full-sized avatar
🎱
All is as thinking makes it so

Omer Hamerman omerxx

🎱
All is as thinking makes it so
View GitHub Profile
@omerxx
omerxx / create_slave.py
Last active May 6, 2016 12:09
Jenkins SSH node creation with auto registration using python jenkinsapi
from jenkinsapi.jenkins import Jenkins
from jenkinsapi.utils.requester import Requester
from subprocess import check_output
import requests
requests.packages.urllib3.disable_warnings()
# Using AWS AMI allows using the private IP and AWS instance name for the node's registration
# Change these value if you're using other AMI or not using AWS at all
instance_name = check_output(["ec2-metadata", "-i"]).split()[1]
instance_ip = check_output(["ec2-metadata", "-o"]).split()[1]
FROM python
RUN apt-get update && apt-get install -y \
vim \
curl
LABEL image.version="0.0.1-beta"
payload = {"channel": "#general", "username": "webhookbot", "text": "Testing slack webhook", "icon_emoji": ":ghost:"}
url = 'https://hooks.slack.com/services/0000000000/0000000000/0000000000'
requests.post(url, data=json.dumps(payload))
@omerxx
omerxx / chaos.py
Last active April 27, 2017 13:01
Lambda function for killing random task on an ecs family
def lambda_handler(event, context):
import boto3
client = boto3.client('ecs', aws_access_key_id='', aws_secret_access_key='')
response = client.list_tasks(cluster='mycluster', family='myservice', maxResults=1,desiredStatus='RUNNING')
stoptask = response['taskArns'][0].split('/')[1]
print client.stop_task(cluster='mycluster', task=stoptask, reason='chaos monkey')
import os
import boto3
import datetime
import dateutil
DEFAULT_MAX_MEM = 3000
LOW_CLUSTER_CPU_TH = 20
HIGH_CLUSTER_CPU_TH = 65
CONTAINERS_MAX_MEM = {
'cluster1': 1200,
@omerxx
omerxx / example.yaml
Created August 31, 2017 13:47
Multi Container TaskDefinition in ECS, linked and mounted with Docker daemon
TaskDefinition:
Type: AWS::ECS::TaskDefinition
Properties:
Family: !Ref ServiceName
ContainerDefinitions:
- Name: !Sub ${ServiceName}-container
Essential: true
Image: !Ref DockerImage
Memory: !Ref Memory
PortMappings:
Resources:
ECSCluster:
Type: AWS::ECS::Cluster
Properties:
ClusterName: !Ref EnvironmentName
ECSAutoScalingGroup:
Type: AWS::AutoScaling::AutoScalingGroup
Properties:
VPCZoneIdentifier: !Ref Subnets
Resources:
Service:
Type: AWS::ECS::Service
DependsOn: ListenerRule
Properties:
Cluster: !Ref Cluster
ServiceName: !Ref ServiceName
LaunchType: !Ref LaunchType
DesiredCount: !Ref DesiredCount
DeploymentConfiguration:
TaskDefinition:
Type: AWS::ECS::TaskDefinition
Properties:
Cpu: !Ref VCpu
RequiresCompatibilities:
- !Ref RequiresCompatibilities
Family: !Ref ServiceName
NetworkMode: !Ref NetworkMode
ExecutionRoleArn: arn:aws:iam::000:role/EcsTaskExecutionRole
TaskRoleArn: arn:aws:iam::000:role/EcsTaskExecutionRole
TargetGroup:
Type: AWS::ElasticLoadBalancingV2::TargetGroup
Properties:
VpcId: !Ref VPC
Port: 80
Protocol: HTTP
Matcher:
HttpCode: 200-299
HealthCheckIntervalSeconds: 80
HealthCheckPath: !Ref HealthCheckPath