简体   繁体   English

使用boto3检查连接到ec2实例的弹性IP

[英]Check elastic IP attached to an ec2 instance using boto3

How to check if the public IP address attached to an instance is Elastic or not, using boto3 ? 如何使用boto3检查附加到实例的公共IP地址是否为Elastic?

Is there a method that i can call and get this information ? 有没有一种我可以调用并获取此信息的方法?

It appears that Network Interface association has an owner field: 似乎网络接口关联具有所有者字段:

"NetworkInterfaces": [
    {
        "Status": "in-use", 
        "MacAddress": "06:68:22:33:44:c1", 
        "SourceDestCheck": true, 
        "VpcId": "vpc-1234", 
        "Description": "", 
        "Association": {
            "PublicIp": "13.54.133.222", 
            "PublicDnsName": "ec2-13-54-133-222.ap-southeast-2.compute.amazonaws.com", 
            "IpOwnerId": "amazon"
        }, 

The IpOwnerId is either the AWS Account number (for an Elastic IP address) or amazon (for a temporary public IP address). IpOwnerId是AWS帐号(用于弹性IP地址)或amazon (用于临时公共IP地址)。

You can retrieve it with: 您可以使用以下方法检索它:

aws ec2 describe-instances --query 'Reservations[*].Instances[*].NetworkInterfaces[*].Association.[PublicIp,IpOwnerId]'

You could similarly access this information via boto3 . 您可以类似地通过boto3访问此信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM