Search code examples
python-3.xamazon-web-servicescontinuous-integrationaws-codebuildaws-codestar

How to customize AWS Codestar / Cloudformation template to create specific codebuild project?


How to customize AWS Codestar / Cloudformation template to create specific codebuild project

Resources like lambda are fine, SAM > Codestar Project template working ok

Problem is when I am trying to add a CodeBuild settings , with specific docker image (need to use Python 3.7 instead of default 2.7) Using Yaml for template.yml + buildspec.yml

    AWSTemplateFormatVersion: 2010-09-09
    Transform:
    - AWS::Serverless-2016-10-31
    - AWS::CodeStar

    Parameters:
      ProjectId:
        Type: String
        Description: CodeStar projectId used to associate new resources to team members
    Resources:
      HelloWorld:
        Type: AWS::Serverless::Function
        Properties:
          Handler: index.lambda_handler
          Runtime: python3.7
          Layers:
          - arn:aws:lxxxxxxxxxxxxxxxxxxxxxx:1
          Role:
          - arn:aws:iam::xxxxxxxxxxxxxxxxxxxxxx

      CodeBuildProject:
        Type: AWS::CodeBuild::Project
        Properties:
          Description: Codebuild project Validate Packer Template
          Artifacts:
            Type: CODEPIPELINE
          Environment:
            Type: LINUX_CONTAINER
            ComputeType: BUILD_GENERAL1_SMALL
            Image: aws/codebuild/python:3.7.1
        Source:
          Type: CODEPIPELINE
        TimeoutInMinutes: 1

Lambda is created succesfully, but Codebuild sections is ignored and nothing happens

EDIT 2 I Was able to edit CF template to force creation of another CodeBuild Project.Unfortunately, it functions like competely separate component

From docs, it appears that it is possible to change resources after creation, supposed to be change a change set CF deploy.

But what about Pipeline changes via code , after default template (sam + Python) was used? Is there a way to overwrite codebuild env(change the docker image to be used) within pipiline in CodeStar? Through COnsole, of course you can change and update anything + overwrite. But nothing in docs about how to do this via template.yml / template.json files


Solution

  • From what I found, there are couple layers of components When you create Codestar project via Console, you select default template. This is the one you need to edit, to change the underlying CodePupeline

    I found a workaround : creating project via CLI This way, you can use toolchain.yml (it is also possibl eediting via console, which contradicts with IAC principle) and edit it, to get needed custom pipeline of any kind