S3バケットのイベント通知一覧を取得する – AWS SDK for JavaScript v3

S3バケットのイベント通知一覧を取得する – AWS SDK for JavaScript v3

S3バケットのイベント通知を一覧取得します。

プロジェクト作成

npmプロジェクト作成します。

npm init -y

@aws-sdk/client-s3をインストールします。

npm i @aws-sdk/client-s3

ESMにするためにpackage.jsonに"type": "module"を1行追加します。

Lambda(node.js v16)

バケット名は設定が必要です。

import { GetBucketNotificationConfigurationCommand , S3Client } from '@aws-sdk/client-s3'
const bucketname = '<バケット名>'

export async function handler(event, context) {
  const client = new S3Client({
    region: 'ap-northeast-1'
  })
  const input = {
    Bucket: bucketname
  }
  const command = new GetBucketNotificationConfigurationCommand(input)
  const response = await client.send(command)
  console.log(response.LambdaFunctionConfigurations)
  return {
    statusCode: 200,
    body: `Hello`
  }
}

レスポンス

こんな感じです。イベント通知がない場合はEventBridgeConfiguration、LambdaFunctionConfigurations、QueueConfigurations、TopicConfigurationsにそれぞれundefinedが返ってきます。

{
  '$metadata': {
    httpStatusCode: 200,
    requestId: undefined,
    extendedRequestId: 'uLgS5LGv5Sz8ucEoqCjEEmkIK3Pq2k97siewV/5ih0Mlptm9bpD7DRE224hW98BF/9aJvelSaqc=',
    cfId: undefined,
    attempts: 1,
    totalRetryDelay: 0
  },
  EventBridgeConfiguration: undefined,
  LambdaFunctionConfigurations: undefined,
  QueueConfigurations: undefined,
  TopicConfigurations: undefined
}

参考サイト

GetBucketNotificationConfigurationCommand | @aws-sdk/client-s3
Documentation for @aws-sdk/client-s3

コメント

株式会社CONFRAGE ITソリューション事業部をもっと見る

今すぐ購読し、続きを読んで、すべてのアーカイブにアクセスしましょう。

続きを読む

タイトルとURLをコピーしました