https://github.com/djnicholson/ec2-rotate-ip
Script to automatically rotate an Elastic IP from within an EC2 instance
https://github.com/djnicholson/ec2-rotate-ip
Last synced: 3 months ago
JSON representation
Script to automatically rotate an Elastic IP from within an EC2 instance
- Host: GitHub
- URL: https://github.com/djnicholson/ec2-rotate-ip
- Owner: djnicholson
- License: gpl-3.0
- Created: 2020-11-30T02:48:16.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2020-11-30T03:44:22.000Z (almost 5 years ago)
- Last Synced: 2025-07-18T12:13:34.595Z (4 months ago)
- Language: TypeScript
- Size: 21.5 KB
- Stars: 5
- Watchers: 1
- Forks: 2
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# ec2-rotate-ip
A script that can be run periodically to change the public-facing IP on one or more EC2 instances in a region.
## Pre-requisites
Ensure the following pre-requisites before running the script.
### Instances
For any instance that should have its public IP rotated:
1. Associate an Elastic IP with that instance.
2. Create a tag on the Elastic IP:
- **rotate=1** _(key="rotate", value="1")_
### Environment
You will need Node.js installed and your environment configured with credentials to use the AWS Node.js SDK.
#### Required AWS permissions:
- `ec2:ReleaseAddress`
- `ec2:DescribeAddresses`
- `ec2:CreateTags`
- `ec2:AssociateAddress`
- `ec2:AllocateAddress`
#### Example IAM policy:
```
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "VisualEditor0",
"Effect": "Allow",
"Action": [
"ec2:ReleaseAddress",
"ec2:DescribeAddresses",
"ec2:CreateTags",
"ec2:AssociateAddress",
"ec2:AllocateAddress"
],
"Resource": "*"
}
]
}
```
#### Environment configuration instructions:
https://docs.aws.amazon.com/sdk-for-javascript/v2/developer-guide/setting-credentials-node.html
## Instructions
Run the following command whenever you want to rotate IPs:
```
AWS_REGION=us-east-1 npx ec2-rotate-ip
```