Skip to content

Instantly share code, notes, and snippets.

@shiro01
Created October 17, 2018 05:33
Show Gist options
  • Save shiro01/e5069ffbc0ce313a8e3ff2eac2b3fada to your computer and use it in GitHub Desktop.
Save shiro01/e5069ffbc0ce313a8e3ff2eac2b3fada to your computer and use it in GitHub Desktop.
S3のファイルをコピーする
# S3バケット内のファイルコピー
def athena_query_result_copy(target_bucket, target_key, output_bucket, output_key):
s3client = boto3.client('s3')
s3client.copy_object(
Bucket=output_bucket,
Key=output_key,
CopySource={
'Bucket': target_bucket,
'Key': target_key
}
)
#
# Lambdaで実施する場合、S3へのアクセス可能なロールが必要
#
# コピー実施前
# s3:test_bucket
# └hoge
# └hoge.txt
#
# コピー実施後
# s3:test_bucket
# └hoge
# └hoge.txt
# └foo
# foo.txt ←作成される。
#
# target__bucket = test_bucket
# target_key = 'hoge/hoge.txt'
# output_bucket = test_bucket
# output_key = 'foo/foo.txt'
# athena_query_result_copy(target__bucket, target_key, output_bucket, output_key)
#
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment