Skip to content

AssetDeployment

Source: src/AWS/Website/AssetDeployment.ts

Upload a local directory into S3 with website-friendly defaults.

AssetDeployment is a helper resource for website hosting. It uploads all files in a directory, infers content types, applies cache-control defaults (HTML is never cached; everything else is immutable), and can optionally purge stale files under a prefix. StaticSite and SsrSite use it internally — reach for it directly when you manage the bucket and CDN yourself.

Upload A Build Directory

const bucket = yield* AWS.S3.Bucket("SiteBucket", {});
const files = yield* AssetDeployment("WebsiteFiles", {
bucket,
sourcePath: "./dist",
prefix: "_assets",
});

Purge Stale Files And Override Caching

const files = yield* AssetDeployment("WebsiteFiles", {
bucket,
sourcePath: "./dist",
purge: true,
fileOptions: [
{
files: "**\/*.json",
cacheControl: "max-age=300,public",
},
],
});
const files = yield* AssetDeployment("WebsiteFiles", {
bucket,
sourcePath: "./dist",
});
// `version` only changes when file contents change, so the
// invalidation re-runs exactly when a new deploy ships new bytes.
yield* AWS.CloudFront.Invalidation("Invalidation", {
distributionId: distribution.distributionId,
version: files.version,
paths: ["/*"],
});