AWS Lifecycle Scripts
Lifecycle scripts are Python files strata runs before or after deploy stages. The
AWSScript base class gives scripts pre-wired access to the AWS CLI — no setup
required.
Quick start — use a built-in script
Reference built-in scripts directly from workspace YAML lifecycle hooks:
lifecycle:
pre_deploy:
scripts:
# Fetch EKS credentials so Helm / ArgoCD can reach the cluster
- strata://aws_eks_credentials.py
# Log Docker into Amazon ECR before image push
- strata://aws_ecr_login.py
pre_provision:
scripts:
# Ensure S3 bucket exists (idempotent — safe to run every time)
- strata://aws_s3_bucket_ensure.py
Tip: Copy any built-in script to
.strata/scripts/to customise it.
Built-in scripts
aws_eks_credentials.py
Runs aws eks update-kubeconfig to merge cluster credentials into the local
kubeconfig. Use before Helm, ArgoCD, or Flux stages targeting Amazon EKS.
Required variables:
Variable |
Description |
|---|---|
|
EKS cluster name |
|
AWS region |
Optional variables:
Variable |
Default |
Description |
|---|---|---|
|
— |
IAM role ARN to assume for kubeconfig auth |
|
— |
Override kubeconfig context name |
|
— |
Set default namespace in kubeconfig context |
variables:
- key: EKS_CLUSTER
source: constant
value: my-eks-cluster
- key: AWS_DEFAULT_REGION
source: constant
value: us-east-1
aws_ecr_login.py
Runs aws ecr get-login-password | docker login so Docker push/pull commands work
against Amazon Elastic Container Registry in the same stage.
Required — one of:
ECR_REGISTRY— full registry URL (e.g.123456789012.dkr.ecr.us-east-1.amazonaws.com)ECR_ACCOUNT_ID+AWS_DEFAULT_REGION— registry URL is constructed automatically
Optional:
Variable |
Description |
|---|---|
|
Account ID (auto-resolved via STS if absent and |
variables:
- key: ECR_REGISTRY
source: constant
value: 123456789012.dkr.ecr.us-east-1.amazonaws.com
aws_s3_bucket_ensure.py
Runs aws s3api create-bucket — idempotent: if the bucket already exists and is
owned by the same account the command succeeds without changes. Use before a Terraform
deploy that needs the remote state bucket to exist.
Required variables:
Variable |
Description |
|---|---|
|
S3 bucket name |
|
AWS region |
Optional variables:
Variable |
Default |
Description |
|---|---|---|
|
|
Set to |
|
|
Set to |
|
|
Public access block (recommended; set |
|
— |
Comma-separated |
variables:
- key: S3_BUCKET
source: constant
value: my-terraform-state
- key: S3_VERSIONING
source: constant
value: "true"
- key: S3_ENCRYPTION
source: constant
value: "true"
Write a custom script
Subclass AWSScript in .strata/scripts/:
# .strata/scripts/pre_deploy_custom.py
from strata.utils.aws_script_base import AWSScript
class MyPreDeploy(AWSScript):
def run(self):
bucket = self.require_env("S3_BUCKET") # exits with error if absent
region = self.region() # resolves from env/profile or exits
result = self.run_aws(["s3api", "head-bucket", "--bucket", bucket,
"--region", region])
self.exit_on_failure(result, "aws s3api head-bucket")
self.log(f"Bucket '{bucket}' confirmed in '{region}'")
if __name__ == "__main__":
MyPreDeploy().execute()
Reference it in workspace YAML:
lifecycle:
pre_deploy:
scripts:
- .strata/scripts/pre_deploy_custom.py
AWSScript reference
Method |
Description |
|---|---|
|
Run |
|
|
|
Return env var value or |
|
Return env var value with optional default |
|
|
|
AWS account ID from |
|
|
|
|
|
Stage name from |
|
Print to stderr — visible in strata console output |
Environment variables in all lifecycle scripts
strata injects these before running any script:
Variable |
Content |
|---|---|
|
Current lifecycle phase (e.g. |
|
Workspace root path |
|
Build artifacts directory |
|
|
|
Current stage name |
all resolved variables |
Secrets and variables from the active deployment |