Skip to content

feat(elasticloadbalancingv2): health check logs for ALB#36227

Open
ren-yamanashi wants to merge 18 commits intoaws:mainfrom
ren-yamanashi:feat/alb-healthcheck-log
Open

feat(elasticloadbalancingv2): health check logs for ALB#36227
ren-yamanashi wants to merge 18 commits intoaws:mainfrom
ren-yamanashi:feat/alb-healthcheck-log

Conversation

@ren-yamanashi
Copy link
Copy Markdown
Contributor

@ren-yamanashi ren-yamanashi commented Nov 27, 2025

This PR is similar to #30599

Reason for this change

ALB can output health check logs as well as access logs to the S3 bucket, but this is not yet supported by L2 Construct.
https://docs.aws.amazon.com/elasticloadbalancing/latest/application/enable-health-check-logging.html

Description of changes

Since health check logs are not supported by NLB, but only by ALB, the logHealthCheckLogs method is added to the ApplicationLoadBalancer instead of the BaseLoadBalancer.

The needed BucketPolicy is described in the documentation only as follows.

{
  "Version":"2012-10-17",		 	 	 
  "Statement": [
    {
      "Effect": "Allow",
      "Principal": {
        "Service": "logdelivery.elasticloadbalancing.amazonaws.com"
      },
      "Action": "s3:PutObject",
      "Resource": "arn:aws:s3:::amzn-s3-demo-bucket/prefix/AWSLogs/123456789012/*"
    }
  ]
}

Description of how you validated changes

add unit tests and integ tests.

Checklist


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license

@aws-cdk-automation aws-cdk-automation requested a review from a team November 27, 2025 14:31
@github-actions github-actions bot added p2 valued-contributor [Pilot] contributed between 6-12 PRs to the CDK labels Nov 27, 2025
@ren-yamanashi ren-yamanashi changed the title feat(elasticloadbalancingv2): healthCheck logs for ALB feat(elasticloadbalancingv2): health check logs for ALB Nov 27, 2025
Copy link
Copy Markdown
Collaborator

@aws-cdk-automation aws-cdk-automation left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(This review is outdated)

bucket.addToResourcePolicy(
new PolicyStatement({
actions: ['s3:PutObject'],
principals: [this.resourcePolicyPrincipal()],
Copy link
Copy Markdown
Contributor Author

@ren-yamanashi ren-yamanashi Nov 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code is followed logConnectionLogs method.

see: https://github.com/aws/aws-cdk/blob/v2.230.0/packages/aws-cdk-lib/aws-elasticloadbalancingv2/lib/alb/application-load-balancer.ts#L368

The key point when use resourcePolicyPrincipal method, this public method (logHealthCheckLogs) needs specified region on the stack.


But, based on the documents I think we can choice don't use resourcePolicyPrincipal method like here code.
(see: https://docs.aws.amazon.com/elasticloadbalancing/latest/application/enable-health-check-logging.html)

principals: [new iam.ServicePrincipal('logdelivery.elasticloadbalancing.amazonaws.com')],

And when we choice it, not needs specified region on the stack.


Q. Which I choice? Use resourcePolicyPrincipal method? or not use?

Current situation is not same when implementation logConnectionLogs method, so I want advice for you.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@badmintoncryer

What could you think about this?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Personally, I’d prefer to implement it using the ServicePrincipal method, but I think it’s better to align with the existing implementation…

For now, let’s keep the current implementation as is, and could you discuss this with the maintainers again?​​​​​​​​​​​​​​​​

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay. I follow you.

@aws-cdk-automation aws-cdk-automation dismissed their stale review November 29, 2025 02:34

✅ Updated pull request passes all PRLinter validations. Dismissing previous PRLinter review.

@ren-yamanashi ren-yamanashi marked this pull request as ready for review November 29, 2025 05:15
@aws-cdk-automation aws-cdk-automation added the pr/needs-community-review This PR needs a review from a Trusted Community Member or Core Team Member. label Nov 29, 2025
Copy link
Copy Markdown
Contributor

@badmintoncryer badmintoncryer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your contribution! I've added some comments.

@aws-cdk-automation aws-cdk-automation removed pr/needs-community-review This PR needs a review from a Trusted Community Member or Core Team Member. labels Dec 2, 2025
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Dec 6, 2025

TestsPassed ☑️SkippedFailed ❌️
Security Guardian Results104 ran93 passed0 skipped11 failed
TestResult
Security Guardian Results
packages/@aws-cdk-testing/framework-integ/test/aws-elasticloadbalancingv2/test/integ.alb.log.enable-acl.js.snapshot/aws-cdk-elbv2-integ-enable-acl.template.json
ec2-no-open-security-groups.guard❌ failure
guardhooks-no-root-principals-except-kms-secrets.guard❌ failure
iam-no-wildcard-actions-inline.guard❌ failure
s3-encryption-enabled.guard❌ failure
packages/@aws-cdk-testing/framework-integ/test/aws-elasticloadbalancingv2/test/integ.alb.log.imported-bucket.js.snapshot/aws-cdk-alb-log-imported-bucket-integ.template.json
ec2-no-open-security-groups.guard❌ failure
guardhooks-no-root-principals-except-kms-secrets.guard❌ failure
s3-encryption-enabled.guard❌ failure
packages/@aws-cdk-testing/framework-integ/test/aws-elasticloadbalancingv2/test/integ.alb.log.js.snapshot/aws-cdk-elbv2-integ.template.json
ec2-no-open-security-groups.guard❌ failure
guardhooks-no-root-principals-except-kms-secrets.guard❌ failure
iam-no-wildcard-actions-inline.guard❌ failure
s3-encryption-enabled.guard❌ failure

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Dec 6, 2025

TestsPassed ☑️SkippedFailed ❌️
Security Guardian Results with resolved templates104 ran93 passed0 skipped11 failed
TestResult
Security Guardian Results with resolved templates
packages/@aws-cdk-testing/framework-integ/test/aws-elasticloadbalancingv2/test/integ.alb.log.enable-acl.js.snapshot/aws-cdk-elbv2-integ-enable-acl.template.json
ec2-no-open-security-groups.guard❌ failure
guardhooks-no-root-principals-except-kms-secrets.guard❌ failure
iam-no-wildcard-actions-inline.guard❌ failure
s3-encryption-enabled.guard❌ failure
packages/@aws-cdk-testing/framework-integ/test/aws-elasticloadbalancingv2/test/integ.alb.log.imported-bucket.js.snapshot/aws-cdk-alb-log-imported-bucket-integ.template.json
ec2-no-open-security-groups.guard❌ failure
guardhooks-no-root-principals-except-kms-secrets.guard❌ failure
s3-encryption-enabled.guard❌ failure
packages/@aws-cdk-testing/framework-integ/test/aws-elasticloadbalancingv2/test/integ.alb.log.js.snapshot/aws-cdk-elbv2-integ.template.json
ec2-no-open-security-groups.guard❌ failure
guardhooks-no-root-principals-except-kms-secrets.guard❌ failure
iam-no-wildcard-actions-inline.guard❌ failure
s3-encryption-enabled.guard❌ failure

Copy link
Copy Markdown
Contributor Author

@ren-yamanashi ren-yamanashi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@badmintoncryer

Thanks review! I fixed and reply your comments.

bucket.addToResourcePolicy(
new PolicyStatement({
actions: ['s3:PutObject'],
principals: [this.resourcePolicyPrincipal()],
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@badmintoncryer

What could you think about this?

Copy link
Copy Markdown
Contributor

@badmintoncryer badmintoncryer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! I've replied your comments.

@ren-yamanashi ren-yamanashi force-pushed the feat/alb-healthcheck-log branch from 062cbf1 to db0fccd Compare December 6, 2025 09:16
@ren-yamanashi
Copy link
Copy Markdown
Contributor Author

@badmintoncryer

I fixed! Please confirm

@badmintoncryer
Copy link
Copy Markdown
Contributor

Thank you for your great work!

@aws-cdk-automation aws-cdk-automation added the pr/needs-maintainer-review This PR needs a review from a Core Team Member label Dec 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

p2 pr/needs-maintainer-review This PR needs a review from a Core Team Member valued-contributor [Pilot] contributed between 6-12 PRs to the CDK

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants