Skip to main content
Version: cicd.4.0 print this page

Driver File

The driver file is the entry point for executing the Amorphic CICD Utils module. This file is executed inside the pipeline. Below is the minimal structure required for the driver file:

import os
from amorphiccicdutils import ResourceManager

# Use either a PAT or a service user token.
AMORPHIC_AUTH_TOKEN = os.getenv('AMORPHIC_AUTHORIZATION_TOKEN')
AMORPHIC_BASE_URL = os.getenv('AMORPHIC_BASE_URL')
AMORPHIC_ROLE_ID = os.getenv('AMORPHIC_ROLE_ID')

rm = ResourceManager(
"./resources",
amorphic_auth_token=AMORPHIC_AUTH_TOKEN,
amorphic_base_url=AMORPHIC_BASE_URL,
amorphic_role_id=AMORPHIC_ROLE_ID,
validate_resource_properties=True,
)

rm.plan()
rm.execute()

The driver file must be named cicd.py and this name must not be changed.

The file can be customized to accommodate advanced use cases. For example, if users need to retrieve values from the Amorphic Parameter Store, the driver file can be extended as follows:

import os
import requests
from amorphiccicdutils import ResourceManager

# Use either a PAT or a service user token.
AMORPHIC_AUTH_TOKEN = os.getenv('AMORPHIC_AUTHORIZATION_TOKEN')
AMORPHIC_BASE_URL = os.getenv('AMORPHIC_BASE_URL')
AMORPHIC_ROLE_ID = os.getenv('AMORPHIC_ROLE_ID')


def get_parameter_from_amorphic(parameter_name):
"""
Retrieve a parameter from the Amorphic Parameter Store.
"""
response = requests.get(
f"{AMORPHIC_BASE_URL}/parameters/{parameter_name}",
headers={
"Content-Type": "application/json",
"Authorization": AMORPHIC_AUTH_TOKEN,
"role_id": AMORPHIC_ROLE_ID
},
timeout=10,
)
return response.json()["ParameterValue"]


# Example: retrieving connection credentials from Amorphic Parameter Store
os.environ["CONN_USERNAME"] = get_parameter_from_amorphic("CONN_USERNAME")
os.environ["CONN_PASSWORD"] = get_parameter_from_amorphic("CONN_PASSWORD")

rm = ResourceManager(
"./resources",
amorphic_auth_token=AMORPHIC_AUTH_TOKEN,
amorphic_base_url=AMORPHIC_BASE_URL,
amorphic_role_id=AMORPHIC_ROLE_ID,
validate_resource_properties=True,
)

rm.plan()
rm.execute()

Configuration Options

The first argument to the ResourceManager class specifies the root directory containing all resource definition JSON files. If you are following the recommended project structure, this value should be set to ./resources. If your resources are organized under a different folder, update this path accordingly.

Authentication requires three attributes:

amorphic_auth_token: Authentication token provided as an environment variable. This can be either a Personal Access Token (PAT) or a service user token.

amorphic_base_url: Base API endpoint for Amorphic, provided as an environment variable.

amorphic_role_id: Role identifier for authorization, provided as an environment variable.

If you are running within the Amorphic Infrastructure, these values are automatically available as environment variables and can be used directly.

Additional options include:

validate_resource_properties: Boolean flag (default: True). Enables schema validation for resource property definitions. Set to False to skip validation.

Logging configuration:

A default.conf file must be created at the root of your repository, in the same location as cicd.py. The pipeline sources this file before running cicd.py, exporting the values as environment variables that the logging utility picks up automatically. Create the file with the following content (recommended defaults; you can configure these values based on your logging needs):

LOG_LEVEL=2
LOG_FILE="true"
CICD_STATE_LOGS="false"

LOG_LEVEL controls pipeline log verbosity. Each level is cumulative — a higher level includes everything emitted by the levels below it:

LevelOutput
1High-level progress and outcomes (for example: loading resources, execution plan table, action start, action completion, deployment completion).
2Per-resource processing details (for example: file-by-file loading, schema validation steps, per-resource success logs, connection/source-path details).
3Verbose payload-level diagnostics (for example: full resource definitions, dependency details, and resource property dumps).

LOG_FILE supported values:

  • "true": Creates and uploads amorphic_cicd.log to {BRANCH_NAME}/logs/{CODEBUILD_BUILD_NUMBER}/amorphic_cicd.log
  • "false": Console logging only

CICD_STATE_LOGS supported values:

  • "true": Prints stateFile.json in CodeBuild logs
  • "false": Does not print stateFile.json in CodeBuild logs
note

If default.conf is not present or LOG_LEVEL / LOG_FILE are not defined in it, the pipeline falls back to the package defaults: LOG_LEVEL=1 (high-level progress only) and LOG_FILE=false (console output only, no log file uploaded to S3).

The CICD utils module reads these as environment variables. The Amorphic CICD infrastructure handles this automatically — the pipeline sources default.conf and exports every variable in it before executing cicd.py. When running locally, you must export these variables manually before running cicd.py.

Execution Phases

The CICD Utils module executes in two phases.

Planning Phase

  • Parses the resource definitions.
  • Validates schema requirements.
  • Creates an execution plan that determines the correct order of resource creation.

Execution Phase

  • Executes the plan generated in the planning phase.
  • Creates resources in Amorphic.

Running only the planning phase does not create resources. The execution phase must always follow the planning phase.