I am relatively new to AWS and Lambdas. I have deployed a lambda and its API gateway. This Lambda is using the aws-sdk to describe EC2 instances. I would like to know if it's possible to use aws-sdk within the Lambda to release the IP Address from a given EC2 Instance Id. I can see in the aws-sdk documentation other methods to in example create an EC2 instance, create tags on the instance or reboot, start, stop the EC2 instance but so far in the aws-sdk documentation I don't find a method that I can use to release the IP Address from the EC2 instance. The only option I have found is in this SO question Call aws-cli from AWS Lambda that is for calling aws-cli commands within the Lambda but that seems it will require a complicated and cumbersome deployment and packaging process. Any help will be greatly appreciated.
Asked
Active
Viewed 410 times
1

John Rotenstein
- 241,921
- 22
- 380
- 470

alejob2k
- 53
- 8
-
There are SDKs for various languages supported by Lambda For implementation using python SDK (boto3), refer https://stackoverflow.com/questions/57597389/need-to-release-all-those-elastic-ip-that-are-unassociated-using-boto3-in-all-re – omuthu Nov 06 '20 at 07:11
-
As an update I have found aws-sdk also has a method to disassociate the Elastic IP from the instance: [aws-sdk reference disassociateAddress](https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/EC2.html#disassociateAddress-property) therefore it can be done using Python/Boto3 or also using NodeJS – alejob2k Nov 09 '20 at 22:03
1 Answers
2
The API call to disassociate elastic IP address from an instance is (in boto3):
- disassociate_address - Disassociates an Elastic IP address from the instance or network interface it's associated with.
Once disassociated, you can then release_address to the AWS pool as to not pay for it, if you want.

Marcin
- 215,873
- 14
- 235
- 294