LoginSignup
1
1

More than 3 years have passed since last update.

AWS LambdaにてPython3でS3でファイルが追加されたイベントを取得し、実行する。

Posted at

概要

調べたので備忘録

手順

  1. Lambda上部のデザイナーから「トリガーを追加」をクリック
    image.png

  2. S3を選択

image.png

  1. 対象バケットを選択、「全てのオブジェクト作成イベント」を選びます。 image.png

※必要あればプレフィックスなどは自由に設定してください。

変更後、「保存」をクリックしてください。

  1. コードはこんな感じで取得できます。
def lambda_handler(event, context):
    for record in event['Records']:
        bucket = record['s3']['bucket']['name']
        key = record['s3']['object']['key']
        exec(bucket,key)

※アクセス権限の設定がない場合は失敗する可能性があります。

参考

サンプル Amazon S3 関数コード
https://docs.aws.amazon.com/ja_jp/lambda/latest/dg/with-s3-example-deployment-pkg.html#with-s3-example-deployment-pkg-python

1
1
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
1