constructor()

in lib/module_3_2/ab_testing_module_3_2.ts [29:101]


  constructor(scope: cdk.App, id: string, props?: cdk.StackProps) {
    super(scope, id, props);

    const hostingBucket = new s3.Bucket(this, 'hosting-bucket-deployment');
    const configBucket = new s3.Bucket(this, 'config-bucket-deployment');


    new s3deployment.BucketDeployment(this, "hosting", {
      sources: [s3deployment.Source.asset("./resources/website")],
      destinationBucket: hostingBucket,
    });

    new s3deployment.BucketDeployment(this, "config", {
      sources: [s3deployment.Source.asset("resources/module_3_2/segmentation")],
      destinationBucket: configBucket,
    });

    const lambdaEdgeViewerRequest = new lambda.Function(this, 'LambdaEdgeViewerRequest', {
      runtime: lambda.Runtime.NODEJS_12_X,
      handler: 'index.handler',
      code: lambda.Code.fromAsset('resources/module_3_2/request'),
    });

    const lambdaEdgeViewerResponse = new lambda.Function(this, 'LambdaEdgeViewerResponse', {
      runtime: lambda.Runtime.NODEJS_12_X,
      handler: 'index.handler',
      code: lambda.Code.fromAsset('resources/module_3_2/response'),
    });

    const hostingOrigin = new origins.S3Origin(hostingBucket);
    const configOrigin = new origins.S3Origin(configBucket);

    const myDistribution = new cloudfront.Distribution(this, 'AB testing distribution', {
      defaultBehavior: {
         origin: hostingOrigin, viewerProtocolPolicy: cloudfront.ViewerProtocolPolicy.REDIRECT_TO_HTTPS
      },

      additionalBehaviors: {
        'config/ab_testing_config.json': {
          origin: configOrigin,
          viewerProtocolPolicy: cloudfront.ViewerProtocolPolicy.REDIRECT_TO_HTTPS,

        },
        '/': {
          origin: hostingOrigin,
          viewerProtocolPolicy: cloudfront.ViewerProtocolPolicy.REDIRECT_TO_HTTPS,
          edgeLambdas: [
            {
              functionVersion: lambdaEdgeViewerRequest.currentVersion,
              eventType: cloudfront.LambdaEdgeEventType.VIEWER_REQUEST,
            },
            {
              functionVersion: lambdaEdgeViewerResponse.currentVersion,
              eventType: cloudfront.LambdaEdgeEventType.VIEWER_RESPONSE,
            },
          ],
        },

      },

       comment : 'AB Testing Workshop - Module 3-2'
    });

    const dashboard = new ABDashboard(this, "MonitoringDashboard");
    dashboard.createModule33Dashboard(lambdaEdgeViewerRequest.functionName, "", "ABTestingWorkshopModule32");


    new cdk.CfnOutput(this, 'CloudFrontURL', {
      description: 'The CloudFront distribution URL',
      value: 'https://' + myDistribution.domainName,
  })

  }