LoginSignup
1
0

More than 3 years have passed since last update.

AWS KMSで暗号化されたS3オブジェクトの期限付きURL(PreSignedURL)を、Nodejsで発行する

Posted at

こういう状態のオブジェクトを想定。
スクリーンショット 2019-06-24 15.52.29.png

一般的な書き方

import { S3 } from 'aws-sdk'

const client = new S3()

client.getSignedUrl('getObject', {
  Bucket: 'BUCKET_NAME',
  Key: 'OBJECT_KEY',
  Expires: 60 * 60 * 24 * 2
}, (e, r) => {
  console.log(e)
  console.log(r)
})

結果

URLは発行されるのですが、暗号化されているオブジェクトは、HTTP403が返ってきます。
スクリーンショット 2019-06-24 15.57.04.png

対応

クラスを初期化する際にsignatureVersionを渡してやりましょう。

import { S3 } from 'aws-sdk'

const client = new S3({
  signatureVersion: 's3v4'
})

client.getSignedUrl('getObject', {
  Bucket: 'BUCKET_NAME',
  Key: 'OBJECT_KEY',
  Expires: 60 * 60 * 24 * 2
}, (e, r) => {
  console.log(e)
  console.log(r)
})
1
0
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
1
0