[Python] AWS Transfer Family: start_remote_delete not recognized in boto3 Lambda function...

Discussão em 'Python' iniciado por Stack, Julho 2, 2025.

  1. Stack

    Stack Membro Participativo

    I'm using an AWS Lambda function written in Python to transfer files from an external SFTP server to an S3 bucket via AWS Transfer Family. The file transfer works perfectly using start_file_transfer.

    Now I want to delete the file from the SFTP server after the transfer using start_remote_delete, which according to AWS docs (April 2025), is supported.

    However, I get this error when invoking it:

    pgsql AttributeError: 'Transfer' object has no attribute 'start_remote_delete' I confirmed that my boto3 version is 1.35.92 within the Lambda environment. Here's the function:

    Here’s my code:

    transfer = boto3.client('transfer')

    def lambda_handler(event, context):
    connector_id = os.environ['CONNECTOR_ID']
    retrieve_paths = ['/1000095842.jpg']
    local_s3_path = '/jams-ftp-process-bucket/ftp-listings'

    try:
    response = transfer.start_file_transfer(
    ConnectorId=connector_id,
    RetrieveFilePaths=retrieve_paths,
    LocalDirectoryPath=local_s3_path
    )
    transfer_id = response['TransferId']
    print(f"Transfer started: {transfer_id}")

    # Attempt to delete after transfer
    delete_response = transfer.start_remote_delete(
    ConnectorId=connector_id,
    RemoteFilePaths=retrieve_paths
    )
    print(f"Delete started: {delete_response['RemoteDeleteId']}")

    return {
    'statusCode': 200,
    'body': f"Transfer and delete started: {transfer_id}"
    }

    except Exception as e:
    print(f"Error during transfer or deletion: {str(e)}")
    return {
    'statusCode': 500,
    'body': f"Operation failed: {str(e)}"
    }


    Expected: File transfers to S3 → then deleted from source SFTP.

    Got: AttributeError that start_remote_delete does not exist.

    Continue reading...

Compartilhe esta Página