I am trying to create a ALB that forces users to u...
# aws
w
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?
Copy code
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
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:
Copy code
defaultActions: [
          {
            type: "forward",
            targetGroupArn: defaultTargetGroup.arn,
          },
        ],
Since the awsx code creates the default target group, maybe that's not needed for you?