# CloudWatch input plugin not working with EC2 namespace

**URL:** <https://discuss.elastic.co/t/cloudwatch-input-plugin-not-working-with-ec2-namespace/329026>\
**Category:** Logstash\
**Created:** [March 31, 2023, 8:19am UTC](https://discuss.elastic.co/t/cloudwatch-input-plugin-not-working-with-ec2-namespace/329026 "2023-03-31T08:19:16Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![kanny](https://avatars.discourse-cdn.com/v4/letter/k/dec6dc/32.png) [@kanny](https://discuss.elastic.co/u/kanny)\
**Post date:** [March 31, 2023, 8:19am UTC](https://discuss.elastic.co/t/cloudwatch-input-plugin-not-working-with-ec2-namespace/329026/1 "2023-03-31T08:19:16Z")

</div>

Hello,

When I ran Logstash 8.6.2 version to collect EC2 CloudWatch metrics, the process returned "Exception: NameError".  
As far as I know by testing, this exception happends only for AWS/EC2 namespace, and setting for other namespace such as AWS/RDS works.  
Logstash 7.17.9 worked with the same config file.

My issue seems the same as this post, but it was already closed without any comments.

> [@Problems with cloudwatch input plugin - namespace AWS/EC2 NameError](https://discuss.elastic.co/t/problems-with-cloudwatch-input-plugin-namespace-aws-ec2-nameerror/326297):
>
> Hello All, problem summary: logstash can't recognize 'AWS/EC2' I am setting up a logstash configuration file to get cloudwatch(EC2, RDS) data. I have written input plugin code as below, and RDS is working as I expected. However, EC2 part isn't working with error. I have no idea why NameError occurs only on EC2, even though it works fine on RDS. It seems that transpiled code 'Aws::EC2' is not recognized by jruby. How can I fix this error? any suggestions would be grateful. thanks for you…

Any suggestions would be greatly appreciated.

Input configuration:

```auto
input {
  cloudwatch {
    namespace => "AWS/EC2"
    metrics => ["CPUUtilization"]
    filters => { "tag:AutoStop"=> "false"}
    region => "ap-northeast-1"
  }
}

```

Error message:

```auto
[2023-03-30T12:29:19,453][ERROR][logstash.javapipeline][main][8624b06bdbedde7950dc9a8f04c94d2da6a631699d3e08a2ee9034935b12428b] A plugin had an unrecoverable error. Will restart this plugin.
  Pipeline_id:main
  Plugin: <LogStash::Inputs::CloudWatch namespace=>"AWS/EC2", metrics=>["CPUUtilization"], id=>"8624b06bdbedde7950dc9a8f04c94d2da6a631699d3e08a2ee9034935b12428b", region=>"ap-northeast-1", enable_metric=>true, codec=><LogStash::Codecs::Plain id=>"plain_177ff1f1-f27e-4aa3-95a5-ec3036638fa2", enable_metric=>true, charset=>"UTF-8">, role_session_name=>"logstash", statistics=>["SampleCount", "Average", "Minimum", "Maximum", "Sum"], interval=>900, period=>300, combined=>false>
  Error: uninitialized constant Aws::EC2
  Exception: NameError
  Stack: org/jruby/RubyModule.java:3963:in `const_missing'
org/jruby/RubyModule.java:3905:in `const_get'
/usr/share/logstash/vendor/bundle/jruby/2.6.0/gems/logstash-integration-aws-7.0.1/lib/logstash/inputs/cloudwatch.rb:247:in `block in clients'
org/jruby/RubyHash.java:794:in `default'
org/jruby/RubyHash.java:1265:in `[]'
/usr/share/logstash/vendor/bundle/jruby/2.6.0/gems/logstash-integration-aws-7.0.1/lib/logstash/inputs/cloudwatch.rb:316:in `resources'
/usr/share/logstash/vendor/bundle/jruby/2.6.0/gems/logstash-integration-aws-7.0.1/lib/logstash/inputs/cloudwatch.rb:179:in `from_resources'
/usr/share/logstash/vendor/bundle/jruby/2.6.0/gems/logstash-integration-aws-7.0.1/lib/logstash/inputs/cloudwatch.rb:160:in `block in run'
org/jruby/RubyArray.java:1865:in `each'
/usr/share/logstash/vendor/bundle/jruby/2.6.0/gems/logstash-integration-aws-7.0.1/lib/logstash/inputs/cloudwatch.rb:157:in `run'
/usr/share/logstash/logstash-core/lib/logstash/java_pipeline.rb:411:in `inputworker'
/usr/share/logstash/logstash-core/lib/logstash/java_pipeline.rb:402:in `block in start_input'

```

Thank you.

---

<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:** [April 28, 2023, 8:20am UTC](https://discuss.elastic.co/t/cloudwatch-input-plugin-not-working-with-ec2-namespace/329026/2 "2023-04-28T08:20:15Z")

</div>

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