Skip to content

Commit b8f47c8

Browse files
authored
feat(cloudfront): function URL origin access control L2 construct (#31339)
Issue # (if applicable) #31629 ### Reason for this change This change introduces support for Lambda Function URLs with custom Origin Access Control (OAC) in CloudFront distributions, enhancing security and control over CloudFront-Lambda integration. ### Description of changes - Added a new feature allowing the configuration of Lambda Function URLs with custom OAC in CloudFront. - Implemented support for custom signing behavior and protocols for Lambda origins. - Included new tests to validate the correct behavior of OAC with Lambda Function URLs. ### Description of how you validated changes - Ran unit tests to ensure that the OAC setup for Lambda Function URLs is correctly applied in CloudFront distributions. - Validated by deploying a sample CDK application to confirm the functionality and integration of Lambda Function URLs with CloudFront using OAC. ### Checklist - [x] My code adheres to the [CONTRIBUTING GUIDE](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) and [DESIGN GUIDELINES](https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md) - [x] OAC implementation is complete. ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent 771eeff commit b8f47c8

File tree

42 files changed

+102680
-3
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+102680
-3
lines changed

Diff for: packages/@aws-cdk-testing/framework-integ/test/aws-cloudfront-origins/test/integ.function-url-origin-oac-alias.js.snapshot/asset.da514df694ce3f41453746a766ae6aff13c869c38002598930d6d34e5711985b.bundle/index.js

+31,702
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: packages/@aws-cdk-testing/framework-integ/test/aws-cloudfront-origins/test/integ.function-url-origin-oac-alias.js.snapshot/cdk.out

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: packages/@aws-cdk-testing/framework-integ/test/aws-cloudfront-origins/test/integ.function-url-origin-oac-alias.js.snapshot/integ-cloudfront-function-url-origin-oac.assets.json

+19
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,254 @@
1+
{
2+
"Resources": {
3+
"MyFunctionServiceRole3C357FF2": {
4+
"Type": "AWS::IAM::Role",
5+
"Properties": {
6+
"AssumeRolePolicyDocument": {
7+
"Statement": [
8+
{
9+
"Action": "sts:AssumeRole",
10+
"Effect": "Allow",
11+
"Principal": {
12+
"Service": "lambda.amazonaws.com"
13+
}
14+
}
15+
],
16+
"Version": "2012-10-17"
17+
},
18+
"ManagedPolicyArns": [
19+
{
20+
"Fn::Join": [
21+
"",
22+
[
23+
"arn:",
24+
{
25+
"Ref": "AWS::Partition"
26+
},
27+
":iam::aws:policy/service-role/AWSLambdaBasicExecutionRole"
28+
]
29+
]
30+
}
31+
]
32+
}
33+
},
34+
"MyFunction3BAA72D1": {
35+
"Type": "AWS::Lambda::Function",
36+
"Properties": {
37+
"Code": {
38+
"ZipFile": "\n exports.handler = async () => ({\n statusCode: 200,\n body: 'Hello!!'\n });\n "
39+
},
40+
"Handler": "index.handler",
41+
"Role": {
42+
"Fn::GetAtt": [
43+
"MyFunctionServiceRole3C357FF2",
44+
"Arn"
45+
]
46+
},
47+
"Runtime": "nodejs20.x"
48+
},
49+
"DependsOn": [
50+
"MyFunctionServiceRole3C357FF2"
51+
]
52+
},
53+
"MyFunctionCurrentVersion197490AFf33de88117a39ef9096915f994a6caf9": {
54+
"Type": "AWS::Lambda::Version",
55+
"Properties": {
56+
"FunctionName": {
57+
"Ref": "MyFunction3BAA72D1"
58+
}
59+
}
60+
},
61+
"MyFunctionAliasLive372006BC": {
62+
"Type": "AWS::Lambda::Alias",
63+
"Properties": {
64+
"FunctionName": {
65+
"Ref": "MyFunction3BAA72D1"
66+
},
67+
"FunctionVersion": {
68+
"Fn::GetAtt": [
69+
"MyFunctionCurrentVersion197490AFf33de88117a39ef9096915f994a6caf9",
70+
"Version"
71+
]
72+
},
73+
"Name": "Live",
74+
"ProvisionedConcurrencyConfig": {
75+
"ProvisionedConcurrentExecutions": 5
76+
}
77+
}
78+
},
79+
"MyFunctionAliasLiveFunctionUrl4C98949A": {
80+
"Type": "AWS::Lambda::Url",
81+
"Properties": {
82+
"AuthType": "AWS_IAM",
83+
"Qualifier": "Live",
84+
"TargetFunctionArn": {
85+
"Fn::GetAtt": [
86+
"MyFunction3BAA72D1",
87+
"Arn"
88+
]
89+
}
90+
},
91+
"DependsOn": [
92+
"MyFunctionAliasLive372006BC"
93+
]
94+
},
95+
"AliasDistributionOrigin1FunctionUrlOriginAccessControl37A840CE": {
96+
"Type": "AWS::CloudFront::OriginAccessControl",
97+
"Properties": {
98+
"OriginAccessControlConfig": {
99+
"Name": "integcloudfrontfunctionurlornctionUrlOriginAccessControlFCD34EE1",
100+
"OriginAccessControlOriginType": "lambda",
101+
"SigningBehavior": "always",
102+
"SigningProtocol": "sigv4"
103+
}
104+
}
105+
},
106+
"AliasDistributionOrigin1InvokeFromApiForintegcloudfrontfunctionurloriginoacAliasDistributionOrigin11CF22ED58F6A0AB2": {
107+
"Type": "AWS::Lambda::Permission",
108+
"Properties": {
109+
"Action": "lambda:InvokeFunctionUrl",
110+
"FunctionName": {
111+
"Fn::GetAtt": [
112+
"MyFunctionAliasLiveFunctionUrl4C98949A",
113+
"FunctionArn"
114+
]
115+
},
116+
"Principal": "cloudfront.amazonaws.com",
117+
"SourceArn": {
118+
"Fn::Join": [
119+
"",
120+
[
121+
"arn:",
122+
{
123+
"Ref": "AWS::Partition"
124+
},
125+
":cloudfront::",
126+
{
127+
"Ref": "AWS::AccountId"
128+
},
129+
":distribution/",
130+
{
131+
"Ref": "AliasDistribution1027E46E"
132+
}
133+
]
134+
]
135+
}
136+
}
137+
},
138+
"AliasDistribution1027E46E": {
139+
"Type": "AWS::CloudFront::Distribution",
140+
"Properties": {
141+
"DistributionConfig": {
142+
"DefaultCacheBehavior": {
143+
"CachePolicyId": "658327ea-f89d-4fab-a63d-7e88639e58f6",
144+
"Compress": true,
145+
"TargetOriginId": "integcloudfrontfunctionurloriginoacAliasDistributionOrigin11CF22ED5",
146+
"ViewerProtocolPolicy": "allow-all"
147+
},
148+
"Enabled": true,
149+
"HttpVersion": "http2",
150+
"IPV6Enabled": true,
151+
"Origins": [
152+
{
153+
"CustomOriginConfig": {
154+
"OriginProtocolPolicy": "https-only",
155+
"OriginSSLProtocols": [
156+
"TLSv1.2"
157+
]
158+
},
159+
"DomainName": {
160+
"Fn::Select": [
161+
2,
162+
{
163+
"Fn::Split": [
164+
"/",
165+
{
166+
"Fn::GetAtt": [
167+
"MyFunctionAliasLiveFunctionUrl4C98949A",
168+
"FunctionUrl"
169+
]
170+
}
171+
]
172+
}
173+
]
174+
},
175+
"Id": "integcloudfrontfunctionurloriginoacAliasDistributionOrigin11CF22ED5",
176+
"OriginAccessControlId": {
177+
"Fn::GetAtt": [
178+
"AliasDistributionOrigin1FunctionUrlOriginAccessControl37A840CE",
179+
"Id"
180+
]
181+
}
182+
}
183+
]
184+
}
185+
}
186+
}
187+
},
188+
"Outputs": {
189+
"ExportsOutputFnGetAttMyFunctionAliasLiveFunctionUrl4C98949AFunctionUrl8F680E6D": {
190+
"Value": {
191+
"Fn::GetAtt": [
192+
"MyFunctionAliasLiveFunctionUrl4C98949A",
193+
"FunctionUrl"
194+
]
195+
},
196+
"Export": {
197+
"Name": "integ-cloudfront-function-url-origin-oac:ExportsOutputFnGetAttMyFunctionAliasLiveFunctionUrl4C98949AFunctionUrl8F680E6D"
198+
}
199+
},
200+
"ExportsOutputRefAliasDistribution1027E46ED597E5E3": {
201+
"Value": {
202+
"Ref": "AliasDistribution1027E46E"
203+
},
204+
"Export": {
205+
"Name": "integ-cloudfront-function-url-origin-oac:ExportsOutputRefAliasDistribution1027E46ED597E5E3"
206+
}
207+
},
208+
"ExportsOutputFnGetAttAliasDistribution1027E46EDomainName9B50152C": {
209+
"Value": {
210+
"Fn::GetAtt": [
211+
"AliasDistribution1027E46E",
212+
"DomainName"
213+
]
214+
},
215+
"Export": {
216+
"Name": "integ-cloudfront-function-url-origin-oac:ExportsOutputFnGetAttAliasDistribution1027E46EDomainName9B50152C"
217+
}
218+
}
219+
},
220+
"Parameters": {
221+
"BootstrapVersion": {
222+
"Type": "AWS::SSM::Parameter::Value<String>",
223+
"Default": "/cdk-bootstrap/hnb659fds/version",
224+
"Description": "Version of the CDK Bootstrap resources in this environment, automatically retrieved from SSM Parameter Store. [cdk:skip]"
225+
}
226+
},
227+
"Rules": {
228+
"CheckBootstrapVersion": {
229+
"Assertions": [
230+
{
231+
"Assert": {
232+
"Fn::Not": [
233+
{
234+
"Fn::Contains": [
235+
[
236+
"1",
237+
"2",
238+
"3",
239+
"4",
240+
"5"
241+
],
242+
{
243+
"Ref": "BootstrapVersion"
244+
}
245+
]
246+
}
247+
]
248+
},
249+
"AssertDescription": "CDK bootstrap stack version 6 required. Please run 'cdk bootstrap' with a recent version of the CDK CLI."
250+
}
251+
]
252+
}
253+
}
254+
}

Diff for: packages/@aws-cdk-testing/framework-integ/test/aws-cloudfront-origins/test/integ.function-url-origin-oac-alias.js.snapshot/integ.json

+12
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: packages/@aws-cdk-testing/framework-integ/test/aws-cloudfront-origins/test/integ.function-url-origin-oac-alias.js.snapshot/lambdaaliasurloriginoacDefaultTestDeployAssert249534BF.assets.json

+32
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)