cloudformation-coverage-roadmap icon indicating copy to clipboard operation
cloudformation-coverage-roadmap copied to clipboard

AWS::CodeBuild::Build

Open benbridts opened this issue 4 years ago • 5 comments

Name of the resource

Other

Resource name

AWS::CodeBuild::Build

Description

There is currently no way to start a CodeBuild Build from CloudFormation. this could be useful in cases where build should be started (at least) once.

Other Details

See https://github.com/WeAreCloudar/cloudformation-samples/tree/main/resource_providers/cloudar_codebuild_build for an example implementation

benbridts avatar Dec 09 '21 20:12 benbridts

CloudFormation is a state-based tool for managing resource, CodeBuild project execution is something rather imperative, not declarative. If you need to run CodeBuild I would rather use Event Bus (you can define Event Rule in CloudFormation for that) or CodePipeline to first deploy CloudFormation and after that, in next phase run CodeBuild with input from stack outputs.

rafalwrzeszcz avatar Aug 20 '22 00:08 rafalwrzeszcz

It depends a bit on how you look at the build. The options you give work if you only care about triggering the build. If you care about the build actually succeeding (and the stack rolling back if it doesn't), a CodeBuild Build is very similar to a CloudFormation Custom Resource.

benbridts avatar Aug 20 '22 21:08 benbridts

As you pointed out CodeBuild in this case acts as a custom resource handler, which means it's the underlying implementaiton, not really description of the resource itself. Succeeded build is not a persistet state, but rather temporary one - for that still a CodePipeline seems more accurate (for which you can define a AWS::CodePipeline::Pipeline resource with CodeBuild step in it).

rafalwrzeszcz avatar Aug 20 '22 22:08 rafalwrzeszcz

Succeeded build is not a persistet state

It is for that particular build. It's perfectly doable to create a CloudFormation Resources Type that follows the required contract.

You might not need this resource, but that does not make the request invalid

benbridts avatar Aug 20 '22 23:08 benbridts

I'd point out that there's an AWS blog on running bash scripts in a CloudFormation template: https://aws.amazon.com/blogs/mt/running-bash-commands-in-aws-cloudformation-templates/

It feels like we should also be having a discussion on cfn-language-discussion about how best to include imperative steps in the stack update process. I'm not convinced "inside the template" is the best answer.

benkehoe avatar Aug 22 '22 13:08 benkehoe