我正在编写一个lambda函数来测试雅典娜表,我已经得到了那部分的工作。我试图重命名该函数创建的ResultConfiguration输出位置文件名,除非复制和删除,否则不能重命名。我得到无效的桶名每次它试图复制,我不知道为什么。这是我做了一些研究后的python代码:
def copy_delete_output_results(query_id, table_name):
oldCsvFileLocation = output + query_id + '.csv'
newOutputLocation = output + table_name
newFileName = table_name + '.csv'
s3.Object(newOutputLocation,newFileName).copy_from(CopySource=oldCsvFileLocation)
s3.Object(output,oldCsvFileLocation).delete()
oldCsvFileLocation = s3://ab-binaries-bucket-devtest/test/testQueryResults/1d8ab6ce-eda0-435f-93c3-2baa6fec8abd.csv
newOutputLocation = s3://ab-binaries-bucket-devtest/test/testQueryResults/dsm_abc_dns
newFileName = dsm_abc_dns.csv
错误信息:
Invalid bucket name "s3://ab-binaries-bucket-devtest/test/testQueryResults/dsm_abc_dns": Bucket name must match the regex "^[a-zA-Z0-9.-_]{1,255}$" or be an ARN matching the regex "^arn:(aws).*:(s3|s3-object-lambda):[a-z-0-9]*:[0-9]{12}:accesspoint[/:][a-zA-Z0-9-.]{1,63}$|^arn:(aws).*:s3-outposts:[a-z-0-9]+:[0-9]{12}:outpost[/:][a-zA-Z0-9-]{1,63}[/:]accesspoint[/:][a-zA-Z0-9-]{1,63}$"
对象有两个参数,第一个是桶名(字符串),第二个是文件键(字符串)。例如:
import boto3
s3 = boto3.resource('s3')
source_bucket_name = 'ab-binaries-bucket-devtest'
source_file_key = 'test/testQueryResults/1d8ab6ce-eda0-435f-93c3-2baa6fec8abd.csv'
destination_bucket_name = 'ab-binaries-bucket-devtest'
destination_file_key = 'test/testQueryResults/dsm_abc_dns/dsm_abc_dns.csv'
# Copy the file
s3.Object(destination_bucket_name, destination_file_key).copy_from(
CopySource={'Bucket': source_bucket_name, 'Key': source_file_key}
)
# Delete the original file
s3.Object(source_bucket_name, source_file_key).delete()
所以,你得到的错误是因为你在第一个参数中传递了完整的s3路径给s3。对象,而不是传递bucket-name