def lambda_handler(event, context): print(json.dumps(event)) # Send the package to the build queue for any ECS instances to consume for package_dict in event['Records']: send_to_queue(BUILD_QUEUE, package_dict['body']) # Start a new task if it's less than the max required if get_running_task_count(ECS_CLUSTER, TASK_FAMILY) < MAX_TASK_COUNT: start_ecs_task(ECS_CLUSTER, TASK_DEFN) return return_code(200, {'status': 'Package building'})
def lambda_handler(event, context): print(json.dumps(event)) # Validate github token response = github_token_validator.validate(event) if response['statusCode'] != 200: print(f"Token not valid: {response}") return response commit_payload = json.loads(unquote(event['body']).replace("payload=", "")) full_name = get_full_name(commit_payload) branch = commit_payload['ref'].replace('refs/heads/', '') stage = 'prod' if branch == 'master' else 'dev' pkgbuild_location = get_pkgbuild_location(commit_payload) if pkgbuild_location is None: print("No PKGBUILD commit found, exiting") retval = { 'headers': { 'Content-Type': 'text/plain' }, 'body': 'No updated PKGBUILD found' } return return_code(401, retval) # Pull latest PKGBUILD print(f"Found PKGBUILD at {pkgbuild_location}") pkgbuild_url = f"https://raw.githubusercontent.com/{full_name}/{branch}/{pkgbuild_location}" with urlopen(pkgbuild_url) as resp: pkgbuild = resp.read().decode() github_repository = f"https://github.com/{full_name}.git" payload = json.dumps({ "payload": pkgbuild, "git_url": github_repository, "git_branch": branch, "stage": stage }) send_to_queue(NEXT_QUEUE, payload) return return_code(200, {'status': 'PKGBUILD extracted'})