When creating lambda-edge behaviours from AWS console , we can select Include Body for lambda edge association.
But the same configuration can't be done by AWS CDK because Include Body property is not available in LambdaFunctionAssociation class.
Is there an intermediate way to achieve this for now?
@nitishdhar it's convoluted but the CDK provides a raw override.
Here's how I got it working:
const distribution = new cloudfront.CloudFrontWebDistribution(this, 'WebDistribution', {
originConfigs: [{
s3OriginSource: {
s3BucketSource: bucket
},
behaviors: [{
isDefaultBehavior: true,
compress: true
}, {
pathPattern: 'api/*',
compress: true,
allowedMethods: cloudfront.CloudFrontAllowedMethods.ALL,
minTtl: cdk.Duration.days(0),
maxTtl: cdk.Duration.days(0),
defaultTtl: cdk.Duration.days(0),
forwardedValues: {
queryString: true,
cookies: {
forward: 'all'
}
},
lambdaFunctionAssociations: [{
eventType: cloudfront.LambdaEdgeEventType.ORIGIN_REQUEST,
lambdaFunction: apiLambdaVersion
}]
}]
}]
})
// get the CloudFormation template
const distributionCfn = distribution.node.defaultChild as cloudfront.CfnDistribution
// Add IncludeBody on the first cache behavior - indexed at 0 because the default behaviour is not on the CacheBehaviors array
distributionCfn.addOverride('Properties.DistributionConfig.CacheBehaviors.0.LambdaFunctionAssociations.0.IncludeBody', true)
distributionCfn above is the CloudFormation template which would look something like this:
Type: AWS::CloudFront::Distribution
Properties:
DistributionConfig:
DefaultCacheBehavior:
...
CacheBehaviors:
- PathPatern: api/*
LambdaFunctionAssociations:
- EventType: origin-request
LambdaFunctionARN: arn:...
The first argument in addOverride is a path to the AWS::CloudFront::Distribution LambdaFunctionAssociation.
So Properties.DistributionConfig.CacheBehaviors.0.LambdaFunctionAssociations.0.IncludeBody adds IncludeBody to LambdaFunctionAssociations[0] on CacheBehaviors[0].
Hopefully this will get sorted out soon, and we won't need to do this. Looks like the property in the CDK was just overlooked.
Hi @marcgreenstock and @nitishdhar
Yeap, this is just an oversight. Adding to our docket.
Thanks for reporting this and thanks @marcgreenstock for the correct workaround 馃憤
@marcgreenstock Thanks!! your solution worked for me as well.
Most helpful comment
@nitishdhar it's convoluted but the CDK provides a raw override.
Here's how I got it working:
distributionCfnabove is the CloudFormation template which would look something like this:The first argument in
addOverrideis a path to the AWS::CloudFront::Distribution LambdaFunctionAssociation.So
Properties.DistributionConfig.CacheBehaviors.0.LambdaFunctionAssociations.0.IncludeBodyaddsIncludeBodytoLambdaFunctionAssociations[0]onCacheBehaviors[0].Hopefully this will get sorted out soon, and we won't need to do this. Looks like the property in the CDK was just overlooked.