Angus
Angus

Reputation: 25

Using ApplicationLoadBalancedFargateService with aws-codepipeline-actions

  // fargate
  const ecsService = new patterns.ApplicationLoadBalancedFargateService(this, 'Service', {
    cluster: cluster, // Required
    publicLoadBalancer: true,
    taskImageOptions: {
      image: ecs.ContainerImage.fromRegistry('nginx')
    }
  });

  // codepipeline artifact
  const sourceOutput = new codepipeline.Artifact();

  // pipeline
  const pipeline = new codepipeline.Pipeline(this, 'Pipeline');
  // pipeline stage: Source
  pipeline.addStage({
    stageName: 'Source',
    actions: [
      new codepipeline_actions.EcrSourceAction({
        actionName: 'ecr_push',
        repository: repository,
        output: sourceOutput
      })
    ]
  });
  // pipeline stage: Deploy
  pipeline.addStage({
    stageName: 'Deploy',
    actions: [
      new codepipeline_actions.EcsDeployAction({
        actionName: 'Deploy',
        input: sourceOutput,
        service: ecsService
      })
    ]
  });

Using patterns ApplicationLoadBalancedFargateService to create fagate service

But, codepipeline_actions EcsDeployAction props service required type ecs.BaseService

How to resolve this problem? Back to build fargae service from scrath ?

Any suggestion will be appreciated !!

Upvotes: 2

Views: 754

Answers (1)

djheru
djheru

Reputation: 3719

The ApplicationLoadBalancedFargateService higher-level pattern has a service property that is exposed on the instance. The type of ecsService.service is FargateService which implements the IBaseService interface. Your code should work if you change it to :

  pipeline.addStage({
    stageName: 'Deploy',
    actions: [
      new codepipeline_actions.EcsDeployAction({
        actionName: 'Deploy',
        input: sourceOutput,
        service: ecsService.service, // <-
      })
    ]
  });

https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-ecs-patterns.ApplicationLoadBalancedFargateService.html#service

Upvotes: 2

Related Questions