c0ntax/aws-ec2-check-tag
最新稳定版本:1.1.1
Composer 安装命令:
composer require c0ntax/aws-ec2-check-tag
包简介
A very simple service that pulls the tags for a given instance to see if a particular key = a particular value.
关键字:
README 文档
README
A very simple library that checks that, for the EC2 instance that this is run on, does a key === a certain value.
Introduction
This was built to scratch a particular itch where I only wanted cron commands and other services to run on one of a set of EC2 instances. This way you can deploy one AMI for a set of load balanced machines and simply tag one of them that you want to execute something on. For example, say we have 3 instances running the code base, but we only want a particular bit of code to run on one of them. Simply set a tag for that instance such as
RunHere: True
And then all you need to do so check that RunHere has been set to True
Usage
Using the above example, you could use the following code:
use C0ntax\Aws\Ec2\CheckTag\Exceptions\KeyNotFoundException; use C0ntax\Aws\Ec2\CheckTag\Exceptions\NotOnEc2InstanceException; public function doSomething() { try { if (!$this->getCheckService()->check('RunHere', 'True')) { return; } } catch (NotOnEc2InstanceException $exception) { // This is probably running on a local instance so we might want to allow this to run // (i.e. we are just going to catch and ignore the exception) } catch (KeyNotFoundException $exception) { // The 'RunHere' key was not found. It's up to you how you've implimented it. It's probably not an error in most cases // It just means that you don't want to run anything here return; } print 'I am doing something'; }
统计信息
- 总下载量: 2.16k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: Apache-2.0
- 更新时间: 2021-08-24