aws / aws-cdk

The AWS Cloud Development Kit is a framework for defining cloud infrastructure in code
https://aws.amazon.com/cdk
Apache License 2.0
11.71k stars 3.93k forks source link

Escape hatches: Go Lang Support #31897

Open toyotest2 opened 1 month ago

toyotest2 commented 1 month ago

Describe the feature

Request: Escape hatches: Go Lang Support

I could not find any Go language samples in the documentation below. https://docs.aws.amazon.com/cdk/v2/guide/cfn_layer.html

Additionally, I found the following comments at the workshop.

https://catalog.us-east-1.prod.workshops.aws/workshops/d93fec4c-fb0f-4813-ac90-758cb5527f2f/en-US/walkthrough/go/sample/source-construct/s3-bucket

CDK has a concept called the [escape hatch ](https://docs.aws.amazon.com/cdk/latest/guide/cfn_layer.html)
, which allows you to modify an L2 construct's underlying CFN Resource to access features that are supported by CloudFormation but not yet supported by CDK. Unfortunately, CDK for Go does not yet support this functionality, so we have to create the resource through the L1 construct. See [this GitHub issue ](https://github.com/aws/jsii/issues/2819)
for more information and to follow progress on support for CDK escape hatches in Go.

Use Case

For Customize L2/L3 Constructs in Go Lang.

Proposed Solution

No response

Other Information

No response

Acknowledgements

CDK version used

2.162.1

Environment details (OS name and version, etc.)

Cloud9AmazonLinux2023-2024-10-21T21-56

khushail commented 1 month ago

Hi @toyotest2 , thanks for reaching out and linking the related docs available. I found this issue mentioned in the workshop doc which was further fixed by the PR.

Considering the usecase, it would be helpful to have the mentioned support for GO as well. Marking the issue as P2 as L2 constructs are available. P2 would mean it would not be immediately addressed by the team but would be on their radar.

gshpychka commented 3 weeks ago

Although I'm very surprised that missing Go support for L1 would be a P2 issue (considering there's no workaround), L1 resources are fully supported in Go as far as I understand, and escape hatches work with jsii.UnsafeCast. Am I missing something?

khushail commented 3 weeks ago

Hi @gshpychka , I understand your point of view here. I marked it as P2 as escape hatches are available in other languages and I am not sure supporting this for GO is on the team roadmap.

I would reach out to team on this if they have this in their future action items or something to be considered a priority.

gshpychka commented 3 weeks ago

I am not sure supporting L1 construct for GO is on the team roadmap.

My understanding is that it's already supported, but I may be missing something.

khushail commented 3 weeks ago

Let me recheck the docs and get back as I am not very familiar with GO language and the provided support by CDK or cloudformation. Apologies for the confusion there.

khushail commented 3 weeks ago

Hey @gshpychka , thanks for double checking and sharing your insights here.

The Go constructs and way of usage are very different and I think I got stumped by that, my bad. It is correct in saying the L1 constructs support as well Escape hatch support is already there, however we need to provide better samples for the GO CDK usage in the docs.

Sharing the CDK GO construct and props ref.

Constructs, which represent one or more AWS resources and their associated attributes, are represented in Go as interfaces

So let me clarify a bit on my earlier statements as per my understanding -

First, CDK has  L2 Construct that allows you to build resources according to best practices by simply specifying a few required values.

L2 constructs are built on L1 construct with abstraction, which allows you to build resources by specifying them in a manner consistent with CloudFormation.

While L2 Construct is convenient and easy to create resources, it also abstracts parameters, so there are some parameters that might not be specified in L2.

Therefore, Escape Hatch come into picture - these provide a way to cast a resource created with L2 Construct to an L1 Construct type and later override the parameters that can only be specified with L1.

but its mentioned in the workshop page -

However, the CDK for Go does not currently support escape hatch according to [the workshop](https://catalog.us-east-1.prod.workshops.aws/workshops/d93fec4c-fb0f-4813-ac90-758cb5527f2f/en-US/walkthrough/go/sample/source-construct/s3-bucket).

which seems confusing but the issue mentioned in above workshop also seems to be resolved and implemented. Also given that PR and its implementation , it makes sense to have its support by jsii.UnsafeCast (though it might not be applicable in every service parameter scenario). I found an article on Escape hatch support for CDK GO, please feel free to check this out - https://www.go-on-aws.com/infrastructure-as-go/cdk-go/escape-hatches/

So in a nutshell. yes Escape hatches are there.

and here is a complete Dev guide of CDK with GO language for the reference - https://pkg.go.dev/github.com/aws/aws-cdk-go/awscdk/v2

khushail commented 3 weeks ago

@toyotest2 , as better examples could be provided in case of GO CDK, I would submit the page feedback which is located on the top right corner. And also adding documentation label to this issue.

@gshpychka , hope that makes sense! Thanks for the correction!