Skip to content

Commit 336b689

Browse files
committed
feat(apigatewayv2): add ipAddressType support to DomainName
1 parent 4e3df41 commit 336b689

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

packages/aws-cdk-lib/aws-apigatewayv2/lib/common/domain-name.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { Construct } from 'constructs';
2+
import { IpAddressType } from './api';
23
import { CfnDomainName, CfnDomainNameProps } from '.././index';
34
import { ICertificate } from '../../../aws-certificatemanager';
45
import { IBucket } from '../../../aws-s3';
@@ -120,6 +121,14 @@ export interface EndpointOptions {
120121
*/
121122
readonly securityPolicy?: SecurityPolicy;
122123

124+
/**
125+
* The IP address types that can invoke this domain name.
126+
* Use 'ipv4' to allow only IPv4 addresses to invoke the domain name, or use 'dualstack'
127+
* to allow both IPv4 and IPv6 addresses to invoke the domain name.
128+
* @default - undefined - AWS default is IPV4
129+
*/
130+
readonly ipAddressType?: IpAddressType;
131+
123132
/**
124133
* A public certificate issued by ACM to validate that you own a custom domain. This parameter is required
125134
* only when you configure mutual TLS authentication and you specify an ACM imported or private CA certificate
@@ -227,6 +236,7 @@ export class DomainName extends Resource implements IDomainName {
227236
endpointType: options.endpointType ? options.endpointType?.toString() : 'REGIONAL',
228237
ownershipVerificationCertificateArn: options.ownershipCertificate?.certificateArn,
229238
securityPolicy: options.securityPolicy?.toString(),
239+
ipAddressType: options.ipAddressType,
230240
};
231241

232242
this.validateEndpointType(domainNameConfig.endpointType);

packages/aws-cdk-lib/aws-apigatewayv2/test/http/domain-name.test.ts

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { Template } from '../../../assertions';
22
import { Certificate } from '../../../aws-certificatemanager';
33
import { Bucket } from '../../../aws-s3';
44
import { Stack } from '../../../core';
5-
import { DomainName, EndpointType, HttpApi, SecurityPolicy } from '../../lib';
5+
import { DomainName, EndpointType, HttpApi, SecurityPolicy, IpAddressType } from '../../lib';
66

77
const domainName = 'example.com';
88
const certArn = 'arn:aws:acm:us-east-1:111111111111:certificate';
@@ -270,6 +270,30 @@ describe('DomainName', () => {
270270
});
271271
});
272272

273+
test('domain name with IP address type set to DUAL_STACK', () => {
274+
// GIVEN
275+
const stack = new Stack();
276+
277+
// WHEN
278+
new DomainName(stack, 'DomainName', {
279+
domainName,
280+
certificate: Certificate.fromCertificateArn(stack, 'cert', certArn),
281+
ipAddressType: IpAddressType.DUAL_STACK,
282+
});
283+
284+
// THEN
285+
Template.fromStack(stack).hasResourceProperties('AWS::ApiGatewayV2::DomainName', {
286+
DomainName: 'example.com',
287+
DomainNameConfigurations: [
288+
{
289+
CertificateArn: 'arn:aws:acm:us-east-1:111111111111:certificate',
290+
EndpointType: 'REGIONAL',
291+
IpAddressType: 'dualstack',
292+
},
293+
],
294+
});
295+
});
296+
273297
test('throws when ownerhsip cert is used for non-mtls domain', () => {
274298
// GIVEN
275299
const stack = new Stack();

0 commit comments

Comments
 (0)