Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(cloudfront): CloudFront Function runtime property #28099

Merged
merged 26 commits into from
Dec 29, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
28ab0c3
feat(cloudfront): Setting Runtime of CF2
watany-dev Nov 22, 2023
9f54b1c
readme
watany-dev Nov 22, 2023
8673979
integ
watany-dev Nov 22, 2023
757a212
snapshot
watany-dev Nov 22, 2023
d3fb723
Revert "snapshot"
watany-dev Nov 22, 2023
0b165cd
integ
watany-dev Nov 22, 2023
858e821
Merge branch 'main' into cf2-runtime2
watany-dev Nov 22, 2023
c209632
fix readme
watany-dev Nov 22, 2023
a74e730
Merge branch 'cf2-runtime2' of https://github.com/watany-dev/aws-cdk …
watany-dev Nov 22, 2023
e80fa76
Merge branch 'aws:main' into cf2-runtime2
watany-dev Nov 24, 2023
204bfe4
Merge branch 'aws:main' into cf2-runtime2
watany-dev Nov 25, 2023
a4d220c
update integ
watany-dev Nov 25, 2023
d1d0236
Merge branch 'main' into cf2-runtime2
watany-dev Nov 28, 2023
c1ba48b
Merge branch 'main' into cf2-runtime2
watany-dev Nov 30, 2023
77dc039
Merge branch 'aws:main' into cf2-runtime2
watany-dev Dec 21, 2023
7d82d0e
enum to class
watany-dev Dec 21, 2023
18b4cfe
fix lint
watany-dev Dec 21, 2023
170ea4b
Apply suggestions from code review
kaizencc Dec 22, 2023
96ba2d0
Merge branch 'main' into cf2-runtime2
watany-dev Dec 23, 2023
1c35ae2
Merge branch 'main' into cf2-runtime2
watany-dev Dec 26, 2023
50e9ca5
optional
watany-dev Dec 28, 2023
b0eebba
optional
watany-dev Dec 28, 2023
87bc78e
Merge branch 'cf2-runtime2' of https://github.com/watany-dev/aws-cdk …
watany-dev Dec 28, 2023
968fe51
default
watany-dev Dec 28, 2023
4819dad
Merge branch 'main' into cf2-runtime2
watany-dev Dec 28, 2023
783aed1
Merge branch 'main' into cf2-runtime2
mergify[bot] Dec 29, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ 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
24 changes: 23 additions & 1 deletion packages/aws-cdk-lib/aws-cloudfront/lib/function.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,12 @@ export interface FunctionProps {
* The source code of the function.
*/
readonly code: FunctionCode;

/**
* The runtime environment for the function.
* @default FunctionRuntime.JS_1_0
*/
readonly runtime?: FunctionRuntime;
}

/**
Expand Down Expand Up @@ -165,7 +171,7 @@ export class Function extends Resource implements IFunction {
functionCode: props.code.render(),
functionConfig: {
comment: props.comment ?? this.functionName,
runtime: 'cloudfront-js-1.0',
runtime: props.runtime ?? FunctionRuntime.JS_1_0,
},
name: this.functionName,
});
Expand Down Expand Up @@ -212,3 +218,19 @@ export interface FunctionAssociation {
/** The type of event which should invoke the function. */
readonly eventType: FunctionEventType;
}

/**
* The function's runtime environment version.
*/
export enum FunctionRuntime {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this would be better as an enum-like class, similar to how our other Rumtime types look.


kaizencc marked this conversation as resolved.
Show resolved Hide resolved
/**
* cloudfront-js-1.0
*/
JS_1_0 = 'cloudfront-js-1.0',

/**
* cloudfront-js-2.0
*/
JS_2_0 = 'cloudfront-js-2.0',
}
30 changes: 29 additions & 1 deletion packages/aws-cdk-lib/aws-cloudfront/test/function.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as path from 'path';
import { Template } from '../../assertions';
import { App, Stack } from '../../core';
import { Function, FunctionCode } from '../lib';
import { Function, FunctionCode, FunctionRuntime } from '../lib';

describe('CloudFront Function', () => {

Expand Down Expand Up @@ -132,4 +132,32 @@ describe('CloudFront Function', () => {
},
});
});

test('runtime testing', () => {
const app = new App();
const stack = new Stack(app, 'Stack', {
env: { account: '123456789012', region: 'testregion' },
});
new Function(stack, 'CF2', {
code: FunctionCode.fromInline('code'),
runtime: FunctionRuntime.JS_2_0,
});

Template.fromStack(stack).templateMatches({
Resources: {
CF2D7241DD7: {
Type: 'AWS::CloudFront::Function',
Properties: {
Name: 'testregionStackCF2CE3F783F',
AutoPublish: true,
FunctionCode: 'code',
FunctionConfig: {
Comment: 'testregionStackCF2CE3F783F',
Runtime: 'cloudfront-js-2.0',
},
},
},
},
});
});
});
Loading