Skip to content

Instantly share code, notes, and snippets.

@hirokazumiyaji
Last active August 29, 2015 14:27
Show Gist options
  • Save hirokazumiyaji/5c74b6a51723cae57c73 to your computer and use it in GitHub Desktop.
Save hirokazumiyaji/5c74b6a51723cae57c73 to your computer and use it in GitHub Desktop.
boto3 auto scaling
# coding: utf-8
from __future__ import absolute_import, print_function, unicode_literals
import session
class AutoScaling(object):
def __init__(self, name):
self._client = session.get(name).client('autoscaling')
def get_schedule(self, **kwargs):
response = self._client.describe_scheduled_actions(**kwargs)
return response['ScheduledUpdateGroupActions']
# coding: utf-8
from __future__ import absolute_import, print_function, unicode_literals
import threading
import boto3
__all__ = ["get"]
_LOCK = threading.Lock()
_CLIENTS = {}
class AutoScaling(object):
def __init__(self, name):
self._client = boto3.Session(profile_name=name).client('autoscaling')
def get_schedule(self, **kwargs):
response = self._client.describe_scheduled_actions(**kwargs)
return response['ScheduledUpdateGroupActions']
def get(name):
global _CLIENTS
if name in _CLIENTS:
return _CLIENTS[name]
return _set_and_get(name)
def _set_and_get(name):
global _LOCK
global _CLIENTS
with _LOCK:
if name in _CLIENTS:
return _CLIENTS[name]
result = _CLIENTS[name] = AutoScaling(name)
return result
# coding: utf-8
from __future__ import absolute_import, print_function, unicode_literals
import threading
import boto3
_LOCK = threading.Lock()
_SESSIONS = {}
def get(name):
if name in _SESSIONS:
return _SESSIONS[name]
return _set_and_get(name)
def _set_and_get(name):
with _LOCK:
if name in _SESSIONS:
return _SESSIONS[name]
result = _SESSION[name] = boto3.Session(profile_name=name)
return result
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment