-
Notifications
You must be signed in to change notification settings - Fork 4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(cloudfront): add Lambda associations (#2760)
This enables to associate a lambda to a distribution behaviour. The lambda could be associated with the four available event-types.
- Loading branch information
1 parent
9ea6148
commit b088c8c
Showing
5 changed files
with
235 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
129 changes: 129 additions & 0 deletions
129
packages/@aws-cdk/aws-cloudfront/test/integ.cloudfront-lambda-association.expected.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
{ | ||
"Resources": { | ||
"Bucket83908E77": { | ||
"Type": "AWS::S3::Bucket" | ||
}, | ||
"LambdaServiceRoleA8ED4D3B": { | ||
"Type": "AWS::IAM::Role", | ||
"Properties": { | ||
"AssumeRolePolicyDocument": { | ||
"Statement": [ | ||
{ | ||
"Action": "sts:AssumeRole", | ||
"Effect": "Allow", | ||
"Principal": { | ||
"Service": { | ||
"Fn::Join": [ | ||
"", | ||
[ | ||
"lambda.", | ||
{ | ||
"Ref": "AWS::URLSuffix" | ||
} | ||
] | ||
] | ||
} | ||
} | ||
} | ||
], | ||
"Version": "2012-10-17" | ||
}, | ||
"ManagedPolicyArns": [ | ||
{ | ||
"Fn::Join": [ | ||
"", | ||
[ | ||
"arn:", | ||
{ | ||
"Ref": "AWS::Partition" | ||
}, | ||
":iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" | ||
] | ||
] | ||
} | ||
] | ||
} | ||
}, | ||
"LambdaD247545B": { | ||
"Type": "AWS::Lambda::Function", | ||
"Properties": { | ||
"Code": { | ||
"ZipFile": "foo" | ||
}, | ||
"Handler": "index.handler", | ||
"Role": { | ||
"Fn::GetAtt": [ | ||
"LambdaServiceRoleA8ED4D3B", | ||
"Arn" | ||
] | ||
}, | ||
"Runtime": "nodejs8.10" | ||
}, | ||
"DependsOn": [ | ||
"LambdaServiceRoleA8ED4D3B" | ||
] | ||
}, | ||
"LambdaVersionFA49E61E": { | ||
"Type": "AWS::Lambda::Version", | ||
"Properties": { | ||
"FunctionName": { | ||
"Ref": "LambdaD247545B" | ||
} | ||
} | ||
}, | ||
"MyDistributionCFDistributionDE147309": { | ||
"Type": "AWS::CloudFront::Distribution", | ||
"Properties": { | ||
"DistributionConfig": { | ||
"CacheBehaviors": [], | ||
"DefaultCacheBehavior": { | ||
"AllowedMethods": [ | ||
"GET", | ||
"HEAD" | ||
], | ||
"CachedMethods": [ | ||
"GET", | ||
"HEAD" | ||
], | ||
"ForwardedValues": { | ||
"Cookies": { | ||
"Forward": "none" | ||
}, | ||
"QueryString": false | ||
}, | ||
"TargetOriginId": "origin1", | ||
"ViewerProtocolPolicy": "redirect-to-https", | ||
"LambdaFunctionAssociations": [ | ||
{ | ||
"EventType": "origin-request", | ||
"LambdaFunctionARN": { | ||
"Ref": "LambdaVersionFA49E61E" | ||
} | ||
} | ||
] | ||
}, | ||
"DefaultRootObject": "index.html", | ||
"Enabled": true, | ||
"HttpVersion": "http2", | ||
"IPV6Enabled": true, | ||
"Origins": [ | ||
{ | ||
"DomainName": { | ||
"Fn::GetAtt": [ | ||
"Bucket83908E77", | ||
"RegionalDomainName" | ||
] | ||
}, | ||
"Id": "origin1", | ||
"S3OriginConfig": {} | ||
} | ||
], | ||
"PriceClass": "PriceClass_100", | ||
"ViewerCertificate": { | ||
"CloudFrontDefaultCertificate": true | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
packages/@aws-cdk/aws-cloudfront/test/integ.cloudfront-lambda-association.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import lambda = require('@aws-cdk/aws-lambda'); | ||
import s3 = require('@aws-cdk/aws-s3'); | ||
import cdk = require('@aws-cdk/cdk'); | ||
import cloudfront = require('../lib'); | ||
|
||
const app = new cdk.App(); | ||
|
||
const stack = new cdk.Stack(app, 'aws-cdk-cloudfront'); | ||
|
||
const sourceBucket = new s3.Bucket(stack, 'Bucket', { | ||
removalPolicy: cdk.RemovalPolicy.Destroy | ||
}); | ||
|
||
const lambdaFunction = new lambda.Function(stack, 'Lambda', { | ||
code: lambda.Code.inline('foo'), | ||
handler: 'index.handler', | ||
runtime: lambda.Runtime.NodeJS810 | ||
}); | ||
|
||
const lambdaVersion = new lambda.Version(stack, 'LambdaVersion', { | ||
lambda: lambdaFunction | ||
}); | ||
|
||
new cloudfront.CloudFrontWebDistribution(stack, 'MyDistribution', { | ||
originConfigs: [ | ||
{ | ||
s3OriginSource: { | ||
s3BucketSource: sourceBucket | ||
}, | ||
behaviors : [ {isDefaultBehavior: true, lambdaFunctionAssociations: [{ | ||
eventType: cloudfront.LambdaEdgeEventType.OriginRequest, | ||
lambdaFunction: lambdaVersion | ||
}]}] | ||
} | ||
] | ||
}); | ||
|
||
app.run(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters