Skip to content

Instantly share code, notes, and snippets.

@lampidudelj
Created July 18, 2019 21:02
Show Gist options
  • Save lampidudelj/d7aa227c3c53d8ae3499a0bb911f4f22 to your computer and use it in GitHub Desktop.
Save lampidudelj/d7aa227c3c53d8ae3499a0bb911f4f22 to your computer and use it in GitHub Desktop.
aws-cdk with s3 and cloudfront distribution
import cdk = require('@aws-cdk/core');
import s3 = require('@aws-cdk/aws-s3');
import cloudfront = require('@aws-cdk/aws-cloudfront');
export class AwsCdkStack extends cdk.Stack {
constructor(scope: cdk.Construct, id: string, props?: cdk.StackProps) {
super(scope, id, props);
const s3Bucket = new s3.Bucket(this, 'host-bucket', {
bucketName: `react-host-bucket-9f7317d0dd7c`,
websiteIndexDocument: 'index.html',
websiteErrorDocument: 'error.html',
publicReadAccess: true
});
const distribution = new cloudfront.CloudFrontWebDistribution(this, 'my-distribution', {
originConfigs: [
{
s3OriginSource: {
s3BucketSource: s3Bucket
},
behaviors : [ {isDefaultBehavior: true}]
}
],
defaultRootObject: 'index.html'
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment