- Newest
- Most votes
- Most comments
You're on the right track, but there's a slight modification needed in your approach. When creating a Fargate service with AWS Cloud Map integration, you can indeed have both A and SRV records, but you need to specify this differently.
Instead of trying to set multiple DNS record types in the cloudMapOptions
, you should use the cloudMapOptions
to set up the initial configuration, and then modify the underlying CloudFormation resource to add the additional DNS record type.
Here's how you can modify your code to achieve this:
- In the
cloudMapOptions
, specify either A or SRV as the primary DNS record type. - After creating the Fargate service, access the underlying CloudFormation resource for the Cloud Map service.
- Override the
dnsConfig
property of this resource to include both A and SRV record types.
Your approach of modifying the CfnService
is correct. However, make sure you're not overwriting the existing configuration. Instead, you should extend it. Here's a slight modification to your code:
const CfnService = this.service.cloudMapService?.node.defaultChild as CfnService; CfnService.dnsConfig = { ...CfnService.dnsConfig, dnsRecords: [ { ttl: 60, type: 'A' }, { ttl: 60, type: 'SRV' } ], };
This way, you're preserving any other configurations that might be present in the dnsConfig
while adding both A and SRV record types.
Remember that when you specify settings for an SRV record and provide values for AWS_INSTANCE_IPV4 or AWS_INSTANCE_IPV6 in the RegisterInstance request, AWS Cloud Map automatically creates A and/or AAAA records with the same name as the service-hostname in the SRV record.
By following this approach, you should be able to create your Fargate service with both A and SRV DNS record types in Cloud Map.
Sources
AWS::ServiceDiscovery::Service DnsRecord - AWS CloudFormation
aws-alb-fargate - AWS Solutions Constructs
AWS::EKS::FargateProfile - AWS CloudFormation
When creating multiple DNS records and TYPES in cloudmap options have you tried allowing the cloud map options to replicate your original then just modify the record source.
Relevant content
- Accepted Answerasked 2 years ago
- Accepted Answerasked a year ago
- asked 2 years ago
- AWS OFFICIALUpdated 4 months ago
- AWS OFFICIALUpdated a year ago
- AWS OFFICIALUpdated 9 months ago
- AWS OFFICIALUpdated 2 years ago