-
Notifications
You must be signed in to change notification settings - Fork 4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(apigatewayv2): http api - custom domain & stage mapping (#8027)
- [x] implementation - [x] README - [x] integ test - [x] 100% unit test coverage ### Commit Message feat(apigatewayv2): http api - custom domain & stage mapping (#8027) - Add new `DomainName` and `HttpApiMapping` construct classes and `addDomainName()` method for `HttpApi` resource. - Add `defaultDomainMapping` construct property for `HttpApi` - Add `domainMapping` attribute for `addStage` Closes #7847 ### End Commit Message ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
- Loading branch information
Showing
18 changed files
with
1,089 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ | |
*.snk | ||
!*.d.ts | ||
!*.js | ||
**/cdk.out | ||
|
||
# Coverage | ||
coverage | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
packages/@aws-cdk/aws-apigatewayv2/lib/common/api-mapping.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { IResource } from '@aws-cdk/core'; | ||
|
||
/** | ||
* Represents an ApiGatewayV2 ApiMapping resource | ||
* @see https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-apigatewayv2-apimapping.html | ||
*/ | ||
export interface IApiMapping extends IResource { | ||
/** | ||
* ID of the api mapping | ||
* @attribute | ||
*/ | ||
readonly apiMappingId: string; | ||
} |
117 changes: 117 additions & 0 deletions
117
packages/@aws-cdk/aws-apigatewayv2/lib/common/domain-name.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
import { ICertificate } from '@aws-cdk/aws-certificatemanager'; | ||
import { Construct, IResource, Resource, Token } from '@aws-cdk/core'; | ||
import { CfnDomainName, CfnDomainNameProps } from '../apigatewayv2.generated'; | ||
|
||
/** | ||
* Represents an APIGatewayV2 DomainName | ||
* @see https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-apigatewayv2-domainname.html | ||
*/ | ||
export interface IDomainName extends IResource { | ||
/** | ||
* The custom domain name | ||
* | ||
* @attribute | ||
* | ||
*/ | ||
readonly domainName: string; | ||
|
||
/** | ||
* The domain name associated with the regional endpoint for this custom domain name. | ||
* | ||
* @attribute | ||
*/ | ||
readonly regionalDomainName: string; | ||
|
||
/** | ||
* The region-specific Amazon Route 53 Hosted Zone ID of the regional endpoint. | ||
* | ||
* @attribute | ||
*/ | ||
readonly regionalHostedZoneId: string; | ||
} | ||
|
||
/** | ||
* custom domain name attributes | ||
*/ | ||
export interface DomainNameAttributes { | ||
/** | ||
* domain name string | ||
*/ | ||
readonly domainName: string; | ||
|
||
/** | ||
* The domain name associated with the regional endpoint for this custom domain name. | ||
*/ | ||
readonly regionalDomainName: string; | ||
|
||
/** | ||
* The region-specific Amazon Route 53 Hosted Zone ID of the regional endpoint. | ||
*/ | ||
readonly regionalHostedZoneId: string; | ||
} | ||
|
||
/** | ||
* properties used for creating the DomainName | ||
*/ | ||
export interface DomainNameProps { | ||
/** | ||
* The custom domain name | ||
*/ | ||
readonly domainName: string; | ||
/** | ||
* The ACM certificate for this domain name | ||
*/ | ||
readonly certificate: ICertificate; | ||
} | ||
|
||
/** | ||
* Custom domain resource for the API | ||
*/ | ||
export class DomainName extends Resource implements IDomainName { | ||
/** | ||
* import from attributes | ||
*/ | ||
public static fromDomainNameAttributes(scope: Construct, id: string, attrs: DomainNameAttributes): IDomainName { | ||
class Import extends Resource implements IDomainName { | ||
public readonly regionalDomainName = attrs.regionalDomainName; | ||
public readonly regionalHostedZoneId = attrs.regionalHostedZoneId; | ||
public readonly domainName = attrs.domainName; | ||
} | ||
return new Import(scope, id); | ||
} | ||
|
||
/** | ||
* The custom domain name for your API in Amazon API Gateway. | ||
* | ||
* @attribute | ||
*/ | ||
public readonly domainName: string; | ||
|
||
/** | ||
* The domain name associated with the regional endpoint for this custom domain name. | ||
*/ | ||
public readonly regionalDomainName: string; | ||
|
||
/** | ||
* The region-specific Amazon Route 53 Hosted Zone ID of the regional endpoint. | ||
*/ | ||
public readonly regionalHostedZoneId: string; | ||
|
||
constructor(scope: Construct, id: string, props: DomainNameProps) { | ||
super(scope, id); | ||
|
||
const domainNameProps: CfnDomainNameProps = { | ||
domainName: props.domainName, | ||
domainNameConfigurations: [ | ||
{ | ||
certificateArn: props.certificate.certificateArn, | ||
endpointType: 'REGIONAL', | ||
}, | ||
], | ||
}; | ||
const resource = new CfnDomainName(this, 'Resource', domainNameProps); | ||
this.domainName = props.domainName ?? resource.ref; | ||
this.regionalDomainName = Token.asString(resource.getAtt('RegionalDomainName')); | ||
this.regionalHostedZoneId = Token.asString(resource.getAtt('RegionalHostedZoneId')); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
export * from './integration'; | ||
export * from './route'; | ||
export * from './stage'; | ||
export * from './stage'; | ||
export * from './domain-name'; | ||
export * from './api-mapping'; |
78 changes: 78 additions & 0 deletions
78
packages/@aws-cdk/aws-apigatewayv2/lib/http/api-mapping.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import { Construct, Resource } from '@aws-cdk/core'; | ||
import { CfnApiMapping, CfnApiMappingProps } from '../apigatewayv2.generated'; | ||
import { IApiMapping, IDomainName } from '../common'; | ||
import { IHttpApi } from '../http/api'; | ||
import { IHttpStage } from './stage'; | ||
|
||
/** | ||
* Properties used to create the HttpApiMapping resource | ||
*/ | ||
export interface HttpApiMappingProps { | ||
/** | ||
* Api mapping key. The path where this stage should be mapped to on the domain | ||
* @default '/' | ||
*/ | ||
readonly apiMappingKey?: string; | ||
|
||
/** | ||
* The HttpApi to which this mapping is applied | ||
*/ | ||
readonly api: IHttpApi; | ||
|
||
/** | ||
* custom domain name of the mapping target | ||
*/ | ||
readonly domainName: IDomainName; | ||
|
||
/** | ||
* stage for the HttpApiMapping resource | ||
* | ||
* @default - the $default stage | ||
*/ | ||
readonly stage?: IHttpStage; | ||
} | ||
|
||
/** | ||
* The attributes used to import existing HttpApiMapping | ||
*/ | ||
export interface HttpApiMappingAttributes { | ||
/** | ||
* The API mapping ID | ||
*/ | ||
readonly apiMappingId: string; | ||
} | ||
|
||
/** | ||
* Create a new API mapping for API Gateway HTTP API endpoint. | ||
* @resource AWS::ApiGatewayV2::ApiMapping | ||
*/ | ||
export class HttpApiMapping extends Resource implements IApiMapping { | ||
/** | ||
* import from API ID | ||
*/ | ||
public static fromHttpApiMappingAttributes(scope: Construct, id: string, attrs: HttpApiMappingAttributes): IApiMapping { | ||
class Import extends Resource implements IApiMapping { | ||
public readonly apiMappingId = attrs.apiMappingId; | ||
} | ||
return new Import(scope, id); | ||
} | ||
/** | ||
* ID of the API Mapping | ||
*/ | ||
public readonly apiMappingId: string; | ||
|
||
constructor(scope: Construct, id: string, props: HttpApiMappingProps) { | ||
super(scope, id); | ||
|
||
const apiMappingProps: CfnApiMappingProps = { | ||
apiId: props.api.httpApiId, | ||
domainName: props.domainName.domainName, | ||
stage: props.stage?.stageName ?? '$default', | ||
apiMappingKey: props.apiMappingKey, | ||
}; | ||
|
||
const resource = new CfnApiMapping(this, 'Resource', apiMappingProps); | ||
this.apiMappingId = resource.ref; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.