Skip to main content

AwsS3StaticWebsiteServiceModule

AwsS3StaticWebsiteServiceModule creates a public S3 bucket served as a website over plain HTTP and uploads a local directory into it (directoryPath); a site on HTTPS from a private bucket is AwsS3StorageServiceModule behind AwsCloudFrontServiceModule.

The bucket is public and served over plain HTTP on its S3 website endpoint. It lives in a region created by AwsServerlessRegionModule. To serve files through CloudFront instead, use AwsS3StorageServiceModule, whose bucket is closed and fronted by AwsCloudFrontServiceModule.

@cost

S3 bills what the bucket holds and serves: storage per GB-month (about $0.023 for S3 Standard in us-east-1), each request a visitor's browser makes (about $0.0004 per 1,000), and data sent to the internet beyond the 100 GB a month AWS gives free. An idle site costs only its storage.

@downtime

Changing a file uploads it again in place, and visitors see the new file once it lands. A replacement deletes the bucket before creating it again, so the site answers nothing until the new bucket holds its files.

@example

TypeScript

import { type Region, stub } from '@quadnix/octo';
import {
AwsS3StaticWebsiteServiceModule
} from '@quadnix/octo-aws-cdk/modules/service/aws-s3-static-website-service';

octo.loadModule(AwsS3StaticWebsiteServiceModule, 'my-website-module', {
bucketName: 'my-static-website',
directoryPath: 'website',
filter: (filePath) => !filePath.includes('.DS_Store'),
region: stub<Region>('${{my-region-module.model.region}}'),
});
@group

Modules/Service/AwsS3StaticWebsiteService

@limit

The website endpoint serves plain HTTP only, never HTTPS. For HTTPS or a domain of your own, serve the files from AwsS3StorageServiceModule through AwsCloudFrontServiceModule instead.

@limit

A bucket name is global across every AWS account: a name anyone already holds is refused. It is 3 to 63 lowercase letters, numbers, dots and hyphens.

@limit

The index document is index.html and the error document error.html; neither name can be changed.

@losesData

Nothing octo cannot put back: every file in the bucket is uploaded from directoryPath, and a new bucket is filled from it again. A file put into the bucket any other way is lost, and blocks the bucket's deletion until removed by hand.

@replaces

Changing bucketName or region replaces the bucket, because S3 can neither rename nor move one.

@see

Hierarchy

Index

Constructors

constructor

  • Parameters

    • moduleId: string

      The ID this module is loaded under.

    Returns AwsS3StaticWebsiteServiceModule

Properties

readonlyinheritedmoduleId

moduleId: string

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

MODULE_PACKAGE: string

The package the module is registered under, set by Module.

staticreadonlyinheritedMODULE_SCHEMA

MODULE_SCHEMA: any

The schema of the module's inputs, set by Module.

Methods

onInit

  • Creates the bucket service, and registers the local directory whose files it serves.


    Parameters

    Returns Promise<AwsS3StaticWebsiteService>

inheritedregisterHooks

  • registerHooks(): { postCommitHooks?: PostHookSignature[]; postModelActionHooks?: PostHookSignature[]; postResourceActionHooks?: PostHookSignature[]; preCommitHooks?: PreHookSignature[]; preModelActionHooks?: PreHookSignature[]; preResourceActionHooks?: PreHookSignature[] }
  • To hook custom behavior into Octo's lifecycle for the duration of this module. Override it to return the callbacks you want run.

    @see

    Techniques for Hooks.


    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 and region this bucket is created in.


    Parameters

    Returns Promise<{ awsAccountId: string; awsRegionId: string }>