AwsCloudFrontServiceModule
Hierarchy
- AModule<AwsCloudFrontServiceModuleSchema, AwsCloudFrontService>
- AwsCloudFrontServiceModule
Index
Constructors
constructor
Parameters
moduleId: string
The ID this module is loaded under.
Returns AwsCloudFrontServiceModule
Properties
readonlyinheritedmoduleId
The ID this module was loaded under. It scopes everything the module produces, so the same module class can be loaded more than once.
staticreadonlyinheritedMODULE_PACKAGE
The package the module is registered under, set by Module.
staticreadonlyinheritedMODULE_SCHEMA
The schema of the module's inputs, set by Module.
Methods
onInit
Validates the origins and routes, creates the distribution's service under the account, and an overlay for each origin's source.
Parameters
inputs: AwsCloudFrontServiceModuleSchema
Returns Promise<[AwsCloudFrontService, ...(AwsCloudFrontAlbOriginOverlay | AwsCloudFrontLambdaOriginOverlay | AwsCloudFrontS3OriginOverlay)[]]>
inheritedregisterHooks
To hook custom behavior into Octo's lifecycle for the duration of this module. Override it to return the callbacks you want run.
Returns { postCommitHooks?: PostHookSignature[]; postModelActionHooks?: PostHookSignature[]; postResourceActionHooks?: PostHookSignature[]; preCommitHooks?: PreHookSignature[]; preModelActionHooks?: PreHookSignature[]; preResourceActionHooks?: PreHookSignature[] }
optionalpostCommitHooks?: PostHookSignature[]
optionalpostModelActionHooks?: PostHookSignature[]
optionalpostResourceActionHooks?: PostHookSignature[]
optionalpreCommitHooks?: PreHookSignature[]
optionalpreModelActionHooks?: PreHookSignature[]
optionalpreResourceActionHooks?: PreHookSignature[]
registerMetadata
Resolves the account this distribution is created in.
Parameters
inputs: AwsCloudFrontServiceModuleSchema
Returns Promise<{ awsAccountId: string; indexFunctions: { code: string; name: string; originId: string }[] }>
AwsCloudFrontServiceModulecreates one CloudFront distribution serving buckets and Lambda functions over HTTPS from the edge, with itsorigins,routes, cache and header policies,functions, and your own domain (aliases,certificateArn).It is given its origins, the models it serves, and its routes, the paths that pick an origin, the way CloudFront itself is configured. For each source it creates an overlay, and grants the distribution access to it through an origin access control: for a bucket from
AwsS3StorageServiceModule, a statement in the bucket's policy; for a Lambda function fromAwsLambdaExecutionModule, a permission of its own admitting this distribution to call the function through its URL, even a function of an app this one extends. An ALB fromAwsEcsAlbServiceModuleis reached over HTTP through its DNS name, and is granted nothing: it still answers anyone who calls it directly. It sits under the account. To drop the edges' copies of a source's files when they change, addAwsCloudFrontInvalidationServiceModule.It creates a CloudFront Function from each file in
functions, which a route runs by name.A route whose origin is a Lambda function or an ALB defaults to every method, no caching, and every viewer header but
Host. Behind a Lambda function, a client sending a body - aPOSTor aPUT- must also send its SHA-256 in thex-amz-content-sha256header, because CloudFront signs the request it forwards to the function. CloudFront waits 60 seconds for the function, so a function with a longer timeout is rejected.CloudFront bills data delivered to viewers (about $0.085 per GB in North America and Europe) and requests (about $0.01 per 10,000 HTTPS requests), after an always-free 1 TB and 10 million requests a month. A CloudFront Function bills about $0.10 per million invocations after 2 million free.
priceClassPriceClass_100serves only from North America and Europe, the cheapest edges. Transfer from an S3 origin to CloudFront is free.None: a change updates the distribution in place, and every edge serves the old configuration until the new one reaches it, which takes a few minutes.
TypeScript
Modules/Service/AwsCloudFrontService
CloudFront waits at most 60 seconds for an origin to answer, so a Lambda function with a longer timeout is rejected. A body sent to a Lambda function must carry its SHA-256 in
x-amz-content-sha256.certificateArnmust name an ACM certificate inus-east-1, whatever region the origins are in, and it is required withaliases.A CloudFront Function's code is at most 10 KB, and it can neither reach the network nor read a request body.
No WAF web ACL can be attached, so the distribution cannot block requests by rule, address or rate.
The distribution serves every country: no geographic restriction can be set.
No origin has a failover origin: when an origin fails, the request fails.
An S3 origin is a bucket of this app: a bucket an extended or stored app holds cannot be served.
Custom error responses apply to every route of the distribution, so a route cannot have an error page of its own.
The distribution writes no access logs.
With
certificateArn, viewers connect over SNI only, with TLS 1.2 as the oldest protocol; a client without SNI cannot connect.Nothing: a distribution holds no data, only cached copies of its origins.
Changing
accountreplaces the distribution and its address. Every other input changes it in place.Servicemodel.