Skip to content

Instantly share code, notes, and snippets.

@squidarth
Created November 16, 2017 18:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save squidarth/7788903a280545dce7ec8fc8dedec123 to your computer and use it in GitHub Desktop.
Save squidarth/7788903a280545dce7ec8fc8dedec123 to your computer and use it in GitHub Desktop.
Mark Jenkins Runner Offline AWS Lambda
import sys
sys.path.append("./lib")
import os
import json
import requests
from requests.auth import HTTPBasicAuth
# This is a simple utility we wrote to pull
# down values from a config file in S3.
from s3_config import get_s3_config_val
def _mark_instance_offline(message):
parsed_message = json.loads(message)
github_access_token = get_s3_config_val()['GITHUB_ACCESS_TOKEN']
ec2_instance_id = parsed_message['EC2InstanceId']
resp = requests.post(
"http://{jenkins_master_ip}:{jenkins_master_port}/computer/{instance_id}/toggleOffline".format(
instance_id=ec2_instance_id,
jenkins_master_ip=os.environ['JENKINS_MASTER_STATIC_IP'],
jenkins_master_port="8080"
), auth=HTTPBasicAuth('github-username', github_access_token))
def event_handler(event, context):
message = event['Records'][0]['Sns']['Message']
print("Received payload: {}".format(message))
_mark_instance_offline(message)
return {"completed": True, 'message': message}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment