File tree Expand file tree Collapse file tree 1 file changed +14
-2
lines changed
Expand file tree Collapse file tree 1 file changed +14
-2
lines changed Original file line number Diff line number Diff line change @@ -153,11 +153,21 @@ def delete(event: dict, context: LambdaContext):
153153 logger .info (f"Disabled { policy_type } policy type" )
154154
155155 logger .debug ("Disabling organizations root sessions..." )
156- iam .disable_organizations_root_sessions ()
156+ try :
157+ iam .disable_organizations_root_sessions ()
158+ except iam .exceptions .ServiceAccessNotEnabledException :
159+ pass
160+ except iam .exceptions .OrganizationNotFoundException :
161+ pass
157162 logger .info ("Disabled organizations root sessions" )
158163
159164 logger .debug ("Disabling organizations root credentials management..." )
160- iam .disable_organizations_root_credentials_management ()
165+ try :
166+ iam .disable_organizations_root_credentials_management ()
167+ except iam .exceptions .ServiceAccessNotEnabledException :
168+ pass
169+ except iam .exceptions .OrganizationNotFoundException :
170+ pass
161171 logger .info ("Disabled organizations root credentials management" )
162172
163173 for service_principal in SERVICE_PRINCIPALS :
@@ -166,6 +176,8 @@ def delete(event: dict, context: LambdaContext):
166176 organizations .disable_aws_service_access (ServicePrincipal = service_principal )
167177 except organizations .exceptions .ConcurrentModificationException :
168178 time .sleep (0.1 )
179+ except organizations .exceptions .AWSOrganizationsNotInUseException :
180+ pass
169181 logger .info (f"Disabled AWS service access for { service_principal } " )
170182
171183
You can’t perform that action at this time.
0 commit comments