首页 > 解决方案 > 如何使用 Amazon 的 s3api 重命名文件?

问题描述

我正在使用 Amazon 的 s3api 接口尝试重命名我已经上传到存储桶的文件(在 bash 脚本中完成)。我想运行命令

aws s3api --recursive mv s3://$bucket_name/$file_name s3://$bucket_name/$file_name.$last_modified_file_date

但显然有些事情发生了变化,因为上述内容因错误而死

usage: aws [options] <command> <subcommand> [<subcommand> ...] [parameters]
To see help text, you can run:

  aws help
  aws <command> help
  aws <command> <subcommand> help
aws: error: argument operation: Invalid choice, valid choices are:

abort-multipart-upload                   | complete-multipart-upload               
copy-object                              | create-bucket                           
create-multipart-upload                  | delete-bucket

如何重命名存储桶中存在的文件?

标签: bashamazon-web-servicesamazon-s3rename

解决方案


您不能直接重命名 s3 中的文件,您唯一的选择是使用“mv”命令并为目标键使用新名称:

aws s3 --recursive mv s3://<bucket>/<old_key> s3://<bucket>/<new_key>

推荐阅读