Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

aws-ecs-patterns: ApplicationLoadBalancedFargateService not generating health check #29832

Open
oechsler opened this issue Apr 15, 2024 · 2 comments
Labels
@aws-cdk/aws-ecs-patterns Related to ecs-patterns library bug This issue is a bug. effort/medium Medium work item – several days of effort p2

Comments

@oechsler
Copy link

Describe the bug

The current implementation of the ApplicationLoadBalancedFargateService is not generating the health checks definition for the service in CloudFormation.

Example code that produces the Issue:

const service = new ApplicationLoadBalancedFargateService(
  this.scope,
  `${this.defineServiceName()}-${this.namingPrefix}-service`,
  {
    serviceName: `${this.defineServiceName()}-${this.namingPrefix}`,
    cluster: this.ecsConstruct.cluster,
    taskDefinition: taskDefinition,
    circuitBreaker: { rollback: true },
    desiredCount: 1,
    healthCheck: {
      command: ['CMD-SHELL', '/opt/health-check.sh >> /proc/1/fd/1 2>&1 || exit 1'],
      interval: Duration.seconds(10),
      retries: 3,
      startPeriod: Duration.seconds(30),
      timeout: Duration.seconds(8),
    },
    loadBalancerName: `${this.namingPrefix}-frontend`,
    targetProtocol: ApplicationProtocol.HTTP,
    protocolVersion: ApplicationProtocolVersion.GRPC,
    certificate: certificate,
    cloudMapOptions: this.baseService.defineCloudMapOptions(
      this.ecsConstruct.cluster.defaultCloudMapNamespace!,
    ),
  },
);

Generated CloudFormation output:

{
  // ...
  "...146D4EEB": {
   "Type": "AWS::ECS::TaskDefinition",
   "Properties": {
    "ContainerDefinitions": [
     {
      "Environment": [
       // ...
      ],
      "Essential": true,
      "Image": {
       "Fn::Sub": "..."
      },
      "LogConfiguration": {
       "LogDriver": "awslogs",
       "Options": {
        "awslogs-group": {
         "Ref": "..."
        },
        "awslogs-stream-prefix": "...",
        "awslogs-region": "..."
       }
      },
      "Name": "...",
      "PortMappings": [
       {
        "AppProtocol": "grpc",
        "ContainerPort": 9000,
        "HostPort": 9000,
        "Name": "f-9000",
        "Protocol": "tcp"
       },
       // ...
      ],
      "StartTimeout": 150
     }
    ],
    "Cpu": "1024",
    "ExecutionRoleArn": {
     "Fn::GetAtt": [
      "...",
      "Arn"
     ]
    },
    "Family": "...",
    "Memory": "4096",
    "NetworkMode": "awsvpc",
    "RequiresCompatibilities": [
     "FARGATE"
    ],
    "RuntimePlatform": {
     "CpuArchitecture": "ARM64",
     "OperatingSystemFamily": "LINUX"
    },
    "TaskRoleArn": {
     "Fn::GetAtt": [
      "...",
      "Arn"
     ]
    }
   },
   "Metadata": {
    "aws:cdk:path": "..."
   }
  },
  // ...
}

Names censored

Expected Behavior

That the defined health check in CDK code is generated in the CloudFormation output and deployed to AWS.

Current Behavior

No health check is generated, nor deployed.

Reproduction Steps

  1. Define ApplicationLoadBalancedFargateService from provided example with healthCheck set.
  2. Run cdk synth
  3. Check output in cdk.out

Possible Solution

No response

Additional Information/Context

No response

CDK CLI Version

2.137.0 (build bb90b4c)

Framework Version

No response

Node.js Version

v20.12.1

OS

macOS 14.4.1 (23E224)

Language

TypeScript

Language Version

No response

Other information

No response

@oechsler oechsler added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Apr 15, 2024
@github-actions github-actions bot added the @aws-cdk/aws-ecs-patterns Related to ecs-patterns library label Apr 15, 2024
@pahud
Copy link
Contributor

pahud commented Apr 17, 2024

It actually runs this for you under the hood:

const container = this.taskDefinition.addContainer(containerName, {
image: taskImageOptions.image,
healthCheck: props.healthCheck,

Can you share how to define your taskDefinition in CDK?

@pahud pahud added p2 response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. effort/medium Medium work item – several days of effort and removed needs-triage This issue or PR still needs to be triaged. labels Apr 17, 2024
@oechsler
Copy link
Author

new ecs.FargateTaskDefinition(
  this.scope,
  `${this.serviceName}-${this.namingPrefix}-task-def`,
  {
    runtimePlatform: {
      cpuArchitecture: CpuArchitecture.ARM64,
      operatingSystemFamily: OperatingSystemFamily.LINUX,
    },
    cpu: props.cpu,
    memoryLimitMiB: props.memoryLimitMiB,
  },
);

taskDefinition.addContainer(`${this.serviceName}-${this.namingPrefix}-container`, {
  image: props.image,
  containerName: `${this.serviceName}-${this.namingPrefix}`,
  logging: new ecs.AwsLogDriver({
    streamPrefix: `${this.serviceName}-${this.namingPrefix}`,
    logGroup: this.defineLogGroup(),
  }),
  environment: this.getCommonEnvironmentVariables(this.dbConstruct, props.frontendService),
  portMappings: props.portMappings,
  startTimeout: props.delay,
});

Here you go

@github-actions github-actions bot removed the response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. label Apr 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-ecs-patterns Related to ecs-patterns library bug This issue is a bug. effort/medium Medium work item – several days of effort p2
Projects
None yet
Development

No branches or pull requests

2 participants