Created
March 27, 2021 13:40
-
-
Save gmariette/8507e55676efc0ad6f9425aa56c05102 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| def assumeRole(self, action): | |
| client = self.initStsClient() | |
| assumedRoleObject = client.assume_role( | |
| RoleArn="arn:aws:iam::"+self.aws_accounts[self.env]["id"]+":role/"+self.aws_accounts[self.env]["role"], | |
| RoleSessionName="Drp-" + action | |
| ) | |
| credentials=assumedRoleObject['Credentials'] | |
| ACCESS_KEY=credentials.get("AccessKeyId") | |
| SECRET_KEY=credentials.get("SecretAccessKey") | |
| SESSION_TOKEN=credentials.get("SessionToken") | |
| return ACCESS_KEY, SECRET_KEY, SESSION_TOKEN | |
| def initeASGClient(self, action): | |
| ''' | |
| DOCSTRING: Return the autoscaling client | |
| INPUT: None | |
| OUTPUT: boto3.client('autoscaling') | |
| ''' | |
| ACCESS_KEY, SECRET_KEY, SESSION_TOKEN = self.assumeRole(action) | |
| self.logger.debug('Launching asg client with role %s on the account %s', self.aws_accounts[self.env]["role"], self.aws_accounts[self.env]["id"]) | |
| return boto3.Session( | |
| region_name=self.aws_accounts[self.env]["region"], | |
| aws_access_key_id=ACCESS_KEY, | |
| aws_secret_access_key=SECRET_KEY, | |
| aws_session_token=SESSION_TOKEN | |
| ).client('autoscaling') | |
| def describeASG(self): | |
| ''' | |
| DOCSTRING: List available ASGs | |
| INPUT: None | |
| OUTPUT: ASGs available | |
| ''' | |
| # Client init | |
| client = self.initeASGClient("DescribeASG") | |
| return client.describe_auto_scaling_groups()['AutoScalingGroups'] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment