0

I am testing adding a watermark to a video once uploaded. I am running into an issue where lamdba wants me to specify which file to change on upload. but i want it to trigger when any (really, any file that ends in .mov, .mp4, etc.) file is uploaded.

To clarify, this all works manually in creating a pipeline and job.

Here's my code:

    require 'json'
    require 'aws-sdk-elastictranscoder'


    def lambda_handler(event:, context:)
      client = Aws::ElasticTranscoder::Client.new(region: 'us-east-1')

        resp = client.create_job({
      pipeline_id: "15521341241243938210-qevnz1", # required
      input: {
        key: File, #this is where my issue
        },
      output: {
    key: "CBtTw1XLWA6VSGV8nb62gkzY",
    # thumbnail_pattern: "ThumbnailPattern",
    # thumbnail_encryption: {
    #   mode: "EncryptionMode",
    #   key: "Base64EncodedString",
    #   key_md_5: "Base64EncodedString",
    #   initialization_vector: "ZeroTo255String",
    # },
    # rotate: "Rotate",
    preset_id: "1351620000001-000001",
    # segment_duration: "FloatString",
    watermarks: [
      {
        preset_watermark_id: "TopRight",
        input_key: "uploads/2354n.jpg",
        # encryption: {
        #   mode: "EncryptionMode",
        #   key: "zk89kg4qpFgypV2fr9rH61Ng",
        #   key_md_5: "Base64EncodedString",
        #   initialization_vector: "ZeroTo255String",
        # },
      },
    ],
  }
  })

end

How do i specify just any file that is uploaded, or files that are a specific format? for the input: key: ?

Now, my issue is that i am using active storage so it doesn't end in .jpg or .mov, etc., it just is a random generated string (they have reasons for doing this). I am trying to find a reason to use active storage and this is my final step to making it work like other alternatives before it.

Scott Hutchinson
  • 1,703
  • 12
  • 22
uno
  • 1,421
  • 12
  • 38

1 Answers1

0

The extension field is Optional. If you don't specify anything in it, the lambda will be triggered no matter what file is uploaded. You can then check if it's the type of file you want and proceed.

Ninad Gaikwad
  • 4,272
  • 2
  • 13
  • 23
  • It requires an input, which i need to specify the file (where input key is). Is there a way to not specify a file, and just specify a file ending? and how? – uno Mar 13 '19 at 14:11
  • When lambda is triggered by file upload event, it sends the details of the file to the lambda as parameters. You can get the key from there – Ninad Gaikwad Mar 13 '19 at 14:43
  • But how? I don't see any way in the docs to define the file that is triggering the lambda – uno Mar 13 '19 at 14:44
  • I tried using `lambda_handler` but that didn't do it – uno Mar 13 '19 at 14:46
  • I use python and am not really familiar with Ruby. I did find a similar solution that someone had posted though. https://dev.to/maartenvanvliet/using-serverless-ruby-on-aws-lambda-to-resize-images-m93 – Ninad Gaikwad Mar 13 '19 at 14:54