https://pulumi.com logo
Title
w

white-rain-67342

03/28/2023, 11:23 PM
I am trying to create a ALB that forces users to use HTTPS when serving. I thought this would be how to solve it, but it doesn't seem like it is working. Has anyone had success in doing this?
const lb = new awsx.lb.ApplicationLoadBalancer(`${prefix}-lb`, {
  listeners: [
    {
      protocol: 'HTTPS',
      port: 443,
      sslPolicy: 'ELBSecurityPolicy-2016-08',
      certificateArn: sslCertificateArn,
    },
    {
      protocol: 'HTTP',
      port: 80,
      defaultActions: [
        {
          type: 'redirect',
          redirect: {
            port: '443',
            protocol: 'HTTPS',
            statusCode: 'HTTP_301',
          },
        },
      ],
    },
  ],
  defaultTargetGroup: {
    port: 80,
    protocol: 'HTTP',
  },
});
l

little-cartoon-10569

03/29/2023, 12:19 AM
You need a default action on the HTTPS listener too, don't you? I've never used the awsx load balancer, but with the aws API, you need to provide this sort of thing for the HTTPS default aciton:
defaultActions: [
          {
            type: "forward",
            targetGroupArn: defaultTargetGroup.arn,
          },
        ],
Since the awsx code creates the default target group, maybe that's not needed for you?