Search code examples
amazon-web-servicesaws-lambdamicroservicesaws-cdkaws-codepipeline

Create one empty cdk pipeline to deploy any lambda code


Can we create a simple cdk pipeline that self update pipeline as shown in (here) But only one pipeline for many micro services that deploy and update lambda code. Is this possible. So that we don't have to create pipeline for every micro service.


Solution

  • If the microservices ARE NOT in the same repo I probably wouldn't recommend it. Its possible to add additional source stages, but I cannot speak to how the pipeline is triggered when there are multiple repos.

    If the microservices ARE in the same repo, you can certainly do this. How the code is structured is up to you. You could group all the resources for each microservice in a single Stack and then have 1 Stage that deploys each MicroserviceStack.

    var pipeline = new CdkPipeline(this, "Test", new CdkPipelineProps());
    
    pipeline.AddApplicationStage(new AllMicroservicesStage(this, "Test", new StageProps()));
    
    
    class AllMicroservicesStage : Stage
    {
      var ms1 = new Microservice1Stack();
    
      var ms2 = new Microservice2Stack();
    
      ...
    }
    
    

    Or seperate each microservice as a Stage with a collection of Stacks in each.

    var pipeline = new CdkPipeline(this, "Test", new CdkPipelineProps());
    
    pipeline.AddApplicationStage(new Microservice1Stage(this, "Test", new StageProps()));
    
    pipeline.AddApplicationStage(new Microservice2Stage(this, "Test2", new StageProps()));
    
    
    class Microservice1Stage : Stage
    {
      var s1 = new WebsiteStack();
    
      var s2 = new QueueProcessingServiceStack();
    
      var s3 = new AuthServerStack();
    
      ...
    }
    
    class Microservice2Stage : Stage
    {
      var s1 = new InternalWebsiteStack();
    
      var s2 = new NetworkInfrastructureStack();
    
      var s3 = new ApiStack();
    
      ...
    }
    
    

    This is just pseudo code for C#.