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.
- class which_runtime.impl.RunTimeGroupEnum(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]¶
Enumeration of common runtime groups in AWS projects.
- class which_runtime.impl.RunTimeEnum(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]¶
Enumeration of common runtime in AWS projects.
- class which_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¶
AWS CodeBuild is a fully managed continuous integration service that compiles source code, runs tests, and produces software packages ready for deployment. It eliminates the need to provision, manage, and scale your own build servers.
Detection is primarily based on the presence of the
CODEBUILD_BUILD_IDenvironment variable, which is automatically set in the AWS CodeBuild build environment.Reference:
- property is_github_action: bool¶
GitHub Actions is a continuous integration and continuous delivery (CI/CD) platform that allows you to automate your build, test, and deployment pipeline. It enables developers to create workflows that build and test every pull request to your repository.
Detection relies on the presence of the
GITHUB_ACTIONenvironment variable, which is automatically set in GitHub Actions runner environments.Reference:
- property is_bitbucket_pipeline: bool¶
Bitbucket Pipelines is a continuous integration and continuous delivery (CI/CD) service built into Bitbucket Cloud. It allows developers to automatically build, test, and deploy their code based on a configuration file in their repository.
Detection relies on the presence of the
BITBUCKET_BUILD_NUMBERenvironment variable, which is automatically set in Bitbucket Pipeline environments.Reference:
- property is_circleci: bool¶
CircleCI is a cloud-based continuous integration and continuous delivery (CI/CD) platform that automates the software development process, from code building to testing and deployment.
Detection is based on the presence of the
CIRCLECIenvironment variable, which is automatically set in CircleCI runner environments.Reference:
- property is_jenkins: bool¶
Jenkins is an open-source automation server that supports building, deploying, and automating any software development project through continuous integration and continuous delivery (CI/CD).
Detection relies on the presence of both
BUILD_TAGandEXECUTOR_NUMBERenvironment variables, which are typically set in Jenkins build environments.Reference:
- property is_aws_lambda: bool¶
AWS Lambda is a serverless compute service that lets you run code without provisioning or managing servers. It supports various programming languages and automatically scales your application by running code in response to each trigger.
Detection is based on the presence of the
AWS_LAMBDA_FUNCTION_NAMEenvironment variable, which is automatically set in AWS Lambda function execution environments.Reference:
- property is_aws_batch: bool¶
AWS Batch is a fully managed batch computing service that enables developers to easily and efficiently run hundreds of thousands of batch computing jobs on AWS. It dynamically provisions optimal quantity and type of compute resources based on job requirements.
Detection relies on the presence of the
AWS_BATCH_JOB_IDenvironment variable, which is automatically set in AWS Batch job environments.Reference:
- property is_aws_glue: bool¶
AWS Glue is a fully managed extract, transform, and load (ETL) service that makes it easy to prepare and load data for analytics. It automatically provisions and manages the resources required for data transformation and movement.
Detection is based on the presence of the
--JOB_RUN_IDargument in system arguments, which is typically used in AWS Glue job environments.
- property is_aws_cloud9: bool¶
AWS Cloud9 is a cloud-based integrated development environment (IDE) that lets you write, run, and debug code with just a web browser. It provides a complete development environment in the cloud, including a code editor, debugger, and terminal.
Detection relies on the presence of the
C9environment variable, which can be manually set in Cloud9 environments. Note that this method may not be stable. You can add theexport C9=trueto the~/.bashrcor~/.bash_profileto make it stable.Reference:
- property is_aws_ec2: bool¶
Amazon EC2 (Elastic Compute Cloud) provides scalable computing capacity in the AWS cloud. It allows users to run virtual servers, known as instances, with various configurations and operating systems.
Detection is based on a custom
IS_AWS_EC2environment variable, as there’s no standard built-in way to detect EC2 instances. You should set a custom environment variable for your ec2 instances to make it stable.
- property is_aws_ecs: bool¶
Amazon ECS (Elastic Container Service) is a fully managed container orchestration service that helps you easily deploy, manage, and scale containerized applications using Docker containers.
Detection relies on a custom
IS_AWS_ECS_TASKenvironment variable, as there’s no standard built-in way to detect ECS task containers. You could set a custom environment variable for your ECS task to make it stable.Reference:
- property is_glue_container: bool¶
Glue container runtime refers to the specific environment used for running AWS Glue ETL jobs in a containerized setting. This provides additional flexibility in job execution and resource management.
Detection is based on a custom
IS_GLUE_CONTAINERenvironment variable set to ‘true’, as there’s no standard built-in way to detect Glue containers. You could set a custom environment variable for your Glue container to make it stable.
- property is_local: bool¶
Local runtime represents a standard development environment on a personal computer or local workstation. It is the default runtime when no specific cloud or CI/CD environment is detected.
Detection occurs by checking if none of the other specific runtime environments are active. Users can also manually set the runtime using the USER_RUNTIME_NAME environment variable to explicitly indicate a local runtime.
- property is_local_runtime_group: bool¶
Local runtime group encompasses development environments where a developer has direct access to the local file system and operating system. This includes standard local machines and cloud-based development environments like AWS Cloud9.
Detection is based on checking if the current runtime is either a local machine or an AWS Cloud9 environment.
- property is_ci_runtime_group: bool¶
CI (Continuous Integration) runtime group includes various automated build and testing environments used in software development workflows. These are platforms that automatically build, test, and validate code changes.
Detection checks for the presence of any CI platform environment variables (CodeBuild, GitHub Actions, GitLab CI, etc.) or a generic ‘CI’ environment variable.
- property is_app_runtime_group: bool¶
Application runtime group includes cloud-based execution environments where application code is deployed and run. This covers various serverless and container-based platforms for running production applications.
Detection checks if the current runtime is any of the supported application platforms like AWS Lambda, Batch, Glue, EC2, ECS, or Cloud9.