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

(@aws-cdk/aws-cloudfront): Go Binding for CloudFront Function Synth Fails #15007

Closed
trevorrobertsjr opened this issue Jun 6, 2021 · 5 comments
Assignees
Labels
@aws-cdk/aws-cloudfront Related to Amazon CloudFront bug This issue is a bug. needs-triage This issue or PR still needs to be triaged.

Comments

@trevorrobertsjr
Copy link

trevorrobertsjr commented Jun 6, 2021

When attempting to run cdk synth for a CloudFront Function deployment with the CDK Go support, I get an error requesting comment and runtime properties that I do provide:

panic: "Resolution error: Supplied properties not correct for \"CfnFunctionProps\"\n  functionConfig: supplied properties not correct for \"FunctionConfigProperty\"\n    comment: required but missing\n    runtime: required but missing."

Reproduction Steps

	awscloudfront.NewCfnFunction(stack, jsii.String("myCDKFunction"), &awscloudfront.CfnFunctionProps{
		Name:         jsii.String("myCfnFunctionCdk"),
		FunctionCode: jsii.String(myFunctionCode),
		AutoPublish:  jsii.Bool(true),
		FunctionConfig: &awscloudfront.CfnFunction_FunctionConfigProperty{
			Comment: jsii.String("testcdk"),
			Runtime: jsii.String("cloudfront-js-1.0"),
		},
	})

What did you expect to happen?

I expect cdk.out to contain generated CloudFormation JSON similar to the following template:

{
    "Resources": {
      "myCDKFunction": {
        "Type": "AWS::CloudFront::Function",
        "Properties": {
          "Name": "whyfunccdk",
          "AutoPublish": true,
          "FunctionConfig": {
            "Comment" : "will this work",
            "Runtime" : "cloudfront-js-1.0"
          },
          "FunctionCode": "function handler(event) {\n\t\tvar request = event.request;\n\t\tvar uri = request.uri;\n\t\n\t\t// Check whether the URI is missing a file name.\n\t\tif (uri.endsWith('/')) {\n\t\t\trequest.uri += 'index.html';\n\t\t}\n\t\t// Check whether the URI is missing a file extension.\n\t\telse if (!uri.includes('.')) {\n\t\t\trequest.uri += '/index.html';\n\t\t}\n\t\treturn request;\n\t}"
        },
        "Metadata": {
          "aws:cdk:path": "HelloCdkGoStackCfnFunc/myCDKFunction"
        }
      }
    }
}

What actually happened?

cdk synth fails to complete

Environment

  • CDK CLI Version : 1.107 and 2.0 rc6
  • Framework Version:
  • Node.js Version: v15.11.0
  • **OS :Big Sur
  • **Language (Version):**go1.16.3

Other


This is 🐛 Bug Report

@trevorrobertsjr trevorrobertsjr added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Jun 6, 2021
@github-actions github-actions bot added the @aws-cdk/aws-cloudfront Related to Amazon CloudFront label Jun 6, 2021
@hoegertn
Copy link
Contributor

hoegertn commented Jun 6, 2021

Can you try it out with the CloudFront Functions L2 construct? So we can see if it breaks in the L1 or somewhere else.

@trevorrobertsjr
Copy link
Author

Thank you for the reply @hoegertn. I will try looking for the CloudFront Functions L2 support in the Go bindings and try again today.

@trevorrobertsjr
Copy link
Author

Thank you for the suggestion. CDK 2.0.0 rc6 did not have L2 constructs for CloudFront Functions (at least, I could not find them). My code worked after I changed back to CDK 1.0.7 and used the L2 construct syntax (i.e. newFunction instead of NewCfnFunction). There were differences in the syntax between the L1 and L2 functions, and I adjusted accordingly for the deploy to succeed.

Any ideas why the code was not accepting the parameters that I was specifying? In Visual Studio Code, it did not indicate any errors with my original code.

@njlynch
Copy link
Contributor

njlynch commented Jun 11, 2021

I think this might be a bug in jsii that's Go-specific. I filed an issue aws/jsii#2880 to track it. Please track the resolution there.

In the meantime, CDK 2.0.0 rc7 has the Function L2, which does work:

awscloudfront.NewFunction(stack, jsii.String("myCDKFunction"), &awscloudfront.FunctionProps{
  Code: awscloudfront.FunctionCode_FromInline(jsii.String("hello world")),
})

@njlynch njlynch closed this as completed Jun 11, 2021
@github-actions
Copy link

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

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 bug This issue is a bug. needs-triage This issue or PR still needs to be triaged.
Projects
None yet
Development

No branches or pull requests

3 participants