hello :wave: quick question - we use the crosswal...
# typescript
m
hello 👋 quick question - we use the crosswalk apit to set up a ALB with a target group, listner and fargate service as
Copy code
const lbx = new awsx.lb.ApplicationLoadBalancer(`api-lb-${stack}`, {
  vpc: vpc,
  subnets: vpc.publicSubnetIds,
  securityGroups: [lbSecurityGroup],
});

const apiTgx = new awsx.lb.ApplicationTargetGroup(`api-tg-${stack}`, {
  vpc: vpc,
  port: 80,
  protocol: 'HTTP',
  healthCheck: {
    path: '/healthcheck',
  },
});

const listener = lbx.createListener(`api-web-${stack}`, {
  protocol: 'HTTPS',
  targetGroup: apiTgx,
  vpc: vpc,
  certificateArn,
});
I'd like to add an additional TG and fargate cluster and do path based routing as described here https://docs.aws.amazon.com/elasticloadbalancing/latest/application/tutorial-application-load-balancer-cli.html#path-based-routing-aws-cli Can someone point me to an example / docs on how to do this please? Much appreciated 🙏
l
Creating an additional TG is no different to the one you've already created. Path-based routing is achieved by adding LIstenerRules to your listener with pathPattern conditions. The classes that make up ListenerRule are defined in the AWS classic API docs: https://www.pulumi.com/registry/packages/aws/api-docs/alb/listenerrule/ The first example on the page covers path patterns.
m
thank you
this is what I ended up doing
Copy code
// forward all analytics routes to the analytics target group
new aws.lb.ListenerRule('analytics', {
  listenerArn: listener.listener.arn,
  priority: 100,
  actions: [{
    type: 'forward',
    targetGroupArn: analyticsTgx.targetGroup.arn,
  }],
  conditions: [
    {
      pathPattern: {
        values: ['/analytics/*'],
      },
    },
  ],
});
I am far from an expert, shouldn't the crosswalk api support
ListenerRule
. it is possible it does and I am asking the wrong question. The right question being is there a better way to do this?
l
It does. The crosswalk "API" is just a wrapper around the aws API. It supports everything that the aws API does. That's what you've done here.
There isn't a need for the awsx maintainers to add
export type ListenerRule = <http://aws.lb|aws.lb>.ListenerRule;
. It doesn't add anything of value to users.
m
Thank you. I was thinking - psuedocode
Copy code
const listener = lbx.createListener(`api-web-${stack}`, {
  protocol: 'HTTPS',
  targetGroup: apiTgx,
  vpc: vpc,
  certificateArn,
  rules : {
    actions: [{
      type: 'forward',
    }],
    conditions: [{
      pathPattern: {
        values: ['/analytics/*'],
      },
    }],
  },
});
might be completely off on this - i'm no expert on typescript either but the targetgroup and listener arn access just bothers me
l
I don't understand. Are you having trouble passing a value to targetGroup?
Is it that you're looking for the nested-json approach to creating entities in awsx? That could be an option. That's very difficult to maintain, unfortunately. I generally recommend avoiding Crosswalk in any cases where you're likely to want to change the resources in the future, or where you're likely to want to do anything that doesn't fit perfectly with the standard use-case.
Changes to the base resources managed by AWS native and classic providers are much more predictable than changes to the smart extensions provided by AWSX.
m
Appreciate you engaging and helping me learn.
I don't understand. Are you having trouble passing a value to targetGroup?
no trouble
Is it that you're looking for the nested-json approach to creating entities in awsx?
yes. Looks cleaner to my eyes.
I generally recommend avoiding Crosswalk in any cases where you're likely to want to change the resources in the future
We did everything with crosswalk - small team when we start (3 of us), best practices applies. Came a long way with it, but I do see your point. The flip side is the lift for learning AWS specific
Changes to the base resources managed by AWS native and classic providers are much more predictable than changes to the smart extensions provided by AWSX.
👍 Thank you for your time. Appreciate it.