0

我在AWS管道与Codestar,CodeBuild,CloudFormation等AWS导入信息从CloudFormation到CodeBuild

我试图找出如何从返回CodeBuild步骤CloudFormation步骤的信息。让我把它分解:

  1. 我用我们的template.yml

    # template.yml 
    
    ... 
    S3BucketAssets: 
        Type: AWS::S3::Bucket 
    ... 
    
  2. 在这一点上有过一个CloudFormation构建一个buildspec.yml为CodeBuild

    # buildspec.yml 
    
    ... 
    phases: 
    ... 
    build: 
        commands: 
        - aws cloudformation package --region $REGION --template template.yml --s3-bucket $S3_BUCKET --output-template $OUTPUT_TEMPLATE 
    
  3. 上面踢,它为S3存储桶创建唯一的名称。真棒。现在,对于CodeBuild的buildspec.yml中的步骤2,我想将项目推送到刚刚在CloudFormation模板中创建的S3存储桶。但是,我不知道如何从CloudFormation模板中获取动态创建的S3存储桶的名称。我想类似的东西:

    # buildspec.yml 
    
    ... 
    phases: 
    ... 
    build: 
        commands: 
        # this is the same step as shown above 
        - aws cloudformation package --region $REGION --template template.yml --s3-bucket $S3_BUCKET --output-template $OUTPUT_TEMPLATE 
        # this is the new step 
        - aws s3 sync dist_files/ s3://{NAME_OF_THE_NEW_S3_BUCKET} 
    

如何可以完成获取动态命名的S3存储,这样我可以推到了吗?

我知道,在CloudFormation模板中,您可以引用S3存储桶名称,如!GetAtt [ClientWebAssets, WebsiteURL]。但是,我不知道如何将这些信息从cloudformation模板中提取出来并返回到codebuild模板中。

回答