2017-08-08 7 views
1

AWS S3 Bucketでトリガをプログラムで作成できるかどうか不思議です。S3-BucketにCLIを使用してAWS-Lambdaベースのトリガーを追加する方法

S3-BucketとAWS Lambda関数があります。 AWSラムダ関数はCLIごとに作成され、CLIベースのコマンドを使用していつでも更新/再作成できます。

aws lambda create-function \ 
--region us-east-1 \ 
--function-name encodeVideo \ 
--zip-file fileb:///tmp/encode_video.zip \ 
--role $LAMBDA_ROLE_ARN \ 
--handler encode_video.handler \ 
--runtime nodejs6.10 \ 
--timeout 10 \ 
--memory-size 1024 


aws lambda add-permission \ 
--function-name encodeVideo \ 
--region us-east-1 \ 
--statement-id some-unique-id \ 
--action "lambda:InvokeFunction" \ 
--principal s3.amazonaws.com \ 
--source-arn arn:aws:s3:::**** \ 
--source-account *********** 

ここで、作成した新しいオブジェクトごとに自動的にラムダ関数を呼び出すS3バケットを設定します。

今のところ私はスクリーンショットで見ることができるように、AWS ConsoleのWebブラウザでこれを行いました。しかし、私はCLIコマンドでシナリオ全体をセットアップできるようにしたい。これどうやってするの?

私はそれはのようなものが必要であることを考え出した:

aws s3api put-bucket-notification-configuration --region us-east-1 \ 
--bucket **** \ 
--notification-configuration file://encodeVideoConfiguration.json 

しかし、私はencodeVideoConfiguration.jsonの内容がどうあるべきかを見つけ出すことができませんでしたか?

enter image description here

答えて

2

--notification-configurationの文書構造が同一コールのためAWS CLI docsでで詳細に記載されている:あなたのケースのために

{ 
    "TopicConfigurations": [ 
    { 
     "Id": "string", 
     "TopicArn": "string", 
     "Events": ["s3:ReducedRedundancyLostObject"|"s3:ObjectCreated:*"|"s3:ObjectCreated:Put"|"s3:ObjectCreated:Post"|"s3:ObjectCreated:Copy"|"s3:ObjectCreated:CompleteMultipartUpload"|"s3:ObjectRemoved:*"|"s3:ObjectRemoved:Delete"|"s3:ObjectRemoved:DeleteMarkerCreated", ...], 
     "Filter": { 
     "Key": { 
      "FilterRules": [ 
      { 
       "Name": "prefix"|"suffix", 
       "Value": "string" 
      } 
      ... 
      ] 
     } 
     } 
    } 
    ... 
    ], 
    "QueueConfigurations": [ 
    { 
     "Id": "string", 
     "QueueArn": "string", 
     "Events": ["s3:ReducedRedundancyLostObject"|"s3:ObjectCreated:*"|"s3:ObjectCreated:Put"|"s3:ObjectCreated:Post"|"s3:ObjectCreated:Copy"|"s3:ObjectCreated:CompleteMultipartUpload"|"s3:ObjectRemoved:*"|"s3:ObjectRemoved:Delete"|"s3:ObjectRemoved:DeleteMarkerCreated", ...], 
     "Filter": { 
     "Key": { 
      "FilterRules": [ 
      { 
       "Name": "prefix"|"suffix", 
       "Value": "string" 
      } 
      ... 
      ] 
     } 
     } 
    } 
    ... 
    ], 
    "LambdaFunctionConfigurations": [ 
    { 
     "Id": "string", 
     "LambdaFunctionArn": "string", 
     "Events": ["s3:ReducedRedundancyLostObject"|"s3:ObjectCreated:*"|"s3:ObjectCreated:Put"|"s3:ObjectCreated:Post"|"s3:ObjectCreated:Copy"|"s3:ObjectCreated:CompleteMultipartUpload"|"s3:ObjectRemoved:*"|"s3:ObjectRemoved:Delete"|"s3:ObjectRemoved:DeleteMarkerCreated", ...], 
     "Filter": { 
     "Key": { 
      "FilterRules": [ 
      { 
       "Name": "prefix"|"suffix", 
       "Value": "string" 
      } 
      ... 
      ] 
     } 
     } 
    } 
    ... 
    ] 
} 

、あなただけのJSON構造のLambdaFunctionConfigurations場を提供したいです。

関連する問題