awscdk-construct-file-publisher
v0.0.5
Published
AWS CDK Construct to upload local files to S3 and make them publicly available via CloudFront
Downloads
4
Readme
awscdk-construct-file-publisher
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
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",
});
}
}