7
6

More than 5 years have passed since last update.

AWSのLambdaで動いてるPythonをS3の署名バージョン4に対応させた

Posted at

はじめに

今話題のこちら
https://dev.classmethod.jp/cloud/aws/s3-sigv2-abolition/

S3の署名バージョン2に廃止に伴う対応です

慣れ親しんだ東京リージョンはこちらを参考にすると、バージョン 2 および 4

なので、対応は必須です!

前提条件

プログラムはAWSのLambdaで動いています

対応方法

基本的にはAWSの言う通りにやればおっけー!
https://docs.aws.amazon.com/ja_jp/AmazonS3/latest/dev/UsingAWSSDK.html#specify-signature-version

のはずが、、、

スクリーンショット 2019-03-22 10.24.46.png

botoデフォルト設定ファイル!?
.boto って事だよね。。。

Lambdaは認識しないんじゃ。。。

Lambdaで対応するための対応

botoのドキュメントに答えは書いてある!
https://boto3.amazonaws.com/v1/documentation/api/latest/guide/s3.html#generating-presigned-urls

@@ -2,8 +2,11 @@


+ from botocore.client import Config


@@ -25,7 +28,7 @@


-    s3 = boto3.resource('s3')
+    s3 = boto3.resource('s3', 'ap-northeast-1', config=Config(signature_version='s3v4'))


検証

以下を書いてログ出力

import botocore
botocore.session.Session().set_debug_logger()

ログ内容(色々MASKしてます)

〜
[DEBUG] 2019-03-20T06:20:12.515Z        〜
StringToSign:
AWS4-HMAC-SHA256
20190320T062012Z
20190320/ap-northeast-1/s3/aws4_request
〜

aws4_request を行っていることで、署名バージョン4を使っていることが判明

7
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
6