-
-
Save squidarth/7788903a280545dce7ec8fc8dedec123 to your computer and use it in GitHub Desktop.
Mark Jenkins Runner Offline AWS Lambda
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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