import { Construct } from 'constructs'; import { RemovalPolicy } from 'aws-cdk-lib'; import { IRestApi } from 'aws-cdk-lib/aws-apigateway'; import { ICertificate } from 'aws-cdk-lib/aws-certificatemanager'; import { IHostedZone } from 'aws-cdk-lib/aws-route53'; import { BucketDeploymentProps } from 'aws-cdk-lib/aws-s3-deployment'; import { CloudFrontWebDistribution, CloudFrontWebDistributionProps } from 'aws-cdk-lib/aws-cloudfront'; import { IBucket, BucketProps } from 'aws-cdk-lib/aws-s3'; import { Mutable } from '../../../lib/Mutable'; import { buildUrls } from '../../../lib/buildUrls'; export interface CDNConstructProps { removalPolicy?: RemovalPolicy; /** * The prefix to use for the resources. Will prefix all resource names with this value. For more info, see * [Naming](https://full-stack-pattern.matthewkeil.com/docs/naming) */ prefix?: string; /** * Option to not use fixed logicalId's for the RestApi resource. For more * info, see [Naming](https://full-stack-pattern.matthewkeil.com/docs/naming) */ dontOverrideLogicalId?: boolean; /** * The absolute paths for the code that will be uploaded and * hosted via S3/CloudFront. */ codePaths: string[]; codeDeploymentProps?: Omit; /** * This is for accounts/clients that have high security and restrict making * buckets. Also helpful during development and forget to delete a bucket. * Will not throw and error when deploying. Sets up a BucketPolicy for * access to the existing bucket. When set to `true`, you must also provide * the `bucketName` */ useExistingBucket?: boolean; /** * This is for accounts/clients that have high security and restrict making * bucket policies. Has no effect unless `props.useExistingBucket = true` */ noBucketPolicy?: boolean; /** * Set the bucketName */ bucketName?: string; /** * Allows hosting at a custom, non-cloudfront, url. The root domain * of the website that is being hosted without the sub-domain. ie. `example.com`. * If provided, must also provide a value for `stage`, `hostedZone` and `certificate`. */ domain?: string; /** * The stage of the website that is being hosted. ex. Using `qa` * as the stage will host the site at the sub-domain `qa.example.com`. When * the stage is prod a naked domain will be used and the `buildWwwSubdomain` * property will be checked. If `true` the `www` sub-domain will also be built. * ex. `www.example.com` and `example.com` will both be valid. */ stage?: string; /** * will build www.{rootDomain} alias on `prod` stage in addition * to the naked rootDomain. For non-production stages, this is a no-op. * * @default true */ buildWwwSubdomain?: boolean; /** * HostedZone to add Distribution AliasRecords to. */ hostedZone?: IHostedZone; /** * The TLS/SSL certificate to use for the distribution. */ certificate?: ICertificate; /** * Optional. If creating the hosting bucket, these props will be * passed to the Bucket construct. To set removal policy use * `CDNConstructProps.removalPolicy`. When removalPolicy is set to DESTROY, * which is the default behavior, autoDeleteObjects will be enabled. */ bucketProps?: Omit, 'removalPolicy' | 'autoDeleteObjects'>; /** * Optional. Props that will get passed to the WebDistribution construct. */ distributionProps?: Mutable & { logicalId?: string; }; api?: { /** * The RestApi that is being hit via CloudFront. */ restApi: IRestApi; /** * The api stage (path suffix) at the end of the execute domain. * * @default "/prod" */ apiStage?: string; /** * The url paths that will be forwarded to the api. * * @default "/api/*" */ apiPathPattern?: string; }; } interface GetBucketNameProps extends Partial> { urls?: ReturnType; } export declare class CDNConstruct extends Construct { private props; /** * Exposes the algorithm that is used to generate the bucket name from the * construct `props`. Useful if you need to know the bucket name for other * constructs and are getting a circular dependency error when importing the * IBucket. Gotta love chicken and the egg ala cdk. */ static getBucketName: (props: GetBucketNameProps) => string; /** * This is a helper function to avoid resource collisions during development. * When buckets get left behind, rebuilding the stack throws an error. Does a * lookup for the bucket that is going to get built and adds * `props.bucketName` and `props.useExistingBucket = true` to the props and * returns the full props object to be used with `new CDNConstruct()` */ static lookupExistingResources(props: CDNConstructProps & { region: string; profile?: string; }): Promise; bucket: IBucket; distribution: CloudFrontWebDistribution; urls?: ReturnType; private originAccessIdentity; constructor(scope: Construct, id: string, props: CDNConstructProps); private buildBucket; private buildDistribution; private buildCodeDeployment; } export {};