How to target all existing resources with a tag based filter

You want to select all existing resources at once with a tag based filter, for example to stop all EC2 instances nightly with the Amazon EC2 Instance task.

Step-by-step guide

You need to specify an appropriate tag based resource filter in JSON format (insert fragments from the inline Examples dialog to get started):

  1. Add an Amazon EC2 Instance task and select the Stop Instance(s) action.

  2. Select the desired AWS region and AWS security credentials as usual.

  3. Click on the Examples button and select the Tag (key only) example filter declaration.

  4. Replace the "Environment" sample filter value for the filter "tag-key" with "Name" so that the resulting filter declaration looks as follows:

    1 2 3 4 5 6 [ { "Name": "tag-key", "Values": ["Name"] } ]

    Alternatively, you can select the Tag (key and value) example filter declaration with a filter "tag:Name" and a wildcard value "*" as follows:

    1 2 3 4 5 6 [ { "Name": "tag:Name", "Values": ["*"] } ]
  5. Save the task.

  6. Due to "Name" being a default tag available for every resource, when you run the task, it will target all EC2 instances in this region, no matter what their actual name is.

Prevent failing builds in regions without resources

You can also check Don't fail for empty filter result to prevent the task failing if no matching resources are found.

[  {    "Name": "tag:Name",    "Values": ["*"]  }]