0

My AWS Project builds a Docker Image, pushes it to ECR and then deploys it to an ECS container.

The source code is on CodeCommit, and I already have two working CDK Stacks to 1) Build the Docker image, and 2) Deploy to ECS.

I would like to setup a pipeline via CDK. If I use the console, it is very straightforward to setup the pipeline adding the "Build" and "Deploy" stages defined by the stacks.

If I want to setup the pipeline via CDK, I could use a CDK Python code like this one:

# Create a source action for CodeCommit
source_action = cpactions.CodeCommitSourceAction(
            action_name="CodeCommit",
            output=codepipeline.Artifact("SourceArtifact")
            repository=codecommit.Repository(self, "SourceRepo",
                                             repository_name=SOURCE_GIT_REPOSITORY),
            branch=SOURCE_GIT_BRANCH
        )

# Create a ShellStep for the synth action (BUT I DO NOT NEED THIS!!!)
synth_action = pipelines.ShellStep("Synth",
                                   input=source_action.output,
                                   commands=[])

# Create a new CodePipeline
pipeline = pipelines.CodePipeline(self, PIPELINE_NAME,
                     pipeline_name=PIPELINE_NAME,
                     synth=synth_action, # THIS IS NOT OPTIONAL!
                     self_mutation=False)

# Add the build stage
pipeline.add_stage(BuildStage(self, "Build"))

# Add the deploy stage
pipeline.add_stage(DeployStage(self, "Deploy", env=kwargs['env']))

the problem is that the 'synth' parameter is required, but I definitely do not need it! What can I do to have my pipeline working without a "synth"? I just need to have source code, and then Build and Deploy stages.

What am I missing?

(BTW, the compiler complains that in the above code 'Build' action already exists, to underline that I did not understand the difference between 'Build' and 'Synth'...)

1 Answer 1

1

CodePipeline from pipelines package is used to build and deploy CDK applications. That's why it uses synth step. If you want to build and deploy docker image to ECR, you should use Pipeline construct from aws_codepipeline package. Check documentation for more details.

Sign up to request clarification or add additional context in comments.

2 Comments

Ok, that makes sense. But using console, I directly add my existing CodeBuild and CodeDeploy services to the new Pipeline. I just want to do same thing, and apparently CodePipeline let me add Stacks (wrapped as Stages) in the pipeline, while it seems there's no way to do that with Pipeline.
Not sure what you mean it allows you to add stacks... CodePipeline allows you to add stages to it. Do you want to add existing Build and CodeDeploy projects, or projects that are created through CDK? You have the add_stage method in the Pipeline docs.aws.amazon.com/cdk/api/v2/python/aws_cdk.aws_codepipeline/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.