constructor()

in transcribe-ui-frontend/provisioning/lib/construct/frontend-service.ts [15:69]


  constructor(scope: cdk.Construct, id: string, props?: FrontendServiceProps) {
    super(scope, id)

    this.bucket = new s3.Bucket(this, `${id}-bucket`, {
      websiteIndexDocument: 'index.html',
      websiteErrorDocument: 'index.html'
    })

    const originAccessIdentity = new cloudfront.OriginAccessIdentity(
      this,
      `${id}-oai`
    )

    const bucketPolicy = new iam.PolicyStatement({
      actions: ['s3:GetObject'],
      effect: iam.Effect.ALLOW,
      principals: [originAccessIdentity.grantPrincipal],
      resources: [`${this.bucket.bucketArn}/*`]
    })
    this.bucket.addToResourcePolicy(bucketPolicy)

    this.distribution = new cloudfront.CloudFrontWebDistribution(
      this,
      `${id}-distribution`,
      {
        priceClass: cloudfront.PriceClass.PRICE_CLASS_ALL,
        webACLId: props?.webAcl.ref,
        originConfigs: [
          {
            s3OriginSource: {
              s3BucketSource: this.bucket,
              originAccessIdentity: originAccessIdentity
            },
            behaviors: [
              {
                isDefaultBehavior: true
              }
            ]
          }
        ],
        errorConfigurations: [
          {
            errorCachingMinTtl: 300,
            errorCode: 404,
            responseCode: 200,
            responsePagePath: '/index.html'
          }
        ]
      }
    )

    new cdk.CfnOutput(this, 'frontend-endpoint', {
      value: `https://${this.distribution.distributionDomainName}`
    })
  }