简体   繁体   中英

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 ?

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).

You can retrieve it with:

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

You could similarly access this information via boto3 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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