DEV Community

Gernot Glawe
Gernot Glawe

Posted on

Migrating to AWS CDK v2 - the missing GO manual

I like using GO, so I use AWS CDK in the new GO flavour also.

AWS has now released the AWS CDK v2 and nicely documented how to upgrade TypeScript, JavaScript, Python, Java and C#.

See AWS Docu.

The GO part is missing ...

Trying cdk ls on a GO CDK app will get you:

cdk ls
This CDK CLI is not compatible with the CDK library used by your application. Please upgrade the CLI to the latest version.
(Cloud assembly schema version mismatch: Maximum schema version supported is 9.0.0, but found 10.0.0)
Enter fullscreen mode Exit fullscreen mode

Here is the fix:

1 - Change AWS CDK import

 import (


-       "github.com/aws/aws-cdk-go/awscdk"
+       "github.com/aws/aws-cdk-go/awscdk/v2"
 )
Enter fullscreen mode Exit fullscreen mode

2 - Change construct imports

   import (
-       "github.com/aws/aws-cdk-go/awscdk"
-       "github.com/aws/aws-cdk-go/awscdk/awsssm"
+       "github.com/aws/aws-cdk-go/awscdk/v2"
+       "github.com/aws/aws-cdk-go/awscdk/v2/awsssm"
)
Enter fullscreen mode Exit fullscreen mode

3 Change Constructs Programming Model import:


   import (

-       "github.com/aws/constructs-go/constructs/v3"
+       "github.com/aws/constructs-go/constructs/v10"
 )
Enter fullscreen mode Exit fullscreen mode

4 - delete some feature flags in cdk.json

E.g. if you get

panic: "Unsupported feature flag '@aws-cdk/core:enableStackNameDuplicates'. This flag existed on CDKv1 but has been removed in CDKv2. CDK will now behave as the same as when the flag is enabled."
Enter fullscreen mode Exit fullscreen mode

Delete the line in cdk.json

5 - Update to new modules

go mod tidy
Enter fullscreen mode Exit fullscreen mode

6 - Pinpoint cdk version

Instead of installing cdk globally (npm i cdk -g) you may use a specific version of the cdk with

npx cdk@2.0.0-rc.1 ls
Enter fullscreen mode Exit fullscreen mode

Without prior installation.

7 - Use aws sdk pointer building instead of jsii

Instead of

    cluster := ecs.NewCluster(stack, jsii.String("ALBFargoECSCluster"),...
Enter fullscreen mode Exit fullscreen mode

use

    cluster := ecs.NewCluster(stack, 
aws.String("ALBFargoECSCluster"), ...
Enter fullscreen mode Exit fullscreen mode

With the import of

"github.com/aws/aws-sdk-go-v2/aws"
Enter fullscreen mode Exit fullscreen mode

Here I GO again

That fixed it for me!

Hope this will help you.

For a chat - contact me on twitter @megaproaktiv

Top comments (0)