-
Notifications
You must be signed in to change notification settings - Fork 4k
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
Changes from 4 commits
28ab0c3
9f54b1c
8673979
757a212
d3fb723
0b165cd
858e821
c209632
a74e730
e80fa76
204bfe4
a4d220c
d1d0236
c1ba48b
77dc039
7d82d0e
18b4cfe
170ea4b
96ba2d0
1c35ae2
50e9ca5
b0eebba
87bc78e
968fe51
4819dad
783aed1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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(); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
{ | ||
"Resources": { | ||
"FunctionRequest95528B2F": { | ||
"Type": "AWS::CloudFront::Function", | ||
"Properties": { | ||
"AutoPublish": true, | ||
"FunctionCode": "function handler(event) { return event.request }", | ||
"FunctionConfig": { | ||
"Comment": "eu-west-1integdistributionfunctionFunctionRequest8E65DEEB", | ||
"Runtime": "cloudfront-js-1.0" | ||
}, | ||
"Name": "eu-west-1integdistributionfunctionFunctionRequest8E65DEEB" | ||
} | ||
}, | ||
"FunctionResponse4EF2D1D3": { | ||
"Type": "AWS::CloudFront::Function", | ||
"Properties": { | ||
"AutoPublish": true, | ||
"FunctionCode": "function handler(event) { return event.response }", | ||
"FunctionConfig": { | ||
"Comment": "eu-west-1integdistributionfunctionFunctionResponseDD4BADA1", | ||
"Runtime": "cloudfront-js-1.0" | ||
}, | ||
"Name": "eu-west-1integdistributionfunctionFunctionResponseDD4BADA1" | ||
} | ||
}, | ||
"DistB3B78991": { | ||
"Type": "AWS::CloudFront::Distribution", | ||
"Properties": { | ||
"DistributionConfig": { | ||
"DefaultCacheBehavior": { | ||
"CachePolicyId": "4135ea2d-6df8-44a3-9df3-4b5a84be39ad", | ||
"Compress": true, | ||
"FunctionAssociations": [ | ||
{ | ||
"EventType": "viewer-request", | ||
"FunctionARN": { | ||
"Fn::GetAtt": [ | ||
"FunctionRequest95528B2F", | ||
"FunctionARN" | ||
] | ||
} | ||
}, | ||
{ | ||
"EventType": "viewer-response", | ||
"FunctionARN": { | ||
"Fn::GetAtt": [ | ||
"FunctionResponse4EF2D1D3", | ||
"FunctionARN" | ||
] | ||
} | ||
} | ||
], | ||
"TargetOriginId": "integdistributionfunctionDistOrigin1D1E9DF17", | ||
"ViewerProtocolPolicy": "allow-all" | ||
}, | ||
"Enabled": true, | ||
"HttpVersion": "http2", | ||
"IPV6Enabled": true, | ||
"Origins": [ | ||
{ | ||
"CustomOriginConfig": { | ||
"OriginProtocolPolicy": "https-only" | ||
}, | ||
"DomainName": "www.example.com", | ||
"Id": "integdistributionfunctionDistOrigin1D1E9DF17" | ||
} | ||
] | ||
} | ||
} | ||
} | ||
}, | ||
"Outputs": { | ||
"RequestFunctionArn": { | ||
"Value": { | ||
"Fn::GetAtt": [ | ||
"FunctionRequest95528B2F", | ||
"FunctionARN" | ||
] | ||
} | ||
}, | ||
"RequestFunctionStage": { | ||
"Value": { | ||
"Fn::GetAtt": [ | ||
"FunctionRequest95528B2F", | ||
"Stage" | ||
] | ||
} | ||
}, | ||
"ResponseFunctionArn": { | ||
"Value": { | ||
"Fn::GetAtt": [ | ||
"FunctionResponse4EF2D1D3", | ||
"FunctionARN" | ||
] | ||
} | ||
}, | ||
"ResponseFunctionStage": { | ||
"Value": { | ||
"Fn::GetAtt": [ | ||
"FunctionResponse4EF2D1D3", | ||
"Stage" | ||
] | ||
} | ||
} | ||
}, | ||
"Parameters": { | ||
"BootstrapVersion": { | ||
"Type": "AWS::SSM::Parameter::Value<String>", | ||
"Default": "/cdk-bootstrap/hnb659fds/version", | ||
"Description": "Version of the CDK Bootstrap resources in this environment, automatically retrieved from SSM Parameter Store. [cdk:skip]" | ||
} | ||
}, | ||
"Rules": { | ||
"CheckBootstrapVersion": { | ||
"Assertions": [ | ||
{ | ||
"Assert": { | ||
"Fn::Not": [ | ||
{ | ||
"Fn::Contains": [ | ||
[ | ||
"1", | ||
"2", | ||
"3", | ||
"4", | ||
"5" | ||
], | ||
{ | ||
"Ref": "BootstrapVersion" | ||
} | ||
] | ||
} | ||
] | ||
}, | ||
"AssertDescription": "CDK bootstrap stack version 6 required. Please run 'cdk bootstrap' with a recent version of the CDK CLI." | ||
} | ||
] | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In my opinion, it would be better to use a new parameter
FunctionRuntime.JS_2_0
as well, what do you think?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, It seems that @mikewrighton previously approved. See this comment if you need me to, otherwise I just approve.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What you say is true. I am happy to report that I have changed to a meaningful integ test
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!