in lib/module_3_1/ab_testing_module_3_1.ts [32:107]
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');
const mySsm = new ssm.StringParameter(this, 'S3BucketNameSSMParam', {
parameterName: "AB-S3-ConfigBucket",
description: 'S3 bucket used to store config for AB testing workshop',
stringValue: configBucket.bucketName
});
new s3deployment.BucketDeployment(this, "deployment", {
sources: [s3deployment.Source.asset("./resources/website")],
destinationBucket: hostingBucket,
});
new s3deployment.BucketDeployment(this, "config", {
sources: [s3deployment.Source.asset("resources/module_3_1/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_1/request'),
});
const lambdaEdgeViewerResponse = new lambda.Function(this, 'LambdaEdgeViewerResponse', {
runtime: lambda.Runtime.NODEJS_12_X,
handler: 'index.handler',
code: lambda.Code.fromAsset('resources/module_3_1/response'),
});
configBucket.grantRead(lambdaEdgeViewerRequest);
mySsm.grantRead(lambdaEdgeViewerRequest);
const myOrigin = new origins.S3Origin(hostingBucket);
const myDistribution = new cloudfront.Distribution(this, 'AB testing distribution', {
defaultBehavior: {
origin: myOrigin, viewerProtocolPolicy: cloudfront.ViewerProtocolPolicy.REDIRECT_TO_HTTPS
},
additionalBehaviors: {
'/': {
origin: myOrigin,
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-1'
});
const dashboard = new ABDashboard(this, "MonitoringDashboard");
dashboard.createModule33Dashboard(lambdaEdgeViewerRequest.functionName, "", "ABTestingWorkshopModule31");
new cdk.CfnOutput(this, 'CloudFrontURL', {
description: 'The CloudFront distribution URL',
value: 'https://' + myDistribution.domainName,
})
}