LoginSignup
0
0

More than 3 years have passed since last update.

【boto3】EC2インスタンスをタグでフィルタリング

Posted at

boto3のresourceでEC2をNameタグでフィルタリングしたい場合、
tag:(タグキー)という形式で指定する。

Nameタグがweb-server01のインスタンスは下記のように取得。


ec2_r = boto3.resource('ec2')
inst_resources = ec2_r.instances.filter(
        Filters=[
            {'Name': 'tag:Name', 'Values': 'web-server01' }
        ])

Systemタグがwebの場合は下記のように。

inst_resources = ec2_r.instances.filter(
        Filters=[
            {'Name': 'tag:System', 'Values': 'web' }
        ])
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0