AWSCDK中的aws-codepipeline/Pipeline与pipelines/CodePipelines有什么区别?
创始人
2024-09-24 03:01:31
0

aws-codepipeline/Pipeline是AWS CDK中的高级抽象类,用于创建AWS CodePipeline管道。而pipelines/CodePipelines是AWS CDK中的低级抽象类,可用于构建与自定义AWS CodePipeline管道。

下面是使用aws-codepipeline/Pipeline创建AWS CodePipeline管道的示例代码:

from aws_cdk import (
    aws_codepipeline as codepipeline,
    aws_codepipeline_actions as actions,
    aws_s3 as s3,
    core,
)


class MyStack(core.Stack):
    def __init__(self, scope: core.Construct, id: str, **kwargs) -> None:
        super().__init__(scope, id, **kwargs)

        source_artifact = codepipeline.Artifact()
        output_artifact = codepipeline.Artifact()

        # Create an S3 bucket to hold the source code
        source_bucket = s3.Bucket(
            self, "SourceBucket",
            versioned=True
        )

        # Create the CodePipeline pipeline
        pipeline = codepipeline.Pipeline(
            self, "Pipeline",
            pipeline_name="MyPipeline"
        )

        # Define pipeline stages
        source_stage = pipeline.add_stage(
            stage_name="Source",
            actions=[
                actions.S3SourceAction(
                    action_name="S3Source",
                    bucket=source_bucket,
                    bucket_key="src.zip",
                    output=source_artifact
                )
            ]
        )

        build_stage = pipeline.add_stage(
            stage_name="Build",
            actions=[
                actions.CodeBuildAction(
                    action_name="CodeBuild",
                    project=codebuild_project,
                    input=source_artifact,
                    outputs=[output_artifact]
                )
            ]
        )

        # Add a manual approval action
        approval_stage = pipeline.add_stage(
            stage_name="Approval",
            actions=[
                actions.ManualApprovalAction(
                    action_name="Approval"
                )
            ]
        )

        # Define the pipeline's deployment stage
        deploy_stage = pipeline.add_stage(
            stage_name="Deploy",
            actions=[
                actions.CloudFormationCreateUpdateStackAction(
                    action_name="Deploy",
                    stack_name="MyStack",
                    template_path=output_artifact.at_path("template.yaml"),
                    admin_permissions=True
                )
            ]
        )

下面是使用pipelines/CodePipelines创建AWS CodePipeline管道的示例代码:

from aws_cdk import (
    aws_cloudformation as cfn,
    aws_lambda as lambda_,
    aws_events as events,
    aws_events_targets as targets,
    aws_codepipeline as codepipeline,
    aws_codepipeline_actions as actions,
    aws_iam as iam,
    aws_codebuild as codebuild,
    aws_s3_assets as s3_assets,
    aws_s3 as s3,
    core,
)


class MyStack(core.Stack):
    def __init__(self, scope: core.Construct, id: str, **kwargs) -> None:
        super().__init__(scope, id, **kwargs)

        source_artifact = codepipeline.Artifact()
        output_artifact = codepipeline.Artifact()

        pipeline = codepipeline.Pipeline(
            self, "Pipeline",
            pipeline_name="MyPipeline"
        )

        # Add a source stage to the pipeline
        source_stage = pipeline.add_stage(
            stage_name="Source"
        )

        # Create an S3 bucket to hold the source code
        source_bucket = s3.Bucket(
            self, "SourceBucket",
            versioned=True
        )

        # Add an S3 source action to the pipeline
        source_action = actions.S3SourceAction(
            action_name="S

相关内容

热门资讯

关于!微信微乐自建房辅助工具,... 关于!微信微乐自建房辅助工具,微乐家乡麻将自建房辅助app(开挂自建房)方法1)微乐家乡麻将自建房辅...
大家学习交流!微信卡五星辅助器... 大家学习交流!微信卡五星辅助器,微乐小程序免费黑科技(开挂自建房)方法1、很好的工具软件,可以解锁游...
三分钟了解!微乐微信自建房辅助... 三分钟了解!微乐微信自建房辅助工具插件,微乐家乡麻将自建房辅助app(开挂自建房)工具1、三分钟了解...
一分钟教会你!微乐家乡麻将自建... 一分钟教会你!微乐家乡麻将自建房辅助app,微乐自建房脚本免费入口(开挂自建房)方法1、用户打开应用...
分享实测!微信微乐自建房辅助工... 分享实测!微信微乐自建房辅助工具,微乐自建房脚本免费入口(开挂自建房)器1、起透看视 微信微乐自建房...
重大通报!微乐自建房辅助工具脚... 重大通报!微乐自建房辅助工具脚本,微乐小程序免费黑科技(开挂自建房)app微乐自建房辅助工具脚本破解...
如何分辨真伪!微乐微信自建房辅... 如何分辨真伪!微乐微信自建房辅助工具插件,微乐小程序免费黑科技(开挂自建房)技巧1、微乐微信自建房辅...
我来教教你!微乐自建房辅助工具... 我来教教你!微乐自建房辅助工具挂,微乐家乡麻将自建房辅助app(开挂自建房)工具1、玩家可以在微乐家...
重大来袭!微乐自建房辅助工具神... 重大来袭!微乐自建房辅助工具神器,微乐小程序免费黑科技(开挂自建房)器1、游戏颠覆性的策略玩法,独创...
带你了解!微信卡五星辅助器,微... 带你了解!微信卡五星辅助器,微乐自建房脚本免费入口(开挂自建房)方法1、带你了解!微信卡五星辅助器,...