Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support include body for LambdaFunctionAssociation #7085

Closed
prax0724 opened this issue Mar 31, 2020 · 4 comments · Fixed by #10008
Closed

Support include body for LambdaFunctionAssociation #7085

prax0724 opened this issue Mar 31, 2020 · 4 comments · Fixed by #10008
Assignees
Labels
@aws-cdk/aws-cloudfront Related to Amazon CloudFront effort/small Small work item – less than a day of effort feature-request A feature should be added or improved. in-progress This issue is being actively worked on. p1

Comments

@prax0724
Copy link

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.

https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-cloudfront.LambdaFunctionAssociation.html

@prax0724 prax0724 added feature-request A feature should be added or improved. needs-triage This issue or PR still needs to be triaged. labels Mar 31, 2020
@nitishdhar
Copy link

Is there an intermediate way to achieve this for now?

@SomayaB SomayaB added the @aws-cdk/aws-lambda Related to AWS Lambda label Mar 31, 2020
@nija-at nija-at added @aws-cdk/aws-cloudformation Related to AWS CloudFormation and removed needs-triage This issue or PR still needs to be triaged. @aws-cdk/aws-lambda Related to AWS Lambda labels Apr 1, 2020
@nija-at nija-at assigned iliapolo and unassigned nija-at Apr 1, 2020
@marcgreenstock
Copy link

marcgreenstock commented Apr 6, 2020

@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.

@iliapolo iliapolo added @aws-cdk/aws-cloudfront Related to Amazon CloudFront and removed @aws-cdk/aws-cloudformation Related to AWS CloudFormation labels Apr 12, 2020
@iliapolo
Copy link
Contributor

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 👍

@iliapolo iliapolo added the effort/small Small work item – less than a day of effort label Apr 12, 2020
@prax0724
Copy link
Author

@marcgreenstock Thanks!! your solution worked for me as well.

@iliapolo iliapolo assigned njlynch and unassigned iliapolo Aug 19, 2020
@njlynch njlynch added the p1 label Aug 21, 2020
njlynch added a commit that referenced this issue Aug 27, 2020
The `includeBody` flag enables a Lambda@Edge function to receive the body of the
request or response. Enabled this flag for both the `CloudFrontWebDistribution`
and `Distribution` constructs.

fixes #7085
@njlynch njlynch added the in-progress This issue is being actively worked on. label Aug 27, 2020
@mergify mergify bot closed this as completed in #10008 Aug 28, 2020
mergify bot pushed a commit that referenced this issue Aug 28, 2020
The `includeBody` flag enables a Lambda@Edge function to receive the body of the
request or response. Enabled this flag for both the `CloudFrontWebDistribution`
and `Distribution` constructs.

fixes #7085

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-cloudfront Related to Amazon CloudFront effort/small Small work item – less than a day of effort feature-request A feature should be added or improved. in-progress This issue is being actively worked on. p1
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants