2017年11月18日土曜日

aws-cli の s3暗号化(SSE-C) 時、 "file://[鍵保存ファイル]" に改行があるとエラーになる


asw-cli で、ファイルに保存した鍵でS3暗号化(SSE-C)をしようとしたら以下のエラーになった。
[root@centos701 ~]# aws s3api put-object --bucket blue21neo --key test.txt --body test.txt --sse-customer-algorithm AES256 --sse-customer-key file://sse-key

An error occurred (InvalidArgument) when calling the PutObject operation: The secret key was invalid for the specified algorithm.


sse-keyファイルに改行コードが含まれていることが原因だった。
改行コードを含まないように、鍵をファイルに保存したら成功した。
[root@centos701 ~]# echo -n "6yPXi6lTRSzuOO9vLy3BTAavvbhimo4L" > sse-key
[root@centos701 ~]# aws s3api put-object --bucket blue21neo --key test.txt --body test.txt --sse-customer-algorithm AES256 --sse-customer-key file://sse-key
"de1ddf908bbf0b547bab82c8f87ec234"      AES256  j/r5InkOc5IeHPGharNZog==