Skip to content

Instantly share code, notes, and snippets.

@okram999
Last active December 2, 2020 05:10
Show Gist options
  • Save okram999/445e542bc3052102d0d9b60ed302e8f1 to your computer and use it in GitHub Desktop.
Save okram999/445e542bc3052102d0d9b60ed302e8f1 to your computer and use it in GitHub Desktop.
debug.py
import boto3
import logging
import sys
SESSION = boto3.session.Session()
CFT = SESSION.client('cloudformation')
LOGGER = logging.getLogger()
LOGGER.setLevel(logging.INFO)
HANDLER = logging.StreamHandler(sys.stdout)
HANDLER.setLevel(logging.DEBUG)
LOGGER.addHandler(HANDLER)
# ou_id = get_parent_for_account(account_id)
ss_url = 'https://marketplace-sa-resources.s3.amazonaws.com/ct-blogs-content/AWSControlTowerExecution.yml'
ss_deploy = {'Enabled': True, 'RetainStacksOnAccountRemoval': True}
ss_name = 'MyCrossAccountRole-StackSet'
ss_param = [{'ParameterKey': 'AdministratorAccountId', 'ParameterValue': '896638299127'}]
capabilites = ['CAPABILITY_NAMED_IAM']
result = False
op_id = None
ss_status = 'RUNNING'
try:
result = CFT.create_stack_set(StackSetName=ss_name,
Description='Cross account role creation for stacksets',
TemplateURL=ss_url,
Capabilities=capabilites,
Parameters=ss_param,
PermissionModel='SERVICE_MANAGED',
AutoDeployment=ss_deploy)
except Exception as exe:
error_msg = str(exe.response['Error']['Message'])
if 'StackSet already exists' in error_msg:
LOGGER.info('StackSet already exists, Adding stack instance')
result = True
else:
raise exe
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment