Can anybody help me with the following scenario? :...
# general
a
Can anybody help me with the following scenario? 🙂 I’m struggling with defining a custom
ListenerRule
for a Load Balancer Listener on AWS. This is my current definition:
Copy code
new aws.elasticloadbalancingv2.ListenerRule(`block-certain-routes`, {
  listenerArn: listener.arn,
  conditions: [{
    field: "path-pattern",
    values: ["/test1", "/test1"]
  }],
  actions: [{
    type: "fixed-response",
    fixedResponse: {
      statusCode: 404,
      contentType: "text/plain",
      messageBody: "Not Found"
    }
  }]
  }
});
I want to send a
404
whenever somebody requests certain paths. Unfortunately, the TS compiler complains with
property apply is missing in type
on the
conditions
and
actions
attributes. Would be more than great if anybody can point me in the correct direction when it comes to defining a
ListenerRule
🙂
w
Looks like there are two changes needed - both subtle. •
values
is actually a single string that represents a path pattern of values that will match the condition (e.g. it can use
*
) •
statusCode
is a string, not a number With those changes - the below looks like it should work:
Copy code
new aws.elasticloadbalancingv2.ListenerRule(`block-certain-routes`, {
    listenerArn: listener.arn,
    conditions: [{
        field: "path-pattern",
        values: "/test1",
    }],
    actions: [{
        type: "fixed-response",
        fixedResponse: {
            statusCode: "404",
            contentType: "text/plain",
            messageBody: "Not Found"
        }
    }]
});
The TypeScript errors are not being as helpful as they could be here unfortunately.
a
Yeah, it works! Thanks @white-balloon-205 - awesome! 🙂 Adding multiple conditions works, but you have to make sure that you don’t use e.g.
path-pattern
twice (with different values). In this case you have to create to dedicated listener rules then.
Also: @white-balloon-205 You’re doing an amazing job at Pulumi. This is actual the first time where “Infrastructure as Code” is “Infrastructure as Code”. Thanks for the hard work!