Simplifying Input Parameters in Pulumi and AWS CDK Libraries

Pulumi AWS CDK input parameters string pointers

2 min read | by Jordi Prats

Some libraries require you to use string pointers or custom objects for some input parameters, notable examples are Pulumi and AWS CDK. If we only need to provide some static value for it can be annoying to use.

Pulumi

With pulumi we just need to initialize it using one of the constructors it provides, for example, to create a string:

pulumi.String("some string")

We can do the same with an integer:

pulumi.Int(3)

AWS CDK

With AWS CDK there's no difference, we just need to use jsii instead:

jsii.String("some string")

String pointer instead of a String

Some libraries might want you to provide a pointer to a string instead of a string. In case we won't be using it elsewhere, we can always using an unnamed function to create a pointer to the literal like so:

stringPointer := func(inlineString string) *string { return &inlineString }("some string")

Posted on 16/05/2023

Categories