Skip to content

Commit

Permalink
we also check the AWS::Lambda::Permission resource exists in the temp…
Browse files Browse the repository at this point in the history
…late and has the expected policy
  • Loading branch information
watany-dev committed Sep 10, 2024
1 parent 2ad9170 commit 989141b
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ class FunctionUrlOriginWithOAC extends cloudfront.OriginBase {
new lambda.CfnPermission(scope, `InvokeFromApiFor${options.originId}`, {
principal: 'cloudfront.amazonaws.com',
action: 'lambda:InvokeFunctionUrl',
functionName: cdk.Fn.select(6, cdk.Fn.split(':', this.functionUrl.functionArn)),
functionName: this.functionUrl.functionArn,
sourceArn: `arn:${cdk.Aws.PARTITION}:cloudfront::${cdk.Aws.ACCOUNT_ID}:distribution/${distributionId}`,
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,27 @@ describe('FunctionUrlOriginAccessControl', () => {
]),
},
});

template.hasResourceProperties('AWS::Lambda::Permission', {
Action: 'lambda:InvokeFunctionUrl',
FunctionName: {
'Fn::GetAtt': ['MyFunctionFunctionUrlFF6DE78C', 'FunctionArn'],
},
Principal: 'cloudfront.amazonaws.com',
SourceArn: {
'Fn::Join': [
'',
[
'arn:',
{ Ref: 'AWS::Partition' },
':cloudfront::',
{ Ref: 'AWS::AccountId' },
':distribution/',
{ Ref: 'MyDistribution6271DFB5' },
],
],
},
});
});

test('Correctly configures CloudFront Distribution with Origin Access Control', () => {
Expand Down Expand Up @@ -176,6 +197,27 @@ describe('FunctionUrlOriginAccessControl', () => {
SigningProtocol: 'sigv4',
},
});

template.hasResourceProperties('AWS::Lambda::Permission', {
Action: 'lambda:InvokeFunctionUrl',
FunctionName: {
'Fn::GetAtt': ['MyFunctionFunctionUrlFF6DE78C', 'FunctionArn'],
},
Principal: 'cloudfront.amazonaws.com',
SourceArn: {
'Fn::Join': [
'',
[
'arn:',
{ Ref: 'AWS::Partition' },
':cloudfront::',
{ Ref: 'AWS::AccountId' },
':distribution/',
{ Ref: 'MyDistribution6271DFB5' },
],
],
},
});
});

test('Correctly configures CloudFront Distribution with a custom Origin Access Control', () => {
Expand Down

0 comments on commit 989141b

Please sign in to comment.