question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to get resources with a value inside any keys

See original GitHub issue

Hi! I’m trying to write a policy that finds aws vpn connection tunnels that have no tunnels up. When searching for tunnels without any filters the resources.json look like this:

[
  {
    (lots of stuff here)
    "VgwTelemetry": [
      {
        "AcceptedRouteCount": 3,
        "LastStatusChange": "2020-06-24T04:33:19+00:00",
        "OutsideIpAddress": "1.1.1.1",
        "Status": "UP",
        "StatusMessage": ""
      },
      {
        "AcceptedRouteCount": 3,
        "LastStatusChange": "2020-06-07T19:41:11+00:00",
        "OutsideIpAddress": "1.1.1.2",
        "Status": "DOWN",
        "StatusMessage": ""
      }
    ]
  }
]

Basically what I’m trying to do is filter resources that have no "Status": "UP" keys in them. I tried to do something like this:

- name: aws-vpnconnection-alltunnelsaredown-find
    description: |
      Find connections with no tunnels up
    resource: aws.vpn-connection
    filters:
      - not:
        - VgwTelemetry.[*].Status: UP

But this doesn’t seem to work. What is the proper way to do this?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
kapiltcommented, Jul 1, 2020

so because the value comes back as an array from expression, comparing to a singleton policy value won’t match for equality, you’ll need to use the long form of the value filter.

- name: aws-vpnconnection-tunnelisdown-find
    resource: aws.vpn-connection
    description: |
      Find connections with no tunnels up
    filters:
      - type: value
         key: VgwTelemetry[].Status
         op: contains
         value: DOWN
1reaction
kapiltcommented, Jun 30, 2020

its useful to try out jmespath-terminal package for exploring this locally with the cli

VgwTelemetry[].Status: DOWN

Read more comments on GitHub >

github_iconTop Results From Across the Web

c# - How to get a value from resource file using its key
There is a much easier way: Namespace.Properties.Resources.FileName -> gets the string of the file ...
Read more >
How to Get All Keys in Redis | Tutorial by Chartio
This is best shown through the redis-cli (command line interface) using GET and SET commands. For example, we may want to store some...
Read more >
Object.keys() - JavaScript - MDN Web Docs
The Object.keys() method returns an array of a given object's own enumerable string-keyed property names.
Read more >
JavaScript: Obtain key-value pairs in an array - Flexiple
Method 1: Using an object to store key => value pairs ; // create object var obj = {}; ; // Loop to...
Read more >
Creating a condition with multiple keys or values
Unless otherwise specified, all keys can have multiple values. ... For example, you can tag resources in AWS and include multiple tag key-value...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found