in source/Lambda/innovation_accept_resource_share.py [0:0]
def accept_resource_share_sbx(credentials):
client = boto3.client('ram',
aws_access_key_id=credentials['AccessKeyId'],
aws_secret_access_key=credentials['SecretAccessKey'],
aws_session_token=credentials['SessionToken'],
region_name=boto3.session.Session().region_name+"",
config=config
)
# Check if resource share invitation is auto-accepted
try:
resource_shares = client.get_resource_shares(resourceOwner='OTHER-ACCOUNTS')
if len(resource_shares["resourceShares"]) > 0:
for r in resource_shares["resourceShares"]:
if r["name"] == "ISTGWShareAppStream" and r["status"] == "ACTIVE":
return
except Exception as e:
message = {'MESSAGE': 'Exception while getting resource shares in the Sandbox Account','FILE': __file__.split('/')[-1],
'METHOD': inspect.stack()[0][3], 'EXCEPTION': str(e), 'TRACE': traceback.format_exc()}
logger.exception(message)
raise
rs_arn = None
try:
response = client.get_resource_share_invitations()
logger.info(response)
if len(response['resourceShareInvitations']) != 0:
for r in response['resourceShareInvitations']:
if r["resourceShareName"] == "ISTGWShareAppStream":
rs_arn = r["resourceShareInvitationArn"]
break
except Exception as e:
message = {'MESSAGE': 'Exception ocurred while fetching TGW resource share invitation in the Sandbox Account',
'FILE': __file__.split('/')[-1], 'METHOD': inspect.stack()[0][3], 'EXCEPTION': str(e), 'TRACE': traceback.format_exc()}
logger.exception(message)
raise
if rs_arn is None:
message = {'MESSAGE': 'No resource share invitations found', 'FILE': __file__.split('/')[-1],
'METHOD': inspect.stack()[0][3], 'MESSAGE': 'No resource share invitations found'}
logger.exception(message)
raise Exception("No resource share invitations found")
try:
accept_inv = client.accept_resource_share_invitation(
resourceShareInvitationArn=rs_arn,
clientToken='xyz_abcd9991'
)
except Exception as e:
message = {'MESSAGE': 'Unable to accept TGW resource share invitation in the Sandbox Account', 'FILE': __file__.split('/')[-1],
'METHOD': inspect.stack()[0][3], 'EXCEPTION': str(e), 'TRACE': traceback.format_exc()}
logger.exception(message)
raise
return