Skip to content

Unable to perform start_remote_delete using AWS Transfer Family in Lambda (boto3 1.35.92)

0

I'm using a Python AWS Lambda function to transfer files from an external SFTP server to S3 using AWS Transfer Family. The start_file_transfer API works correctly and the files are successfully moved to S3.

However, I want to delete the source file from the SFTP server after the transfer using start_remote_delete. I confirmed that I’m using boto3 version 1.35.92, which should support this API based on the AWS documentation (April 2025 update).

Here is the Lambda code:

import boto3
import os

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}")

        # Now attempt to delete source files
        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)}"
        }

But I get this error in CloudWatch Logs:

AttributeError: 'Transfer' object has no attribute 'start_remote_delete'

Things I've tried:

  • Verified boto3 version inside Lambda: 1.35.92
  • Used correct transfer = boto3.client('transfer')
  • Checked AWS docs — start_remote_delete should be available

Do I need to update the runtime or boto3 layer differently? Or is this functionality not yet supported in Lambda despite being available in boto3?

Tags: aws-transfer-family, aws-lambda, boto3, python, sftp, s3

2 Answers
0

The issue you're encountering is related to the parameters and method name you're using for the delete operation. Based on the AWS Transfer Family documentation, there are a few corrections needed in your code:

  1. The correct method name is start_remote_delete (which you're using), but the parameter structure is incorrect.

  2. The parameter should be DeletePath (singular), not RemoteFilePaths. Each delete operation can only handle one file or directory at a time.

Here's how you should modify your delete operation code:

# For each file path you want to delete
for path in retrieve_paths:
delete_response = transfer.start_remote_delete(
ConnectorId=connector_id,
DeletePath=path  # Note: singular parameter name and only one path at a time
)
print(f"Delete started: {delete_response['DeleteId']}")  # Note: correct response field

A few important notes:

  • You must call start_remote_delete once for each file or directory you want to delete, as the command only accepts a single path as an argument.
  • The response will contain a DeleteId (not RemoteDeleteId).
  • If you need to delete multiple files, you can improve performance by creating concurrent sessions with remote servers that support it, allowing you to delete up to 5 files/directories in parallel.
  • Make sure your remote SFTP server supports delete operations.

If you're still encountering the "object has no attribute" error after making these changes, it could indicate that your Lambda environment's boto3 version doesn't actually match what you expect. You might need to:

  1. Update your Lambda function's runtime to a newer Python version
  2. Add a Lambda layer with the latest boto3 version
  3. Check if the Transfer Family connector has the necessary permissions to perform delete operations

The delete functionality was added relatively recently to AWS Transfer Family, so ensuring you have the latest boto3 version is important.
Sources
start_remote_delete - Boto3 1.37.31 documentation
StartRemoteDelete - AWS Transfer Family
Move, rename, or delete files or directories on the remote server - AWS Transfer Family
AWS Lambda error when using start_file_transfer() method | AWS re:Post

answered 9 months ago
EXPERT
reviewed 9 months ago
0

Hello.

"start_remote_delete" is a feature added in "1.37.29".
An explanation is given in the changelog below.
Therefore, I think you need to configure a Lambda layer to upgrade the boto3 version.
https://github.com/boto/boto3/blob/develop/CHANGELOG.rst

1.37.29
=======

* api-change:``bedrock``: [``botocore``] New options for how to handle harmful content detected by Amazon Bedrock Guardrails.
* api-change:``bedrock-runtime``: [``botocore``] New options for how to handle harmful content detected by Amazon Bedrock Guardrails.
* api-change:``codebuild``: [``botocore``] AWS CodeBuild now offers an enhanced debugging experience.
* api-change:``glue``: [``botocore``] Add input validations for multiple Glue APIs
* api-change:``medialive``: [``botocore``] AWS Elemental MediaLive now supports SDI inputs to MediaLive Anywhere Channels in workflows that use AWS SDKs.
* api-change:``personalize``: [``botocore``] Add support for eventsConfig for CreateSolution, UpdateSolution, DescribeSolution, DescribeSolutionVersion. Add support for GetSolutionMetrics to return weighted NDCG metrics when eventsConfig is enabled for the solution.
* api-change:``transfer``: [``botocore``] This launch enables customers to manage contents of their remote directories, by deleting old files or moving files to archive folders in remote servers once they have been retrieved. Customers will be able to automate the process using event-driven architecture.

The version of boto3 included in the Python 3.13 runtime is a little old, so try creating a layer and adding it.

START RequestId: 30fab158-661f-4bb8-9ee8-674f444fa3ed Version: $LATEST
boto3 version: 1.35.92
botocore version: 1.35.92

You can create a boto3 layer by running the following command from CloudShell.
https://docs.aws.amazon.com/cloudshell/latest/userguide/welcome.html

mkdir python
pip3 install boto3 -t ./python
zip -r ./python.zip .
aws lambda publish-layer-version --layer-name python-layer --zip-file fileb://python.zip --compatible-runtimes python3.13
aws lambda update-function-configuration --function-name "functionname" --layers arn:aws:lambda:<your-region>:<your-aws-account-id>:layer:python-layer:1
EXPERT
answered 9 months ago
EXPERT
reviewed 9 months ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.