Skip to content
New issue

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

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

Already on GitHub? # to your account

aws_ecs_patterns: default listener rule cannot be changed #30412

Closed
kcong7714 opened this issue Jun 1, 2024 · 3 comments
Closed

aws_ecs_patterns: default listener rule cannot be changed #30412

kcong7714 opened this issue Jun 1, 2024 · 3 comments
Labels
@aws-cdk/aws-ecs-patterns Related to ecs-patterns library bug This issue is a bug. needs-triage This issue or PR still needs to be triaged.

Comments

@kcong7714
Copy link

kcong7714 commented Jun 1, 2024

Describe the bug

I have a my_service instantiated from aws_ecs_patterns.ApplicationLoadBalancedFargateService().

I need a custom listener rule with a host header condition so that all other traffic will not be forwarded to the container. This can be added without issue, but the default listener rule does not change despite explicitly defining it, rendering the added custom rule pointless.

Expected Behavior

Default listener rule returns HTTP 503 Service Unavailable.

Current Behavior

Default listener rule is forwarding to target group my_service.target_group.

Reproduction Steps

my_service is instantiated from aws_ecs_patterns.ApplicationLoadBalancedFargateService().

A custom listener rule is added:

aws_elbv2.ApplicationListenerRule(
    self, 'my-rule',
    listener=my_service.listener,
    priority=1,
    conditions=[aws_elbv2.ListenerCondition.host_headers([MY_DOMAIN_NAME])],
    action=elbv2.ListenerAction.forward(target_groups=[my_service.target_group]),
)

An attempt to change the default listener rule:

my_service.listener.default_action = elbv2.ListenerAction.fixed_response(
    status_code=503,
    content_type='text/plain',
    message_body='Service Unavailable',
)

Possible Solution

No response

Additional Information/Context

cdk synth sample output:

  MyServiceLBPublicListener:
    Type: AWS::ElasticLoadBalancingV2::Listener
    Properties:
      DefaultActions:
        - TargetGroupArn:
            Ref: MyServiceLBPublicListenerECSGroup
          Type: forward

CDK CLI Version

2.144.0 (build 5fb15bc)

Framework Version

No response

Node.js Version

v20.11.1

OS

Ubuntu 22.04.4 LTS

Language

Python

Language Version

3.10.12

Other information

No response

@kcong7714 kcong7714 added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Jun 1, 2024
@github-actions github-actions bot added the @aws-cdk/aws-ecs-patterns Related to ecs-patterns library label Jun 1, 2024
@kcong7714
Copy link
Author

Sorry, my bad, it's not a bug. The right way to do this is:

my_service.listener.add_action(
    'DefaultAction',
    action=elbv2.ListenerAction.fixed_response(
        status_code=503,
        content_type='text/plain',
        message_body='Service Unavailable',
    )
)

When priority is not specified, it becomes the default action.

cdk synth output:

  MyServiceLBPublicListener:
    Type: AWS::ElasticLoadBalancingV2::Listener
    Properties:
      DefaultActions:
        - FixedResponseConfig:
            ContentType: text/plain
            MessageBody: Service Unavailable
            StatusCode: "503"
          Type: fixed-response

Copy link

github-actions bot commented Jun 1, 2024

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

@aws-cdk-automation
Copy link
Collaborator

Comments on closed issues and PRs are hard for our team to see. If you need help, please open a new issue that references this one.

@aws aws locked as resolved and limited conversation to collaborators Jul 25, 2024
# for free to subscribe to this conversation on GitHub. Already have an account? #.
Labels
@aws-cdk/aws-ecs-patterns Related to ecs-patterns library bug This issue is a bug. needs-triage This issue or PR still needs to be triaged.
Projects
None yet
Development

No branches or pull requests

2 participants