Skip to content

Commit 3cc66bf

Browse files
authored
fix: add lambda:InvokeFunction permission for CloudFront OAC (#83)
## Summary Starting October 2025, new Lambda function URLs require both `lambda:InvokeFunctionUrl` and `lambda:InvokeFunction` permissions when using CloudFront Origin Access Control (OAC). ## Problem CDK's `FunctionUrlOrigin.withOriginAccessControl` only adds `lambda:InvokeFunctionUrl` permission. New deployments after October 2025 would fail with 403 errors because the `lambda:InvokeFunction` permission is missing. ## Solution Explicitly add `lambda:InvokeFunction` permission using `CfnPermission`. ## Reference - AWS Documentation: https://docs.aws.amazon.com/lambda/latest/dg/urls-auth.html ## Dependencies **Please merge #81 first.** This PR is based on that branch and will have no conflicts once #81 is merged.
1 parent 0c41aa8 commit 3cc66bf

File tree

3 files changed

+78
-2
lines changed

3 files changed

+78
-2
lines changed

cdk/lib/constructs/cf-lambda-furl-service/service.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Construct } from 'constructs';
2-
import { Duration } from 'aws-cdk-lib';
3-
import { FunctionUrlAuthType, Function, InvokeMode } from 'aws-cdk-lib/aws-lambda';
2+
import { Aws, Duration } from 'aws-cdk-lib';
3+
import { FunctionUrlAuthType, Function, InvokeMode, CfnPermission } from 'aws-cdk-lib/aws-lambda';
44
import {
55
AllowedMethods,
66
CacheCookieBehavior,
@@ -120,6 +120,18 @@ export class CloudFrontLambdaFunctionUrlService extends Construct {
120120
minimumProtocolVersion: SecurityPolicyProtocol.TLS_V1_2_2021,
121121
});
122122

123+
// Starting October 2025, new function URLs require both lambda:InvokeFunctionUrl
124+
// and lambda:InvokeFunction permissions for CloudFront OAC.
125+
// CDK's FunctionUrlOrigin.withOriginAccessControl only adds lambda:InvokeFunctionUrl,
126+
// so we explicitly add lambda:InvokeFunction here.
127+
// See: https://docs.aws.amazon.com/lambda/latest/dg/urls-auth.html
128+
new CfnPermission(this, 'InvokeFunctionPermission', {
129+
action: 'lambda:InvokeFunction',
130+
functionName: handler.functionArn,
131+
principal: 'cloudfront.amazonaws.com',
132+
sourceArn: `arn:${Aws.PARTITION}:cloudfront::${Aws.ACCOUNT_ID}:distribution/${distribution.distributionId}`,
133+
});
134+
123135
if (hostedZone) {
124136
new ARecord(this, 'Record', {
125137
zone: hostedZone,

cdk/test/__snapshots__/serverless-fullstack-webapp-starter-kit-without-domain.test.ts.snap

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3685,6 +3685,38 @@ service iptables save",
36853685
},
36863686
"Type": "AWS::IAM::Policy",
36873687
},
3688+
"WebappInvokeFunctionPermission8F3F2610": {
3689+
"Properties": {
3690+
"Action": "lambda:InvokeFunction",
3691+
"FunctionName": {
3692+
"Fn::GetAtt": [
3693+
"WebappHandler8DD158A3",
3694+
"Arn",
3695+
],
3696+
},
3697+
"Principal": "cloudfront.amazonaws.com",
3698+
"SourceArn": {
3699+
"Fn::Join": [
3700+
"",
3701+
[
3702+
"arn:",
3703+
{
3704+
"Ref": "AWS::Partition",
3705+
},
3706+
":cloudfront::",
3707+
{
3708+
"Ref": "AWS::AccountId",
3709+
},
3710+
":distribution/",
3711+
{
3712+
"Ref": "Webapp107041BD",
3713+
},
3714+
],
3715+
],
3716+
},
3717+
},
3718+
"Type": "AWS::Lambda::Permission",
3719+
},
36883720
"WebappMigrationRunnerAC67C012": {
36893721
"DependsOn": [
36903722
"VpcPrivateSubnet1DefaultRouteBE02A9ED",

cdk/test/__snapshots__/serverless-fullstack-webapp-starter-kit.test.ts.snap

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3491,6 +3491,38 @@ service iptables save",
34913491
},
34923492
"Type": "AWS::IAM::Policy",
34933493
},
3494+
"WebappInvokeFunctionPermission8F3F2610": {
3495+
"Properties": {
3496+
"Action": "lambda:InvokeFunction",
3497+
"FunctionName": {
3498+
"Fn::GetAtt": [
3499+
"WebappHandler8DD158A3",
3500+
"Arn",
3501+
],
3502+
},
3503+
"Principal": "cloudfront.amazonaws.com",
3504+
"SourceArn": {
3505+
"Fn::Join": [
3506+
"",
3507+
[
3508+
"arn:",
3509+
{
3510+
"Ref": "AWS::Partition",
3511+
},
3512+
":cloudfront::",
3513+
{
3514+
"Ref": "AWS::AccountId",
3515+
},
3516+
":distribution/",
3517+
{
3518+
"Ref": "Webapp107041BD",
3519+
},
3520+
],
3521+
],
3522+
},
3523+
},
3524+
"Type": "AWS::Lambda::Permission",
3525+
},
34943526
"WebappMigrationRunnerAC67C012": {
34953527
"DependsOn": [
34963528
"VpcPrivateSubnet1DefaultRouteBE02A9ED",

0 commit comments

Comments
 (0)