【问题标题】:How to use pre-existing Amazon S3 bucket for Artifacts in cdk python?如何在 cdk python 中为 Artifacts 使用预先存在的 Amazon S3 存储桶?
【发布时间】:2021-11-04 06:19:42
【问题描述】:

如何将预先存在的 Amazon S3 存储桶用于 source_artifact 和 cloud_assembly_artifact Artifacts docs here我的代码在下面

source_artifact = codepipeline.Artifact()
cloud_assembly_artifact = codepipeline.Artifact()   

pipeline = pipelines.CdkPipeline(self, 'Pipeline',
  cloud_assembly_artifact=cloud_assembly_artifact,
  pipeline_name='testPipeline',
  source_action = cpactions.CodeCommitSourceAction(
            repository=codecommit.Repository.from_repository_name(
              self, 
              id="cicd_pipeline",
              repository_name="repo-name"
            ),
            branch='master',
            action_name='CodeCommit',
            trigger=cpactions.CodeCommitTrigger.POLL,
            output=source_artifact,
        ),
  synth_action=pipelines.SimpleSynthAction(
    source_artifact=source_artifact,
    cloud_assembly_artifact=cloud_assembly_artifact,
    install_command='npm install -g aws-cdk && pip install -r requirements.txt',
    build_command='pytest unittests',
    synth_command='cdk synth'))

【问题讨论】:

    标签: python amazon-web-services amazon-s3 aws-cdk aws-codepipeline


    【解决方案1】:

    您应该创建一个代码管道管道并在其中附加一个工件桶。

    创建管道后,您可以在 CdkPipeline 构造中指定代码管道。 (打字稿但应该和python类似)

    this._artifactsS3Bucket = Bucket.fromBucketArn(this, 'S3ArtifactsBucket', this._props.s3ArtifactBucketARN);
    new Pipeline(this, 'Pipeline', {
          artifactBucket: this._artifactsS3Bucket,
          pipelineName: this._pipelineName,
          restartExecutionOnUpdate: true
    });
    

    将此 codePipeline 附加到 cdkPipeline 的构造

    【讨论】:

    • pipeline = pipelines.CdkPipeline(self, 'Pipeline', cloud_assembly_artifact=cloud_assembly_artifact, code_pipeline = codepipeline.Pipeline(self, 'Pipeline1', artifact_bucket=s3.Bucket.from_bucket_name(self, id="test", bucket_name="bucket-name"), restart_execution_on_update=None), pipeline_name='testPipeline',
    • 使用后出现错误。 ` '文件“/home/sameed/.local/lib/python3.8/site-packages/jsii/_kernel/providers/process.py”,第 326 行,从 JavaScriptError(resp.error) 发送引发 JSIIError(resp.error)堆栈)jsii.errors.JSIIError:如果使用“codePipeline”给出现有的 CodePipeline,则无法设置“pipelineName”`
    • 如果您已经使用了以前创建的管道,则不能在 cdk 管道构造中使用管道名称。
    • @SameedUsmani 对你有用吗?如果看到请接受这个答案,以便将来的用户可以得到帮助。
    • cdcp = codepipeline.Pipeline(self, 'codepipeline', artifact_bucket=bucket, restart_execution_on_update=None, pipeline_name="cdktestpipeline")
    猜你喜欢
    • 2021-09-06
    • 1970-01-01
    • 1970-01-01
    • 2023-03-31
    • 2016-08-25
    • 1970-01-01
    • 2020-07-16
    • 1970-01-01
    • 2012-06-27
    相关资源
    最近更新 更多