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
}
参考サイト
AWS SDK for JavaScript v3
API Reference

KHI入社して退社。今はCONFRAGEで正社員です。関西で140-170/80~120万から受け付けております^^
得意技はJS(ES20xx),Java,AWSの大体のリソースです
コメントはやさしくお願いいたします^^
座右の銘は、「狭き門より入れ」「願わくは、我に七難八苦を与えたまえ」です^^

コメント