- Newest
- Most votes
- Most comments
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:
-
The correct method name is
start_remote_delete(which you're using), but the parameter structure is incorrect. -
The parameter should be
DeletePath(singular), notRemoteFilePaths. 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_deleteonce 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(notRemoteDeleteId). - 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:
- Update your Lambda function's runtime to a newer Python version
- Add a Lambda layer with the latest boto3 version
- 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
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
Relevant content
- asked a year ago
- asked 2 years ago
