Skip to content
This repository has been archived by the owner on Feb 12, 2024. It is now read-only.

Commit

Permalink
add assume role (#39)
Browse files Browse the repository at this point in the history
Co-authored-by: Puneeth Nanjundaswamy <puneeth@m1.fritz.box>
  • Loading branch information
Puneeth-n and Puneeth Nanjundaswamy committed Feb 14, 2022
1 parent 47fd39a commit 342a808
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions ecs-cluster/scripts/assume_role.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
'''
Return STS credentials
'''

import boto3
import logging as log


def get_temporary_credentials(role_to_assume, region, session_name, duration_seconds=3600):
'''
Return temporary credentials
'''

log.info('Assuming role {} in region {} with session name {} for {} seconds'.format(
role_to_assume, region, session_name, duration_seconds))

sts_client = boto3.client('sts', region_name=region)
assumed_role = sts_client.assume_role(RoleArn=role_to_assume,
RoleSessionName=session_name,
DurationSeconds=duration_seconds)

return assumed_role['Credentials']

0 comments on commit 342a808

Please sign in to comment.