从aws cloudmap服务中删除终止的ec2实例
aws-cloud-unmap的Python项目详细描述
AWS云图
外部控制器,用于从aws云地图服务中删除已终止的ec2实例。
工作原理
此应用程序定期扫描注册到云地图服务的实例,并将其与在1+区域中运行的EC2实例匹配:然后,它将取消注册在服务中注册的任何与正在运行的EC2实例不匹配的实例。
必要条件:
- 实例必须在云映射服务中注册,云映射实例ID等于EC2实例ID
- 实例必须使用
AWS_INSTANCE_IPV4
属性(可以是私有或公共IP地址)在云映射服务中注册
如何进行匹配:
- 如果实例id和
AWS_INSTANCE_IPV4
地址都与正在运行的ec2实例匹配,则注册的实例被视为有效。- 如果注册时没有
AWS_INSTANCE_IPV4
属性,则跳过已注册的实例(保持未触及)。 - 如果注册时没有
安全对策:
- 应用程序会记录一个警告,并执行not取消注册不匹配的实例,以防服务在没有注册实例的情况下退出
- 应用程序处理
SIGINT
和SIGTERM
上的正常关闭。如果在和解期间收到这样的信号,它将在退出 之前完成正在进行的协调。
如何运行它
您有两个选项来运行它:
手动安装并运行^{
} Python package pip3 install aws-cloud-unmap aws-cloud-unmap --service-id srv-12345 --service-region us-east-1 --instances-region us-east-1
使用Docker image available on Docker hub
docker run --env AWS_ACCESS_KEY_ID="id" --env AWS_SECRET_ACCESS_KEY="secret" spreaker/aws-cloud-unmap --service-id srv-12345 --service-region us-east-1 --instances-region us-east-1
cli支持以下参数:
Argument | Required | Description |
---|---|---|
^{ | yes | AWS CloudMap service ID |
^{ | yes | AWS CloudMap service region |
^{ | yes | AWS regions where EC2 instances should be checked |
^{ | How frequently the service should be reconciled (in seconds). Defaults to ^{ | |
^{ | Run a single reconcile and then exit | |
^{ | Enable the Prometheus exporter. Disabled by default | |
^{ | The host at which the Prometheus exporter should listen to. Defaults to ^{ | |
^{ | The port at which the Prometheus exporter should listen to. Defaults to ^{ | |
^{ | Minimum log level. Accepted values are: ^{ |
导出指标
该应用程序的特点是集成普罗米修斯出口商。导出以下度量:
Metric name | Labels | Description |
---|---|---|
^{ | ^{ | Always ^{ |
^{ | ^{ | The timestamp (in seconds) of the last successful reconciliation |
所需的IAM权限
为了成功运行,此应用程序需要以下IAM权限:
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "DescribeEC2Instances",
"Effect": "Allow",
"Action": [ "ec2:DescribeInstances" ],
"Resource": "*"
},{
"Sid": "ListAndDeregisterServiceInstances",
"Effect": "Allow",
"Action": [
"servicediscovery:ListInstances",
"servicediscovery:DeregisterInstance",
"route53:GetHealthCheck",
"route53:DeleteHealthCheck",
"route53:UpdateHealthCheck"
],
"Resource": "*"
},{
"Sid": "UpdateDnsWhileDeregisteringServiceInstances",
"Effect": "Allow",
"Action": [ "route53:ChangeResourceRecordSets" ],
"Resource": [
"ARN-OF-YOUR-ROUTE53-HOSTEDZONE"
]
}
]
}
开发
运行开发环境:
docker-compose build dev && docker-compose run --rm dev
在开发环境中运行测试:
python3 -m unittest
许可证
此软件在MIT license下发布。