Skip to content

CodePipelineConfig

Bases: BaseModel, AwsTypesValidationMixin

Configuration model for AWS CodePipeline creation and management.

Defines the complete structure and validation rules for creating CodePipeline workflows with different usage patterns (BUILD_RELEASE, BUILD_DEPLOY, DEPLOY), git integration, artifact management, and comprehensive stage validation.

Attributes:

Name Type Description
usage Usage

Pipeline usage pattern determining required stages and validation

stages StagesConfig

Complete stage configuration with individual actions

restart_execution_on_update bool

Restart pipeline execution when updated

git_provider GitProvider

Git provider for source code (currently CodeCommit only)

git_repo Any

Git repository containing source code

git_branch str

Git branch to monitor for changes

is_dev_branch bool

Flag indicating development branch for different behaviors

artifact_bucket Optional[Any]

S3 bucket for storing pipeline artifacts

release_bucket Optional[Any]

S3 bucket for storing release artifacts

target_env Optional[str]

Target environment for deployment pipelines

Validation Rules
  • Usage-specific stage requirements
  • Stage-specific field requirements based on action types
  • Artifact reference validation between stages
  • CloudFormation deployment parameter validation
Source code in mare_aws_common_lib/models/codepipeline_config.py
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
class CodePipelineConfig(BaseModel, AwsTypesValidationMixin):
    """Configuration model for AWS CodePipeline creation and management.

    Defines the complete structure and validation rules for creating CodePipeline
    workflows with different usage patterns (BUILD_RELEASE, BUILD_DEPLOY, DEPLOY),
    git integration, artifact management, and comprehensive stage validation.

    Attributes:
        usage: Pipeline usage pattern determining required stages and validation
        stages: Complete stage configuration with individual actions
        restart_execution_on_update: Restart pipeline execution when updated
        git_provider: Git provider for source code (currently CodeCommit only)
        git_repo: Git repository containing source code
        git_branch: Git branch to monitor for changes
        is_dev_branch: Flag indicating development branch for different behaviors
        artifact_bucket: S3 bucket for storing pipeline artifacts
        release_bucket: S3 bucket for storing release artifacts
        target_env: Target environment for deployment pipelines

    Validation Rules:
        - Usage-specific stage requirements
        - Stage-specific field requirements based on action types
        - Artifact reference validation between stages
        - CloudFormation deployment parameter validation
    """

    model_config = ConfigDict(extra="forbid", arbitrary_types_allowed=True)

    # Core pipeline configuration
    usage: Usage = Field(..., description="Pipeline usage type (BUILD_RELEASE, BUILD_DEPLOY, DEPLOY)")
    stages: StagesConfig = Field(..., description="Configuration for pipeline stages")
    restart_execution_on_update: bool = Field(default=True, description="Whether to restart execution on update")

    # Git configuration
    git_provider: GitProvider = Field(..., description="Git provider")
    git_repo: Any = Field(..., description="Git repository")
    git_branch: str = Field(..., description="Git branch")
    is_dev_branch: bool = Field(..., description="Whether this is a development branch")

    # S3 buckets
    artifact_bucket: Optional[Any] = Field(None, description="S3 bucket for pipeline artifacts")
    release_bucket: Optional[Any] = Field(None, description="S3 bucket for releases")

    # Deployment configuration
    target_env: Optional[str] = Field(None, description="Target environment for deployment")

    class Typed:
        """Inner class, Type-safe accessor for AWS CDK resources with proper typing."""
        def __init__(self, config: 'CodePipelineConfig'):
            self._config = config

        @property
        def git_repo(self) -> 'codecommit.IRepository':
            """CodeCommit repository for source code."""
            return self._config.git_repo

        @property
        def artifact_bucket(self) -> 's3.IBucket':
            """S3 bucket for pipeline artifacts."""
            return self._config.artifact_bucket

        @property
        def release_bucket(self) -> 's3.IBucket':
            """S3 bucket for release artifacts."""
            return self._config.release_bucket


    @property
    def typed(self) -> Typed:
        """Access to type-safe AWS CDK resource properties, references the Typed inner class."""
        if not hasattr(self, '_typed'):
            self._typed = self.Typed(self)
        return self._typed


    @field_validator("git_provider", mode="after")
    @classmethod
    def validate_git_provider(cls, value):
        """Validate git provider is supported (currently CodeCommit only)."""
        if value != GitProvider.CODECOMMIT:
            raise ValueError(f"{value} is not yet supported by the CodebuildBuilder")
        return value

    @field_validator("git_repo", mode="after")
    @classmethod
    def validate_git_repo(cls, value, info: ValidationInfo):
        """Validate git repository object implements codecommit.IRepository interface."""
        return cls.validate_repository(value, "git", "codecommit.IRepository")

    @field_validator("artifact_bucket", "release_bucket", mode="after")
    @classmethod
    def validate_artifact_bucket(cls, value):
        """Validate S3 bucket objects implement s3.IBucket interface."""
        return cls.validate_bucket(value)

    @model_validator(mode="after")
    def validate_usage_requirements(self) -> 'CodePipelineConfig':
        """Validate usage-specific required fields are present.

        Returns:
            Self with validated usage requirements

        Raises:
            ValueError: If required fields for the usage type are missing
        """
        usage_requirements = {
            Usage.BUILD_RELEASE: ["artifact_bucket", "release_bucket"],
            Usage.BUILD_DEPLOY: ["artifact_bucket"],
            Usage.DEPLOY: ["artifact_bucket", "release_bucket", "target_env"]
        }

        required_fields = usage_requirements.get(self.usage, [])
        missing_fields = [field for field in required_fields if getattr(self, field, None) is None]
        if missing_fields:
            raise ValueError(f"Fields {missing_fields} are mandatory for {self.usage}")

        return self

    @model_validator(mode="after")
    def validate_stages_configuration(self) -> 'CodePipelineConfig':
        """Validate complete stage configuration for consistency and requirements.

        Returns:
            Self with validated stage configuration

        Raises:
            ValueError: If stage configuration is invalid for the usage type
            ValueError: If required stage items or fields are missing
            ValueError: If artifact references are invalid
        """
        stages_dict = self.stages.model_dump(exclude_none=True)

        # Validate usage-specific stage requirements
        self._validate_usage_stage_requirements(stages_dict)

        # Validate stage-specific restrictions
        self._validate_stage_restrictions(stages_dict)

        # Validate individual stage items
        self._validate_stage_items(stages_dict)

        return self


    def _validate_usage_stage_requirements(self, stages_dict: Dict[str, Any]):
        """Validate that required stages are present for the usage type."""
        usage_required_stages = {
            Usage.BUILD_RELEASE: {"build", "release"},
            Usage.BUILD_DEPLOY: {"build", "deploy"},
            Usage.DEPLOY: {"deploy"},
        }

        required_stages = usage_required_stages.get(self.usage, set())
        missing_stages = [stage for stage in required_stages if stage not in stages_dict]

        if missing_stages:
            raise ValueError(f"{self.usage} usage requires stage(s): {', '.join(missing_stages)}")

    def _validate_stage_restrictions(self, stages_dict: Dict[str, Any]):
        """Validate stage restrictions based on usage type."""
        # Control stage only for BUILD_RELEASE
        if self.usage != Usage.BUILD_RELEASE and "control" in stages_dict:
            raise ValueError("'control' stage can only be used for Usage.BUILD_RELEASE")

        # Manual source only for DEPLOY
        if self.usage != Usage.DEPLOY and "manual_source" in stages_dict:
            raise ValueError("'manual_source' stage can only be used for Usage.DEPLOY")

        # Manual source can only contain one item
        if self.usage == Usage.DEPLOY and "manual_source" in stages_dict:
            if len(stages_dict.get("manual_source", {})) > 1:
                raise ValueError("'manual_source' stage can only contain one item")

    def _validate_stage_items(self, stages_dict: Dict[str, Any]):
        """Validate individual stage items and their requirements."""
        for stage_name, stage_config in stages_dict.items():
            if not isinstance(stage_config, dict):
                continue

            for item_name, item_config in stage_config.items():
                if not isinstance(item_config, dict):
                    continue
                self._validate_item_requirements(stage_name, item_name, item_config, stages_dict)

    def _validate_item_requirements(self, stage_name: str, item_name: str, 
                                   item_config: Dict[str, Any], stages_dict: Dict[str, Any]):
        """Validate requirements for individual stage items."""
        self._validate_build_project_requirement(stage_name, item_name, item_config)
        self._validate_action_type_requirement(stage_name, item_name, item_config)
        self._validate_output_names_requirement(stage_name, item_config)

        if stage_name.lower() == StageType.DEPLOY.value:
            self._validate_deploy_requirements(stage_name, item_name, item_config, stages_dict)

    def _validate_build_project_requirement(self, stage_name: str, item_name: str, item_config: Dict[str, Any]):
        """Validate build_project field requirements for specific stages."""
        build_project_required_stages = {
            StageType.BUILD.value,
            StageType.PUBLISH.value,
            StageType.SELF_MUTATE.value,
            StageType.MANUAL_SOURCE.value,
            StageType.CONTROL.value,
            StageType.SYNTH.value
        }

        requires_build_project = (
            stage_name.lower() in build_project_required_stages or
            (stage_name in (StageType.RELEASE.value, StageType.DEPLOY.value) and 
             item_config.get('action_type') == ActionType.CODEBUILD)
        )

        if requires_build_project and item_config.get('build_project') is None:
            context = ""
            if stage_name in (StageType.RELEASE.value, StageType.DEPLOY.value):
                context = " when 'action_type' is CODEBUILD"
            raise ValueError(f"'build_project' is mandatory for stage '{stage_name}', item '{item_name}'{context}")        

    def _validate_action_type_requirement(self, stage_name: str, item_name: str, item_config: Dict[str, Any]):
        """Validate action_type field requirements for specific stages."""
        if stage_name in [StageType.RELEASE.value, StageType.DEPLOY.value]:
            if item_config.get('action_type') is None:
                raise ValueError(f"'action_type' is mandatory for stage '{stage_name}', item '{item_name}'")

    def _validate_output_names_requirement(self, stage_name: str, item_config: Dict[str, Any]):
        """Validate output_names field restrictions for stages."""
        allowed_stages = {
            StageType.BUILD.value,
            StageType.PUBLISH.value,
            StageType.SELF_MUTATE.value,
            StageType.MANUAL_SOURCE.value,
            StageType.CONTROL.value
        }

        if item_config.get("output_names") and stage_name.lower() not in allowed_stages:
            raise ValueError(
                f"'output_names' is not allowed for stage '{stage_name}'. "
                f"Allowed stages are: {', '.join(sorted(allowed_stages))}"
            )

    def _validate_deploy_requirements(self, stage_name: str, item_name: str, 
                                     item_config: Dict[str, Any], stages_dict: Dict[str, Any]):
        """Validate deployment-specific requirements based on action type."""
        action_type = item_config.get("action_type")
        if action_type == ActionType.CLOUDFORMATION:
            self._validate_cloudformation_deploy(stage_name, item_name, item_config, stages_dict)
        elif action_type == ActionType.S3:
            self._validate_s3_deploy(stage_name, item_name, item_config)

    def _validate_cloudformation_deploy(self, stage_name: str, item_name: str, 
                                       item_config: Dict[str, Any], stages_dict: Dict[str, Any]):
        """Validate CloudFormation deployment requirements."""
        # Validate artifact_id reference
        self._validate_artifact_id_reference(stage_name, item_name, item_config, stages_dict)

        # Validate required CloudFormation fields
        required_fields = ["action_role", "deployment_role", "stack_name", "stack_base_path", "deploy_env"]
        missing_fields = [field for field in required_fields if not item_config.get(field)]

        if missing_fields:
            raise ValueError(
                f"Fields {missing_fields} are mandatory for stage '{stage_name}', item '{item_name}'"
            )

    def _validate_s3_deploy(self, stage_name: str, item_name: str, item_config: Dict[str, Any]):
        """Validate S3 deployment requirements."""
        if not item_config.get("deploy_bucket"):
            raise ValueError(f"'deploy_bucket' is mandatory for stage '{stage_name}', item '{item_name}'")

    def _validate_artifact_id_reference(self, stage_name: str, item_name: str, 
                                       item_config: Dict[str, Any], stages_dict: Dict[str, Any]):
        """Validate that artifact_id references a valid previous stage item."""
        artifact_id = item_config.get("artifact_id")
        if not artifact_id:
            return

        available_items = self._get_available_artifact_items(stages_dict)

        if available_items is None:
            return  # No validation needed for this usage type

        if not available_items:
            raise ValueError(
                f"Could not find a previous stage from which to fetch artifact_id '{artifact_id}'"
            )

        if artifact_id not in available_items:
            previous_stage = self._get_previous_stage_name(stages_dict)
            raise ValueError(
                f"'artifact_id' with value '{artifact_id}' in stage '{stage_name}' -> '{item_name}' "
                f"must refer to one of the following '{previous_stage}' stage items: {', '.join(sorted(available_items))}"
            )

    def _get_available_artifact_items(self, stages_dict: Dict[str, Any]) -> Optional[List[str]]:
        """Get available artifact items from previous stages."""
        if self.usage == Usage.BUILD_DEPLOY:
            return list(stages_dict.get("synth", {}).keys())
        elif self.usage == Usage.DEPLOY and "manual_source" in stages_dict:
            manual_source_config = next(iter(stages_dict.get("manual_source", {}).values()))
            return manual_source_config.get("output_names", [])

        return None  # No validation required

    def _get_previous_stage_name(self, stages_dict: Dict[str, Any]) -> str:
        """Get the name of the previous stage for artifact validation."""
        if self.usage == Usage.BUILD_DEPLOY:
            return StageType.BUILD.value
        elif self.usage == Usage.DEPLOY and "manual_source" in stages_dict:
            return StageType.MANUAL_SOURCE.value

        return "unknown"

typed property

Access to type-safe AWS CDK resource properties, references the Typed inner class.

Typed

Inner class, Type-safe accessor for AWS CDK resources with proper typing.

Source code in mare_aws_common_lib/models/codepipeline_config.py
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
class Typed:
    """Inner class, Type-safe accessor for AWS CDK resources with proper typing."""
    def __init__(self, config: 'CodePipelineConfig'):
        self._config = config

    @property
    def git_repo(self) -> 'codecommit.IRepository':
        """CodeCommit repository for source code."""
        return self._config.git_repo

    @property
    def artifact_bucket(self) -> 's3.IBucket':
        """S3 bucket for pipeline artifacts."""
        return self._config.artifact_bucket

    @property
    def release_bucket(self) -> 's3.IBucket':
        """S3 bucket for release artifacts."""
        return self._config.release_bucket

artifact_bucket property

S3 bucket for pipeline artifacts.

git_repo property

CodeCommit repository for source code.

release_bucket property

S3 bucket for release artifacts.

validate_artifact_bucket(value) classmethod

Validate S3 bucket objects implement s3.IBucket interface.

Source code in mare_aws_common_lib/models/codepipeline_config.py
239
240
241
242
243
@field_validator("artifact_bucket", "release_bucket", mode="after")
@classmethod
def validate_artifact_bucket(cls, value):
    """Validate S3 bucket objects implement s3.IBucket interface."""
    return cls.validate_bucket(value)

validate_git_provider(value) classmethod

Validate git provider is supported (currently CodeCommit only).

Source code in mare_aws_common_lib/models/codepipeline_config.py
225
226
227
228
229
230
231
@field_validator("git_provider", mode="after")
@classmethod
def validate_git_provider(cls, value):
    """Validate git provider is supported (currently CodeCommit only)."""
    if value != GitProvider.CODECOMMIT:
        raise ValueError(f"{value} is not yet supported by the CodebuildBuilder")
    return value

validate_git_repo(value, info) classmethod

Validate git repository object implements codecommit.IRepository interface.

Source code in mare_aws_common_lib/models/codepipeline_config.py
233
234
235
236
237
@field_validator("git_repo", mode="after")
@classmethod
def validate_git_repo(cls, value, info: ValidationInfo):
    """Validate git repository object implements codecommit.IRepository interface."""
    return cls.validate_repository(value, "git", "codecommit.IRepository")

validate_stages_configuration()

Validate complete stage configuration for consistency and requirements.

Returns:

Type Description
CodePipelineConfig

Self with validated stage configuration

Raises:

Type Description
ValueError

If stage configuration is invalid for the usage type

ValueError

If required stage items or fields are missing

ValueError

If artifact references are invalid

Source code in mare_aws_common_lib/models/codepipeline_config.py
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
@model_validator(mode="after")
def validate_stages_configuration(self) -> 'CodePipelineConfig':
    """Validate complete stage configuration for consistency and requirements.

    Returns:
        Self with validated stage configuration

    Raises:
        ValueError: If stage configuration is invalid for the usage type
        ValueError: If required stage items or fields are missing
        ValueError: If artifact references are invalid
    """
    stages_dict = self.stages.model_dump(exclude_none=True)

    # Validate usage-specific stage requirements
    self._validate_usage_stage_requirements(stages_dict)

    # Validate stage-specific restrictions
    self._validate_stage_restrictions(stages_dict)

    # Validate individual stage items
    self._validate_stage_items(stages_dict)

    return self

validate_usage_requirements()

Validate usage-specific required fields are present.

Returns:

Type Description
CodePipelineConfig

Self with validated usage requirements

Raises:

Type Description
ValueError

If required fields for the usage type are missing

Source code in mare_aws_common_lib/models/codepipeline_config.py
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
@model_validator(mode="after")
def validate_usage_requirements(self) -> 'CodePipelineConfig':
    """Validate usage-specific required fields are present.

    Returns:
        Self with validated usage requirements

    Raises:
        ValueError: If required fields for the usage type are missing
    """
    usage_requirements = {
        Usage.BUILD_RELEASE: ["artifact_bucket", "release_bucket"],
        Usage.BUILD_DEPLOY: ["artifact_bucket"],
        Usage.DEPLOY: ["artifact_bucket", "release_bucket", "target_env"]
    }

    required_fields = usage_requirements.get(self.usage, [])
    missing_fields = [field for field in required_fields if getattr(self, field, None) is None]
    if missing_fields:
        raise ValueError(f"Fields {missing_fields} are mandatory for {self.usage}")

    return self
Example
from mare_aws_common_lib.models import CodePipelineConfig, StagesConfig, StageItemConfig
from mare_aws_common_lib.enums import Usage, GitProvider, ActionType
from aws_cdk import aws_codecommit as codecommit, aws_codebuild as codebuild

config = CodePipelineConfig(
    usage=Usage.BUILD_RELEASE,
    git_provider=GitProvider.CODECOMMIT,
    git_repo=codecommit_repository,
    git_branch="main",
    is_dev_branch=False,
    artifact_bucket=artifacts_s3_bucket,
    release_bucket=releases_s3_bucket,
    restart_execution_on_update=True,
    stages=StagesConfig(
        build={
            "compile": StageItemConfig(
                run_order=1,
                build_project=build_codebuild_project,
                output_names=["BuildArtifact"]
            )
        },
        release={
            "publish": StageItemConfig(
                run_order=1,
                action_type=ActionType.S3,
                artifact_id="compile",
                deploy_bucket=releases_s3_bucket
            )
        }
    )
)

StagesConfig

Bases: BaseModel

Configuration model for CodePipeline stage definitions.

Defines the complete set of pipeline stages with their individual action configurations. Each stage contains a dictionary of named actions that execute according to their run_order and action_type specifications.

Attributes:

Name Type Description
source Optional[Dict[str, StageItemConfig]]

Source stage for automatic git repository polling

manual_source Optional[Dict[str, StageItemConfig]]

Manual source stage for artifact-based deployments

control Optional[Dict[str, StageItemConfig]]

Control stage for pipeline validation and gating

manual_approval Optional[bool]

Flag to include manual approval stage

self_mutate Optional[Dict[str, StageItemConfig]]

Self-mutation stage for pipeline updates

build Optional[Dict[str, StageItemConfig]]

Build stage for compilation and testing

release Optional[Dict[str, StageItemConfig]]

Release stage for artifact publishing

publish Optional[Dict[str, StageItemConfig]]

Publish stage for package/image publishing

deploy Optional[Dict[str, StageItemConfig]]

Deploy stage for environment deployment

Source code in mare_aws_common_lib/models/codepipeline_config.py
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
class StagesConfig(BaseModel):
    """Configuration model for CodePipeline stage definitions.

    Defines the complete set of pipeline stages with their individual action
    configurations. Each stage contains a dictionary of named actions that
    execute according to their run_order and action_type specifications.

    Attributes:
        source: Source stage for automatic git repository polling
        manual_source: Manual source stage for artifact-based deployments
        control: Control stage for pipeline validation and gating
        manual_approval: Flag to include manual approval stage
        self_mutate: Self-mutation stage for pipeline updates
        build: Build stage for compilation and testing
        release: Release stage for artifact publishing
        publish: Publish stage for package/image publishing  
        deploy: Deploy stage for environment deployment
    """
    model_config = ConfigDict(extra="forbid", arbitrary_types_allowed=True)

    # Source stages
    source: Optional[Dict[str, StageItemConfig]] = Field(None, description="Source stage configuration")
    manual_source: Optional[Dict[str, StageItemConfig]] = Field(None, description="Manual source stage configuration")

    # Control and approval stages
    control: Optional[Dict[str, StageItemConfig]] = Field(None, description="Control stage configuration")
    manual_approval: Optional[bool] = Field(default=False, description="Whether to include manual approval stage")
    self_mutate: Optional[Dict[str, StageItemConfig]] = Field(None, description="Self-mutate stage configuration")

    # Other stages
    build: Optional[Dict[str, StageItemConfig]] = Field(None, description="Build stage configuration")
    release: Optional[Dict[str, StageItemConfig]] = Field(None, description="Release stage configuration")
    publish: Optional[Dict[str, StageItemConfig]] = Field(None, description="Publish stage configuration")
    deploy: Optional[Dict[str, StageItemConfig]] = Field(None, description="Deploy stage configuration")
    synth: Optional[Dict[str, StageItemConfig]] = Field(None, description="Synth stage configuration")
Example
from mare_aws_common_lib.models import StagesConfig, StageItemConfig

stages = StagesConfig(
    build={
        "unit-tests": StageItemConfig(
            run_order=1,
            build_project=unit_test_project,
            output_names=["TestResults"]
        ),
        "compile": StageItemConfig(
            run_order=2,
            build_project=compilation_project,
            output_names=["BuildArtifacts"]
        ),
        "integration-tests": StageItemConfig(
            run_order=3,
            build_project=integration_test_project,
            extra_inputs=["TestResults"],
            artifact_id="compile"
        )
    }
)

StageItemConfig

Bases: BaseModel, AwsTypesValidationMixin

Configuration model for individual CodePipeline stage actions.

Defines the structure and validation rules for pipeline stage actions including build actions, deployment actions, and artifact management. Supports different action types with specific validation requirements for each action configuration.

Attributes:

Name Type Description
run_order int

Execution order within the stage (determines parallel vs sequential execution)

action_type Optional[ActionType]

Type of action (CODEBUILD, CLOUDFORMATION, S3, etc.)

build_project Optional[Any]

CodeBuild project for build and custom actions

action_env_vars Optional[Dict[str, Any]]

Environment variables for CodeBuild actions

extra_inputs Optional[List[str]]

Additional input artifact names beyond primary input

artifact_id Optional[str]

ID of the input artifact from previous stages

output_names Optional[List[str]]

Names of output artifacts produced by this action

action_role Optional[Any]

IAM role for action execution permissions

deployment_role Optional[Any]

IAM role for CloudFormation deployment operations

stack_base_path Optional[str]

Base path for CloudFormation templates in repository

stack_name Optional[str]

CloudFormation stack name for deployment actions

deploy_env Optional[str]

Target environment for deployment (dev, test, prod)

deploy_bucket Optional[Any]

S3 bucket for S3 deployment actions

Source code in mare_aws_common_lib/models/codepipeline_config.py
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
class StageItemConfig(BaseModel, AwsTypesValidationMixin):
    """Configuration model for individual CodePipeline stage actions.

    Defines the structure and validation rules for pipeline stage actions including
    build actions, deployment actions, and artifact management. Supports different
    action types with specific validation requirements for each action configuration.

    Attributes:
        run_order: Execution order within the stage (determines parallel vs sequential execution)
        action_type: Type of action (CODEBUILD, CLOUDFORMATION, S3, etc.)
        build_project: CodeBuild project for build and custom actions
        action_env_vars: Environment variables for CodeBuild actions
        extra_inputs: Additional input artifact names beyond primary input
        artifact_id: ID of the input artifact from previous stages
        output_names: Names of output artifacts produced by this action
        action_role: IAM role for action execution permissions
        deployment_role: IAM role for CloudFormation deployment operations
        stack_base_path: Base path for CloudFormation templates in repository
        stack_name: CloudFormation stack name for deployment actions
        deploy_env: Target environment for deployment (dev, test, prod)
        deploy_bucket: S3 bucket for S3 deployment actions
    """
    model_config = ConfigDict(extra="forbid", arbitrary_types_allowed=True)

    # Core configuration
    run_order: int = Field(..., description="Execution order within the stage")
    action_type: Optional[ActionType] = Field(None, description="Type of action to perform")

    # Build configuration
    build_project: Optional[Any] = Field(None, description="CodeBuild project for build actions")
    action_env_vars: Optional[Dict[str, Any]] = Field(None, description="Environment variables for the action")

    # Input/Output configuration
    extra_inputs: Optional[List[str]] = Field(None, description="List of additional input artifact names")
    artifact_id: Optional[str] = Field(None, description="ID of the input artifact")
    output_names: Optional[List[str]] = Field(None, description="List of output artifact names")

    # IAM configuration
    action_role: Optional[Any] = Field(None, description="IAM role for the action")
    deployment_role: Optional[Any] = Field(None, description="IAM role for deployment")

    # CloudFormation configuration
    stack_base_path: Optional[str] = Field(None, description="Base path for CloudFormation stack in your project")
    stack_name: Optional[str] = Field(None, description="CloudFormation stack name")
    deploy_env: Optional[str] = Field(None, description="Deployment environment name")

    # S3 configuration
    deploy_bucket: Optional[Any] = Field(None, description="S3 bucket for deployment")

    class Typed:
        """Inner class, Type-safe accessor for AWS CDK resources with proper typing."""
        def __init__(self, config: 'StageItemConfig'):
            self._config = config

        @property
        def action_role(self) -> 'iam.IRole':
            """IAM role for action execution."""
            return self._config.action_role

        @property
        def deployment_role(self) -> 'iam.IRole':
            """IAM role for CloudFormation deployment."""
            return self._config.deployment_role

        @property
        def deploy_bucket(self) -> 's3.IBucket':
            """S3 bucket for deployment actions."""
            return self._config.deploy_bucket

    @property
    def typed(self) -> Typed:
        """Access to type-safe AWS CDK resource properties, references the Typed inner class."""
        if not hasattr(self, '_typed'):
            self._typed = self.Typed(self)
        return self._typed

    @field_validator("build_project", mode="after")
    @classmethod
    def validate_build_project(cls, value):
        """Validate CodeBuild project object implements proper interface."""
        if value is not None and not (hasattr(value, 'project_arn') and hasattr(value, 'project_name')):
            raise ValueError("Must be a valid codebuild.IProject object")
        return value

    @field_validator("action_env_vars", mode="after")
    @classmethod
    def validate_action_env_vars(cls, value):
        """Validate environment variables are proper CodeBuild format."""
        return cls.validate_vars(value)

    @field_validator("action_role", "deployment_role", mode="after")
    @classmethod
    def validate_action_role(cls, value):
        """Validate IAM role objects implement iam.IRole interface."""
        return cls.validate_role(value)

    @field_validator("deploy_bucket", mode="after")
    @classmethod
    def validate_deploy_bucket(cls, value):
        """Validate S3 bucket object implements s3.IBucket interface."""
        return cls.validate_bucket(value)

typed property

Access to type-safe AWS CDK resource properties, references the Typed inner class.

Typed

Inner class, Type-safe accessor for AWS CDK resources with proper typing.

Source code in mare_aws_common_lib/models/codepipeline_config.py
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
class Typed:
    """Inner class, Type-safe accessor for AWS CDK resources with proper typing."""
    def __init__(self, config: 'StageItemConfig'):
        self._config = config

    @property
    def action_role(self) -> 'iam.IRole':
        """IAM role for action execution."""
        return self._config.action_role

    @property
    def deployment_role(self) -> 'iam.IRole':
        """IAM role for CloudFormation deployment."""
        return self._config.deployment_role

    @property
    def deploy_bucket(self) -> 's3.IBucket':
        """S3 bucket for deployment actions."""
        return self._config.deploy_bucket

action_role property

IAM role for action execution.

deploy_bucket property

S3 bucket for deployment actions.

deployment_role property

IAM role for CloudFormation deployment.

validate_action_env_vars(value) classmethod

Validate environment variables are proper CodeBuild format.

Source code in mare_aws_common_lib/models/codepipeline_config.py
95
96
97
98
99
@field_validator("action_env_vars", mode="after")
@classmethod
def validate_action_env_vars(cls, value):
    """Validate environment variables are proper CodeBuild format."""
    return cls.validate_vars(value)

validate_action_role(value) classmethod

Validate IAM role objects implement iam.IRole interface.

Source code in mare_aws_common_lib/models/codepipeline_config.py
101
102
103
104
105
@field_validator("action_role", "deployment_role", mode="after")
@classmethod
def validate_action_role(cls, value):
    """Validate IAM role objects implement iam.IRole interface."""
    return cls.validate_role(value)

validate_build_project(value) classmethod

Validate CodeBuild project object implements proper interface.

Source code in mare_aws_common_lib/models/codepipeline_config.py
87
88
89
90
91
92
93
@field_validator("build_project", mode="after")
@classmethod
def validate_build_project(cls, value):
    """Validate CodeBuild project object implements proper interface."""
    if value is not None and not (hasattr(value, 'project_arn') and hasattr(value, 'project_name')):
        raise ValueError("Must be a valid codebuild.IProject object")
    return value

validate_deploy_bucket(value) classmethod

Validate S3 bucket object implements s3.IBucket interface.

Source code in mare_aws_common_lib/models/codepipeline_config.py
107
108
109
110
111
@field_validator("deploy_bucket", mode="after")
@classmethod
def validate_deploy_bucket(cls, value):
    """Validate S3 bucket object implements s3.IBucket interface."""
    return cls.validate_bucket(value)
Example
from mare_aws_common_lib.models import StageItemConfig
from aws_cdk import aws_codebuild as codebuild

# Build action with CodeBuild project
build_action = StageItemConfig(
    run_order=1,
    build_project=my_codebuild_project,
    action_env_vars={
        "ENVIRONMENT": codebuild.BuildEnvironmentVariable(value="production"),
        "BUILD_NUMBER": codebuild.BuildEnvironmentVariable(value="${CODEBUILD_BUILD_NUMBER}")
    },
    output_names=["BuildArtifacts", "TestReports"]
)