Skip to content

Commit

Permalink
integ
Browse files Browse the repository at this point in the history
  • Loading branch information
watany-dev committed Nov 22, 2023
1 parent 9f54b1c commit 8673979
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import * as cdk from 'aws-cdk-lib';
import { IntegTest } from '@aws-cdk/integ-tests-alpha';
import { TestOrigin } from './test-origin';
import * as cloudfront from 'aws-cdk-lib/aws-cloudfront';

const app = new cdk.App();
const stack = new cdk.Stack(app, 'integ-distribution-function', { env: { region: 'eu-west-1' } });

const cfFunctionRequest = new cloudfront.Function(stack, 'FunctionRequest', {
code: cloudfront.FunctionCode.fromInline('function handler(event) { return event.request }'),
});

const cfFunctionResponse = new cloudfront.Function(stack, 'FunctionResponse', {
code: cloudfront.FunctionCode.fromInline('function handler(event) { return event.response }'),
});

new cloudfront.Distribution(stack, 'Dist', {
defaultBehavior: {
origin: new TestOrigin('www.example.com'),
cachePolicy: cloudfront.CachePolicy.CACHING_DISABLED,
functionAssociations: [{
function: cfFunctionRequest,
eventType: cloudfront.FunctionEventType.VIEWER_REQUEST,
}, {
function: cfFunctionResponse,
eventType: cloudfront.FunctionEventType.VIEWER_RESPONSE,
}],
},
});

new cdk.CfnOutput(stack, 'RequestFunctionArn', { value: cfFunctionRequest.functionArn });
new cdk.CfnOutput(stack, 'RequestFunctionStage', { value: cfFunctionRequest.functionStage });

new cdk.CfnOutput(stack, 'ResponseFunctionArn', { value: cfFunctionResponse.functionArn });
new cdk.CfnOutput(stack, 'ResponseFunctionStage', { value: cfFunctionResponse.functionStage });

new IntegTest(app, 'CF2Runtime', {
testCases: [stack],
});

app.synth();
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ const stack = new cdk.Stack(app, 'integ-distribution-function', { env: { region:

const cfFunction = new cloudfront.Function(stack, 'Function', {
code: cloudfront.FunctionCode.fromInline('function handler(event) { return event.request }'),
runtime: cloudfront.FunctionRuntime.JS_2_0,
});

new cloudfront.Distribution(stack, 'Dist', {
Expand Down

0 comments on commit 8673979

Please sign in to comment.