def _register_s3_location()

in migration/bring-your-own-gdc-assets/bring_your_own_gdc_assets.py [0:0]


def _register_s3_location(s3_path, role_arn, lf_client):
    '''
    Registers the S3 location of the glue table as Hybrid Mode to the lake formation with provided role arn, if role arn is not provided, use service linked role
    '''
    try:
        # Convert S3 path to arn
        resource_arn = f"arn:aws:s3:::{s3_path.replace('s3://', '')}"

        if role_arn:
            lf_client.register_resource(
                ResourceArn=resource_arn,
                RoleArn=role_arn,
                HybridAccessEnabled=True
            )
            print(f"Successfully registered {resource_arn} to {role_arn}")
        else:
            # if role arn for access is not provided by the user, AWSServiceRoleForLakeFormationDataAccess service linked role would be used
            lf_client.register_resource(
                ResourceArn=resource_arn,
                UseServiceLinkedRole=True,
                HybridAccessEnabled=True
            )
            print(f"Successfully registered {resource_arn} to AWSServiceRoleForLakeFormationDataAccess service linked role")

    except Exception as e:
        print(f"Error registering {resource_arn}: {str(e)}")
        raise e