def byos3tb_main()

in migration/bring-your-own-s3-tables/bring_your_own_s3_table_bucket.py [0:0]


def byos3tb_main():
    args = _parse_args()
    session = boto3.Session()
    if (args.region):
        session = boto3.Session(region_name=args.region)
    lf_client = session.client('lakeformation')
    glue_client = session.client('glue')
    s3tables_client = session.client('s3tables')
    
    current_region = session.region_name
    s3_table_bucket_region = args.table_bucket_arn.split(':')[3]
    if current_region != s3_table_bucket_region:
        raise Exception(f"Error: Current region '{current_region}' does not match the region of the S3 Table Bucket '{s3_table_bucket_region}'. Please ensure the region is correct.")

    try:
        account_id = args.table_bucket_arn.split(':')[4]
        _add_lf_admin(lf_client, account_id, args.execute)
        _register_resource(lf_client, args.table_bucket_arn, args.iam_role_arn_lf_resource_register, args.execute)
        _create_glue_catalog(glue_client, args.table_bucket_arn, args.execute)
        _grant_s3_table_bucket_lf_permissions(lf_client, s3tables_client, args.project_role_arn, args.table_bucket_arn, args.table_bucket_namespace, args.table_name, args.execute)
    except Exception as e:
        print(f"An error occurred during import S3 Table Bucket process: {e}")
        raise
    if args.execute:
        print("Successfully imported S3 Table Bucket to SMUS project")