c0ntax/aws-ec2-check-tag 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

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

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: Apache-2.0
  • 更新时间: 2021-08-24