# How to iterate multiple S3 inputs?

**URL:** <https://discuss.elastic.co/t/how-to-iterate-multiple-s3-inputs/100424>\
**Category:** Logstash\
**Created:** [September 13, 2017, 10:16pm UTC](https://discuss.elastic.co/t/how-to-iterate-multiple-s3-inputs/100424 "2017-09-13T22:16:38Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![android.kc](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/android.kc/32/58806_2.png) [@android.kc](https://discuss.elastic.co/u/android.kc)\
**Post date:** [September 13, 2017, 10:16pm UTC](https://discuss.elastic.co/t/how-to-iterate-multiple-s3-inputs/100424/1 "2017-09-13T22:16:38Z")

</div>

I am using s3 input plugin to download/unzip .gz file and feed to Logstash. Here is the input part of my working config for Logstash

```auto
input {
  s3 {
    interval => 86400
    bucket => "us-west-1"
    aws_credentials_file => "<path_to_cred>"
    region => "us-west-1"
    sincedb_path => "<path_to_sincedb>"
    prefix => "<tenant1_id>/elasticsearch/"
    codec => multiline { 
      pattern => "^\["
      negate => true
      what => "previous"
    }
    type => "elasticsearch"
    add_field => {
     "tenantID" => "<tenant1_id>"
    }    
  }
  
  s3 {
    interval => 86400
    bucket => "us-west-1"
    aws_credentials_file => "<path_to_cred>"
    region => "us-west-1"
    sincedb_path => "<path_to_sincedb>"
    prefix => "<tenant2_id>/elasticsearch/"
    codec => multiline { 
      pattern => "^\["
      negate => true
      what => "previous"
    }
    type => "elasticsearch"
    add_field => {
     "tenantID" => "<tenant2_id>"
    }    
  }    
  }
}

```

As you can see, most fields are identical except the **prefix** and **add\_field.tenantID** , and I have about 100 tenants with different prefix but following the same pattern \<tenant#\_id\>. I'm new to logstash and ruby syntax. How do I remove the duplicated code by moving them into a function, for loop or something easy to maintain?

Thanks,  
KC

---

<div class="post-metadata">

**Author:** ![magnusbaeck](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/magnusbaeck/32/44943_2.png) [@magnusbaeck](https://discuss.elastic.co/u/magnusbaeck)\
**Post date:** [September 14, 2017, 9:36am UTC](https://discuss.elastic.co/t/how-to-iterate-multiple-s3-inputs/100424/2 "2017-09-14T09:36:03Z")

</div>

Logstash has nothing built-in to help with this. I suggest you generate your configuration file from a template, e.g. using Ansible.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [October 12, 2017, 9:36am UTC](https://discuss.elastic.co/t/how-to-iterate-multiple-s3-inputs/100424/3 "2017-10-12T09:36:09Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
