def get_role_arn_from_stack()

in AccountCreationLambda.py [0:0]


def get_role_arn_from_stack(cloudformation, stackid):
    """
	Uses the stack id to get the role arn from describe_stacks.
	"""

    if stackid is None:
        print("A stack id was not returned. Exiting")
        return None

    cloudformation_stack_description = cloudformation.describe_stacks(StackName=stackid)
    if "Stacks" in cloudformation_stack_description:
        Stacks = cloudformation_stack_description["Stacks"]
        if len(Stacks) > 0:
            if "Outputs" in Stacks[0]:
                Outputs = Stacks[0]["Outputs"]
                if len(Outputs) > 0:

                    if "OutputKey" in Outputs[0]:
                        print("Created a " + Outputs[0]["OutputKey"])
                        print("Created " + Outputs[0]["OutputValue"])
                        if Outputs[0]["OutputKey"] == "RoleArn":
                            print("Found role. Waiting 10 seconds before adding to CloudCheckr.")
                            # AWS makes you wait ten seconds before adding
                            # a role to CloudCheckr sometimes.
                            time.sleep(10)
                            return Outputs[0]["OutputValue"]
                        else:
                            if len(Outputs) > 1:
                                if "OutputKey" in Outputs[1]:
                                    print("Created a " + Outputs[1]["OutputKey"])
                                    print("Created " + Outputs[1]["OutputValue"])
                                    if Outputs[1]["OutputKey"] == "RoleArn":
                                        print("Found role. Waiting 10 seconds \
                                                before adding to CloudCheckr.")
                                        # AWS makes you wait ten seconds before
                                        # adding a role to CloudCheckr sometimes.
                                        time.sleep(10)
                                        return Outputs[1]["OutputValue"]
                                else:
                                    print(
                                        "First and second returned values in the stack \
                                        were neither a role arn. Investigate stack output")
                                    return None
                    else:
                        print("Could not find an output key in the first \
                                cloudformation stack output")
                else:
                    print("The number of Outputs was 0")
            else:
                print(
                    "Could not find Outputs in the first stack values. \
                            Trying again in 10 seconds to let stack complete")
                time.sleep(10)
                return get_role_arn_from_stack(cloudformation, stackid)
        else:
            print("The number of stacks was 0")
    else:
        print("Could not find any stacks in the cloudformation stack description")