# Logstash output s3 didn't work with condition

**URL:** <https://discuss.elastic.co/t/logstash-output-s3-didnt-work-with-condition/29905>\
**Category:** Logstash\
**Created:** [September 24, 2015, 9:45am UTC](https://discuss.elastic.co/t/logstash-output-s3-didnt-work-with-condition/29905 "2015-09-24T09:45:27Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![vankhoa011](https://avatars.discourse-cdn.com/v4/letter/v/71e660/32.png) [@vankhoa011](https://discuss.elastic.co/u/vankhoa011)\
**Post date:** [September 24, 2015, 9:45am UTC](https://discuss.elastic.co/t/logstash-output-s3-didnt-work-with-condition/29905/1 "2015-09-24T09:45:27Z")

</div>

Hi all,

I make a config for logstash ,  
I want if the logs match logtype==request and env==prd , it will save to Bucket 1  
If the logstash logtype==request and env==stg , i will save to Bucket2.

However, there is something wrong. All logs saved on Bucket 1. I don't know why.  
Is there something wrong with my config. Please help me to fix that.

Regards,  
Khoa Nguyen

```
output {

  if [logtype] == "request" and [env] == "prd" {
    s3 {
        access_key_id => "XXX"
        secret_access_key => "XXX"
        bucket => "XXX1"
        endpoint_region => "us-east-1"
        time_file => 1
    }
  }
  if [logtype] == "request" and [env] == "stg" {
    s3 {
      access_key_id => "XXX"
      secret_access_key => "XXX2"
      bucket => "XXX"
      endpoint_region => "us-east-1"
      time_file => 1
    }
  }
}
```

---

<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 24, 2015, 9:55am UTC](https://discuss.elastic.co/t/logstash-output-s3-didnt-work-with-condition/29905/2 "2015-09-24T09:55:24Z")

</div>

Your configuration looks okay. Have you verified that the `logtype` and `env` fields have the values you expected, i.e. that they're not all equal to "request" and "prd"? Have you made sure that you don't have a leftover configuration file in /etc/logstash/conf.d that contains an s3 output declaration that unconditionall saves everything to bucket 1?

---

<div class="post-metadata">

**Author:** ![vankhoa011](https://avatars.discourse-cdn.com/v4/letter/v/71e660/32.png) [@vankhoa011](https://discuss.elastic.co/u/vankhoa011)\
**Post date:** [September 24, 2015, 10:05am UTC](https://discuss.elastic.co/t/logstash-output-s3-didnt-work-with-condition/29905/3 "2015-09-24T10:05:16Z")

</div>

@magnusbaeck: I checked my configure many times. The `logtype` and `env` are correct.  
I don't have any leftover configure to make all logs save on bucket 1. It's weird.

Do you have any idea to debug this issue ? Actually, the full config is following . Because I want to all log save into ES also, some logs go to S3 bucket.

```
output {
  elasticsearch {
    host => "XXX"
    protocol => "http"
    cluster => "XXX"
  }
  if [logtype] == "request" and [env] == "prd" {
    s3 {
        access_key_id => "XXX"
        secret_access_key => "XXX"
        bucket => "XXX1"
        endpoint_region => "us-east-1"
        time_file => 1
    }
  }
  if [logtype] == "request" and [env] == "stg" {
    s3 {
      access_key_id => "XXX"
      secret_access_key => "XXX2"
      bucket => "XXX"
      endpoint_region => "us-east-1"
      time_file => 1
    }
  }
}
```

---

<div class="post-metadata">

**Author:** ![vankhoa011](https://avatars.discourse-cdn.com/v4/letter/v/71e660/32.png) [@vankhoa011](https://discuss.elastic.co/u/vankhoa011)\
**Post date:** [September 25, 2015, 8:10am UTC](https://discuss.elastic.co/t/logstash-output-s3-didnt-work-with-condition/29905/4 "2015-09-25T08:10:50Z")

</div>

I changed the config output of logstash which remove send log to second bucket.

It works properly. So I think the root cause is the output of S3 plugin .  
This plugin allow only one bucket to save data.

```
output {
  elasticsearch {
    host => "XXX"
    protocol => "http"
    cluster => "XXX"
  }
  if [logtype] == "request" and [env] == "prd" {
    s3 {
        access_key_id => "XXX"
        secret_access_key => "XXX"
        bucket => "XXX1"
        endpoint_region => "us-east-1"
        time_file => 1
    }
  }
 }
```

---

<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:** [July 6, 2017, 5:28am UTC](https://discuss.elastic.co/t/logstash-output-s3-didnt-work-with-condition/29905/5 "2017-07-06T05:28:04Z")

</div>


