EC2 Tag conditionals
This is a python library and shell command that answers the question:
"Is this instance tagged with the given tag and have a given value"
It is designed to be run on AWS's EC2 instances.
It will always fail if it's not on AWS, so tags should only be tested for truthiness, not falseness.
As a Library
from ec2_tag_conditional import InstanceTags
tags = InstanceTags()
if tags['Env'] == 'prod':
do_prod_thing()
else:
do_other_thing()
As a command line script
> instance-tags "Env=prod"
> echo $?
0
> instance-tags "Madeup=NotThere"
> echo $?
1
> instance-tags "Env=prod" && do_prod_thing
Example use cases
This code was written with the following use case in mind:
You have n servers in a auto scaling group, launched from a custom
AMI (golden image). The nature of the application running on the
servers is that, for some functions to work (backup, reporting),
a given set of tasks should only be run by one server.
This server is called a 'controller'. The script that created the ASG
also tags (in the AWS metadata) one (and only one) of the servers
with controller=True.
When the AMI is baked, the images don't need to know if they are a controller or not, as cron tasks can be written like:
instance-tags "controller=True" && do_controller_only
Or for controllers in production (rather than dev or staging environments):
instance-tags "controller=True" && instance-tags "Env=prod" && do_controller_only
Because the exit code of the instance-tags script is 1 if the tag
with the given value isn't found on the instance, the script wont
run on any server that isn't an EC2 instance with the given values.
Metadata
Release files for ec2_tag_conditional 0.1.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| ec2_tag_conditional-0.1.2-py3-none-any.whl | Python 3 | none | any | Details for ec2_tag_conditional-0.1.2-py3-none-any.whl |
Release files / ec2_tag_conditional-0.1.2-py3-none-any.whl
| Download URL | ec2_tag_conditional-0.1.2-py3-none-any.whl |
|---|---|
| Size | 3.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
d3f9c273a7f5c8af05a7dfec3e4c8b4a18435390dbd309c8934096a2bef57ded
|
|
BLAKE2b-256 checksum How to use checksums |
6eb7416d97784625acbb64b7d9855fbcf25b13299138c51c265b2eedb2ed9409
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.0.0 requests-toolbelt/0.8.0 tqdm/4.24.0 CPython/3.6.4
|
Security for ec2_tag_conditional 0.1.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.