Skip to content

About

AWS CDK Construct to upload local files to S3 and make them publicly accessible via CloudFront

Resources

Stars

0 stars

Watchers

1 watching

Forks

Repository files navigation

awscdk-construct-file-publisher

View on Construct Hub

CDK Construct for making local files publicly available

  • Specify a path to a local folder that contains files
  • FilePublisher creates an S3 bucket and uploads all the files to the bucket
  • FilePublisher creates a CloudFront distribution and set the bucket as its origin via Origin Access Identity (OAI)
  • You can access the files via CloudFront as the S3 bucket remains private

Install

NPM

Usage

import * as cdk from 'aws-cdk-lib';
import { Construct } from 'constructs';
import { FilePublisher } from 'awscdk-construct-file-publisher';

export class ExampleStack extends cdk.Stack {
  constructor(scope: Construct, id: string, props?: cdk.StackProps) {
    super(scope, id, props);

    // Upload all the files in the local folder (./upload) to S3
    const publicFolder = new FilePublisher(this, 'FilePublisher', {
      path: './upload',
    });

    // You can access the file via Internet
    new cdk.CfnOutput(this, "PublicURL", {
      value: `${publicFolder.url}/dog.mp4`,,
      exportName: cdk.Aws.STACK_NAME + "PublicURL",
      description: "Public URL",
    });
  }
}

About

AWS CDK Construct to upload local files to S3 and make them publicly accessible via CloudFront

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages