Defined in: src/constructs/api-gateway-cloudfront-distribution/api-cloudfront-distribution.ts:82
Props for an API Gateway–fronted CloudFront distribution.
Remarks
Wraps a cloudFront.Distribution that fronts an apigw.RestApi,
creates an alias for <apiSubDomain>.<hostedZone>, optionally associates a
Lambda@Edge version, and (optionally) wires the distribution into a provided
monitoring facade.
Important constraints
- domainCertificate: When used with CloudFront, the ACM certificate
must be in
us-east-1. - edgeFunction: Lambda@Edge versions must be in
us-east-1. - If monitoringFacade is supplied, the construct calls
monitoringFacade.monitorCloudFrontDistribution({ distribution })after creating the distribution.
Example
const zone = route53.HostedZone.fromHostedZoneAttributes(this, 'Zone', {
hostedZoneId: 'Z1234567890',
zoneName: 'mydomain.com',
});
const cert = acm.Certificate.fromCertificateArn(this, 'Cert',
'arn:aws:acm:us-east-1:123456789012:certificate/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'
);
const api = new apigw.RestApi(this, 'Api', {
deployOptions: { stageName: 'dev' },
});
// (Optional) monitoring facade you manage elsewhere
const facade = new monitoring.MonitoringFacade(this, 'Monitoring', { /\* ... */ });
new ApiCloudFrontDistribution(this, 'Dist', {
stageName: 'dev',
domainHostedZone: zone,
apiSubDomain: 'api',
domainCertificate: cert,
api,
priceClass: cloudFront.PriceClass.PRICE_CLASS_100,
enabled: true,
comment: 'dev api distribution',
edgeFunction: lambda.Version.fromVersionArn(this, 'EdgeVer', 'arn:aws:lambda:us-east-1:acct:function:name:1'),
monitoringFacade: facade,
// Optional alarms — these examples use the official types from
// the cdklabs/cdk-monitoring-constructs package.
alarmConfiguration: {
// Map of disambiguator (e.g. 'Critical', 'Warning') to ErrorRateThreshold
// See constructs.dev docs for ErrorRateThreshold.
addError4xxRate: {
'4xxErrorRate': {
maxErrorRate: 1,
evaluationPeriods: 1,
datapointsToAlarm: 1,
},
},
},
});
See
cloudFront.DistributionProps
Extends
Pick<cloudFront.DistributionProps,"comment"|"priceClass"|"enabled">
Properties
alarmConfiguration?
optionalalarmConfiguration:CloudFrontDistributionMonitoringOptions
Defined in: src/constructs/api-gateway-cloudfront-distribution/api-cloudfront-distribution.ts:171
Optional configuration for alarms and thresholds to apply to the monitored CloudFront distribution.
Remarks
Only applicable if monitoringFacade is also provided.
Default Value
No alarms or thresholds are configured.
api
api:
RestApi
Defined in: src/constructs/api-gateway-cloudfront-distribution/api-cloudfront-distribution.ts:117
The API Gateway REST API that the distribution will front.
apiSubDomain
apiSubDomain:
string
Defined in: src/constructs/api-gateway-cloudfront-distribution/api-cloudfront-distribution.ts:106
The subdomain to use for the API.
The final DNS name will typically be <apiSubDomain>.<domainHostedZone.zoneName>.
Example
'api'
comment
comment:
string
Defined in: src/constructs/api-gateway-cloudfront-distribution/api-cloudfront-distribution.ts:138
A human-readable comment for the distribution.
Example
'dev api distribution'
Overrides
Pick.comment
domainCertificate
domainCertificate:
ICertificate
Defined in: src/constructs/api-gateway-cloudfront-distribution/api-cloudfront-distribution.ts:112
The ACM certificate for the CloudFront alias. Must be in us-east-1.
(CloudFront requires certificates in the N. Virginia region.)
domainHostedZone
domainHostedZone:
IHostedZone
Defined in: src/constructs/api-gateway-cloudfront-distribution/api-cloudfront-distribution.ts:98
The public Route 53 hosted zone that owns the apex domain (e.g., mydomain.com).
Used to create the DNS record for the API subdomain.
edgeFunction?
optionaledgeFunction:IVersion
Defined in: src/constructs/api-gateway-cloudfront-distribution/api-cloudfront-distribution.ts:147
Optional Lambda@Edge function version to associate with the distribution
(e.g., at VIEWER_REQUEST). The version must be in us-east-1.
If omitted, no edge function is attached.
See
lambda.Version
enabled
enabled:
boolean
Defined in: src/constructs/api-gateway-cloudfront-distribution/api-cloudfront-distribution.ts:131
Whether the distribution is enabled.
Default Value
true
Overrides
Pick.enabled
monitoringFacade?
optionalmonitoringFacade:MonitoringFacade
Defined in: src/constructs/api-gateway-cloudfront-distribution/api-cloudfront-distribution.ts:160
Optional monitoring facade used to register metrics/alarms/dashboards for the created CloudFront distribution.
Remarks
When provided, the construct calls
monitoringFacade.monitorCloudFrontDistribution({ distribution })
after creating the distribution.
Default Value
undefined
priceClass
priceClass:
PriceClass
Defined in: src/constructs/api-gateway-cloudfront-distribution/api-cloudfront-distribution.ts:124
The CloudFront price class.
Default Value
cloudFront.PriceClass.PRICE_CLASS_100 (recommended)
Overrides
Pick.priceClass
stageName
stageName:
string
Defined in: src/constructs/api-gateway-cloudfront-distribution/api-cloudfront-distribution.ts:92
The API Gateway stage name that this distribution targets (e.g., dev, prod).
Example
'dev'