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

Go: demonstrate how to use `CfnParameter` string values

Open jpmcb opened this issue 2 years ago • 0 comments
trafficstars

Describe the feature

Let's say that I have this function

func CreateCluster(stack constructs.Construct, instanceType awscdk.CfnParameter) eks.Cluster {
        cluster := awseks.NewCluster(stack, jsii.String("my-cluster"), &awseks.ClusterProps{ ... })

	cluster.AddNodegroupCapacity(jsii.String("my-nodegroup"), &eks.NodegroupOptions{
		InstanceTypes: &[]ec2.InstanceType{
			ec2.NewInstanceType(instanceType.ValueAsString()),
                }
        })
}

where I want to pass in a cdk parameter.

Doing the above breaks in weird ways:

panic: Error: Malformed instance type identifier

goroutine 1 [running]:

Doing a

fmt.Printf("Instance type: %v\n", instanceType.ValueAsString())

shows that the value at buildtime is actually just a node as a string:

Instance type: ${Token[TOKEN.652]}

What am I missing here? I expected ValueAsString() to just work ™️

Use Case

Having an example of using ValueAsString() would be really useful for passing parameters to Go cdk stacks.

Proposed Solution

No response

Other Information

No response

Acknowledgements

  • [ ] I may be able to implement this feature request
  • [ ] This feature might incur a breaking change

Language

Go

jpmcb avatar May 10 '23 21:05 jpmcb