John
John

Reputation: 11831

AWS CDK: how to create Route53 A Record pointing at Elastic IP?

I am creating a CfnUserPoolDomain and am getting an error "Custom domain is not a valid subdomain: Was not able to resolve the root domain, please ensure an A record exists for the root domain."

I need to have an A record that points to the subdomain, as documented here.

I do not yet have a resource that I want the A record to point to, so I want to create an elastic IP that does nothing (not pointing at anything) and create an A record that points at that EIP.

    CfnEIP eip = CfnEIP.Builder.create(this, "apex-a-record-target")
            .domain("vpc")
            .build();

    ARecord apexRecord = ARecord.Builder.create(this, "apex-a-record")
            .zone(hostedZone)
            .target(RecordTarget.fromIpAddresses( ** what goes here ? **   ))
            .build();

I don't see how to get the IPv4 address from the EIP? How do I get the IP address or otherwise associate the A record with the EIP?

Upvotes: 1

Views: 2024

Answers (1)

Mitchell Valine
Mitchell Valine

Reputation: 254

Some cloudformation resources don't return any attributes, but you can 'extract' their value using the Cfn Ref functionality. For L1 CDK constructs, you can do this with .ref.

I think you can do the following:

    ARecord apexRecord = ARecord.Builder.create(this, "apex-a-record")
            .zone(hostedZone)
            .target(RecordTarget.fromIpAddresses(eip.ref))
            .build();

Upvotes: 2

Related Questions