I am trying to figure out what is the best way to get a list of ec2 instances with a certain tag for example "testing" using the ruby aws sdk.
ec2 = AWS::EC2.new(:access_key_id => "XXXXXXXXXXXXX", :secret_access_key => "YYYYYYYYY")
ec2list = ec2.instances.filter("Name", "testing)
This does not seem to work for some reason. It was thinking it will filter out the collection and just give me instances with tag testing. Is there a way to do this using the ruby sdk? thank you.
To get started, you can enable tags on instance metadata at launch in the console or CLI and you can save this launch setting in a launch template. You can also use the CLI to enable tags on instance metadata on a running instance or on a stopped instance.
To find resources to tagSign in to the AWS Management Console , choose Resource Groups, and then choose Tag Editor. (optional) Choose regions in which to search for resources to tag. By default, your current region is selected.
If you're using the Amazon EC2 API, the AWS CLI, or an AWS SDK, you can use the CreateTags EC2 API action to apply tags to existing resources. Additionally, some resource-creating actions enable you to specify tags for a resource when the resource is created.
Q: Does AWS CloudFormation support Amazon EC2 tagging? Yes. Amazon EC2 resources that support the tagging feature can also be tagged in an AWS template.
If you want the tag "Name" with the value of "testing" use:
instances = resource.instances(
filters: [
{
name: 'tag:Name',
values: ["testing"]
}
]
)
For all instances with a tag key of "testing" the following is used.
instances = resource.instances(
filters: [
{
name: 'tag:Key',
values: ["testing"]
}
]
)
See the #instances docs for more filter options.
This worked for me:
ec2.instances.tagged("testing")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With