I am fairly new to AWS CLI. I am trying to find out the limit(quota) of elastic IP addresses for a region(e.g. us-east-1). From that limit, how many have been used and how many are remaining for my terraform script to use. I need to use this to conditionalise the further flow. Need help. Right now I have tried to use the below but it gives me wrong answer.
Available_Elastic_IPs=$(AWS_ACCESS_KEY_ID=$AWS_ACCESS_KEY_ID AWS_SECRET_ACCESS_KEY=$AWS_SECRET_ACCESS_KEY AWS_SESSION_TOKEN=$AWS_SESSION_TOKEN aws ec2 describe-addresses --query "Addresses[?NetworkInterfaceId == null ].PublicIp" --region "$REGION" --output "text" | wc -w)
This tells me where the network interface ID are null. Even if the count is 0, I can still go ahead and create EC2 instances with elastic IPs. So I think the query needs slight adjustment.
2
Answers
Thanks to @Lorenzo's answer, I was able to get through my problem. I combined all this and ran on Jenkins shell script and it worked.
Here is my EIP_Get_Quota.tf file
extracted the output with the help of below code in shell script
Then I ran the below in AWS command line (CLI)
This is a minimal working example that I used to achieve what you’re trying to :
The output I added will look something like this
Some docs that I used that may be helpful to you:
To get the quota name I followed the AWS docs instructions on the console and copy/pasted the quota_name that was shown there.