aws / aws/aws-cdk

apigatewayv2: Custom domain configuration for WebSocket API

Open
#23,805 3 comments 3 reactions 0 assignees View on GitHub
@aws-cdk/aws-apigatewayv2 feature-request p2
Dominant language
TypeScript
Stars
12.9k
Forks
4.6k
Avg merge
2d 3h
Merged PRs (30d)
83

Description

### Describe the feature

HTTP API construct has [defaultDomainMapping](https://docs.aws.amazon.com/cdk/api/v2/docs/@aws-cdk_aws-apigatewayv2-alpha.HttpApi.html#defaultdomainmappingspan-classapi-icon-api-icon-experimental-titlethis-api-element-is-experimental-it-may-change-without-noticespan) property to set a custom domain for the API. We'd like to have an equivalent property for WebSocket API.

### Use Case

Set a custom domain for WebSocket API.

### Proposed Solution

We can add `defaultDomainMapping` option and create `CfnMapping` resouce like the below:

```ts
new CfnApiMapping(this, 'Mapping', {
apiId: api.apiId,
domainName: domainName.name,
stage: stage.stageName,
});
```

We may additionally need to create a `CfnStage` because currently it is not created inside `WebSocketApi`. In HTTP API we have [createDefaultStage](https://docs.aws.amazon.com/cdk/api/v2/docs/@aws-cdk_aws-apigatewayv2-alpha.HttpApi.html#createdefaultstagespan-classapi-icon-api-icon-experimental-titlethis-api-element-is-experimental-it-may-change-without-noticespan) option for this purpose.

### Other Information
Currently we can set a custom domain by the code like below:

```ts
const api = new WebSocketApi(this, 'Api', {
connectRouteOptions: {
authorizer,
integration: new WebSocketLambdaIntegration('ConnectIntegration', websocketHandler),
},
disconnectRouteOptions: {
integration: new WebSocketLambdaIntegration('DisconnectIntegration', websocketHandler),
},
defaultRouteOptions: {
integration: new WebSocketLambdaIntegration('DefaultIntegration', websocketHandler),
},
});

const stage = new WebSocketStage(this, `Stage`, {
webSocketApi: api,
stageName: this.defaultStageName,
autoDeploy: true,
});

const dnsRecordName = 'foo';
const customDomainName = `${dnsRecordName}.${props.hostedZone.zoneName}`;

const domainName = new DomainName(this, 'DomainName', {
domainName: customDomainName,
certificate: new Certificate(this, 'Certificate', {
domainName: customDomainName,
validation: CertificateValidation.fromDns(props.hostedZone),
}),
});

new CfnApiMapping(this, 'Mapping', {
apiId: api.apiId,
domainName: domainName.name,
stage: stage.stageName,
});

new ARecord(this, 'DnsRecord', {
recordName: dnsRecordName,
zone: props.hostedZone,
target: RecordTarget.fromAlias(
new ApiGatewayv2DomainProperties(domainName.regionalDomainName, domainName.regionalHostedZoneId),
),
});
```

### Acknowledgements

- [ ] I may be able to implement this feature request
- [ ] This feature might incur a breaking change

### CDK version used

2.61.1

### Environment details (OS name and version, etc.)

macOS

Contributor guide

Open the contributing guide

Research direction

Start by comparing HttpApi's defaultDomainMapping and createDefaultStage behavior with the WebSocketApi and WebSocketStage constructs. Review the proposed CfnApiMapping and possible CfnStage resources, then define completion as equivalent custom-domain mapping support for WebSocket APIs, including the required default stage behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
aws, typescript
Domain
api, cloud
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.