aws-cdk icon indicating copy to clipboard operation
aws-cdk copied to clipboard

[aws-cloudfront] EdgeLambda: got an unexpected keyword argument 'include_body'

Open codernaive opened this issue 6 years ago • 3 comments

cdk returns error got an unexpected keyword argument 'include_body'

Documentation for python language bindings indicates include_body (Optional [bool]) as a valid parameter for constructor. Not specifying this constructor parameter generates cloudfront distribution but without include_body checked (request body not passed to lambda I guess). include_body is a valid option for EdgeLambda event_type (VIEWER_REQUEST).

Reproduction Steps

       .
       .
       .
       function_version = lamb.Version(
            self,
            "myLVersion",
            lambda_=lambda_function,
        )

        edge_lambda = cf.EdgeLambda(
            event_type=cf.LambdaEdgeEventType.VIEWER_REQUEST,
            function_version=function_version,
            include_body=True,
        )

        cf_dist = cf.Distribution(
            self,
            _id,
            http_version=cf.HttpVersion.HTTP2,
            default_root_object='index.html',
            default_behavior=cf.BehaviorOptions(
                compress=True,
                viewer_protocol_policy=cf.ViewerProtocolPolicy.REDIRECT_TO_HTTPS,
                origin=origins.S3Origin(s3_bucket),
                edge_lambdas=[
                    edge_lambda,
                ]
            )
        )

What did you expect to happen?

No errors on cdk deploy with correct cloudfront distribution configuration.

Passing include_body=True should result in a Cloudfront distribution with an EdgeLambda function specified for VIEWER_REQUEST with include_body checked.

What actually happened?

TypeError: __init__() got an unexpected keyword argument 'include_body'

Environment

  • CLI Version :1.62.0 (build 8c2d7fc)
  • Framework Version: [email protected] (I'm assuming Framework means the installed node package version)
  • Node.js Version: v14.8.0
  • OS : Ubuntu 20.04
  • Language (Version): Python (3.8.2)

Other

Traceback (most recent call last):
  File "app.py", line 12, in <module>
    REDACTEDStack(app, "sdfa-machine")
  File "/home/REDACTED/REDACTED/REDACTED/_virtual_envs/home/REDACTED/lib/python3.8/site-packages/jsii/_runtime.py", line 69, in __call__
    inst = super().__call__(*args, **kwargs)
  File "/home/REDACTED/REDACTED/REDACTED_stack.py", line 58, in __init__
    edge_lambda = cf.EdgeLambda(
TypeError: __init__() got an unexpected keyword argument 'include_body'
Subprocess exited with error 1

This is :bug: Bug Report

codernaive avatar Sep 05 '20 16:09 codernaive

For what it's worth the following works in TypeScript....

       const function_version = new lamb.Version(
            this,
            'SomeFunctionVersion',
            {
                lambda: lambda_function,
            }
        )

        const edge_lambda: EdgeLambda = {
            eventType: cf.LambdaEdgeEventType.VIEWER_REQUEST,
            functionVersion: function_version,
            includeBody: true,
        }

        const distribution = new cf.Distribution(
            this,
            id,
            {
                httpVersion: cf.HttpVersion.HTTP2,
                defaultRootObject: 'index.html',
                defaultBehavior: {
                    origin: new origins.S3Origin(bucket),
                    compress: true,
                    viewerProtocolPolicy: cf.ViewerProtocolPolicy.REDIRECT_TO_HTTPS,
                    edgeLambdas: [
                        edge_lambda,
                    ]
                }
            }
        )

codernaive avatar Sep 06 '20 18:09 codernaive

Thanks for the bug report, @ekeyser .

Unfortunately, I'm not able to reproduce this with cdk 1.62. I suspect that while at least one installed package is at 1.62, the aws-cdk.aws_cloudfront package is at some previous version. Can you double-check the versions you have installed (e.g., ls .env/lib/python3.8/site-packages | grep aws_cdk from your package root)?

njlynch avatar Sep 07 '20 08:09 njlynch

Yep I guess that was it. Looks like my virtualenv site-packages were still at 1.61.1. Tried running pip install -r requirements.txt --upgrade and of course that did nothing because nothing with pip has ever seemed to work like you would expect. Deleted all the aws-cdk site packages and ran pip install -r requirements.txt and it pulled the latest 1.62. cdk synth then ran correctly.

codernaive avatar Sep 07 '20 13:09 codernaive