I’m trying to move over from Cloudformation to CDK and have been struggling here.
I’m trying to create a ELB listner and add a default action to it. Port 80 Listner with default action to redirect to 443. It seems like this should be easy but I can’t see any way to hook in to the default actions for a listner. Some sources say default_action is a prop of the Listner class but I can’t seem to find how to use it on instantiation. Others say to use .add_action as in this example:
listener80.add_action('DefaultAction',
elbv2.ListenerAction.fixed_response(200,
content_type=elbv2.ContentType.TEXT_PLAIN,
message_body="OK"
))
However i keep getting this error:
AttributeError: module 'aws_cdk.aws_elasticloadbalancingv2' has no attribute 'ContentType'
Even though that example is straight out of AWS docs…
2
Answers
For anyone else struggling like i was here is the way to declare it on instantiation:
or to add it with add action:
I had the same problem, and until now I didn’t find any information about the new position of the enum ContentType in cdk v2, alternatively, according to the definition of the interface FixedResponseOptions :
I just put a string value instead, for example ‘text/plain’