结合使用ApplicationLoadBalancedFargateService和aws-codepipeline-actions

时间:2019-11-14 02:06:37

标签: aws-cdk

  // 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
      })
    ]
  });

使用模式ApplicationLoadBalancedFargateService创建Fagate服务

但是,codepipeline_actions EcsDeployAction道具service需要类型ecs.BaseService

如何解决此问题?从scrath返回来构建Fargae服务?

任何建议将不胜感激!

1 个答案:

答案 0 :(得分:1)

ApplicationLoadBalancedFargateService更高级别的模式具有实例上公开的service属性。 ecsService.service的类型为FargateService,它实现了IBaseService接口。如果将代码更改为:

  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