impl#

Runtime refers to the specific computational environment in which your code is executed. For example, running code on a local laptop, CI/CD build environments, AWS EC2 instances, AWS Lambda functions, and more. Understanding the current runtime is essential as it can impact how your code behaves.

For instance, when running your code on a local laptop, you might want to use an AWS CLI named profile to access DevOps or workload AWS accounts. However, in an application runtime like AWS Lambda, the default Boto session is typically preconfigured for the current workload AWS account.

This Python module is designed to detect the current runtime information and offers a set of is_xyz methods to assist you in crafting conditional logic for performing different actions based on the runtime. Notably, many of these methods employ the LAZY LOAD technique for efficiency.

While this module is an integral part of the https://github.com/MacHu-GWU/aws_ops_alpha-project repository, it is also available for standalone use.

Requirements: Python>=3.8

Dependencies:

cached-property>=1.5.2; python_version < '3.8'
class aws_ops_alpha.runtime.impl.RunTimeGroupEnum(value)[source]#

Enumeration of common runtime groups in AWS projects.

class aws_ops_alpha.runtime.impl.RunTimeEnum(value)[source]#

Enumeration of common runtime in AWS projects.

class aws_ops_alpha.runtime.impl.Runtime[source]#

Detect the current runtime information by inspecting environment variables.

The instance of this class is the entry point of all kinds of runtime related variables, methods.

You can extend this class to add more runtime detection logic.

property is_aws_codebuild: bool#

Reference:

property is_github_action: bool#

Reference:

property is_gitlab_ci: bool#

Reference:

property is_bitbucket_pipeline: bool#

Reference:

property is_circleci: bool#

Reference:

property is_jenkins: bool#

Reference:

property is_aws_lambda: bool#

Reference:

property is_aws_batch: bool#

Reference:

property is_aws_cloud9: bool#

We use “C9” environment variable to detect AWS Cloud9 runtime. Note that this method may not be stable. But you could add the export C9=true to the ~/.bashrc or ~/.bash_profile.

Reference:

property is_aws_ec2: bool#

There’s no official way to detect if it is ec2 instance, you could set a custom environment variable for all your ec2 instances

property is_aws_ecs: bool#

There’s no official way to detect if it is ecs task container, you could set a custom environment variable for all your ECS task.

Reference:

property is_glue_container: bool#

There’s no official way to detect if it is in a glue container.

property is_local: bool#

If it is not a CI or app runtimes, it is local.

property current_runtime: str#

Return the human friendly name of the current runtime.

property is_local_runtime_group: bool#

Where developer has access to the local file system and operating system.

property is_ci_runtime_group: bool#

Where CI/CD automation code runs.

property is_app_runtime_group: bool#

Where application code runs.

property current_runtime_group: str#

Return the human friendly name of the current runtime group.