Skip to content

Go SDK v2 migration#1247

Open
raleycs wants to merge 2 commits intoaws-samples:mainfrom
raleycs:go-sdk-v2-migration
Open

Go SDK v2 migration#1247
raleycs wants to merge 2 commits intoaws-samples:mainfrom
raleycs:go-sdk-v2-migration

Conversation

@raleycs
Copy link
Copy Markdown

@raleycs raleycs commented Mar 23, 2026

Migrate Go examples from AWS SDK v1 to v2

The AWS SDK for Go v1 reached end-of-support on July 31, 2025. This PR migrates all Go examples off the v1 SDK and addresses related deprecations.

Fixes #1063

Changes

AWS SDK v1 → v2 migration

lambda-dynamodb/lambda-handler/main.go — Full handler migration:

  • session.Must(session.NewSessionWithOptions(...))config.LoadDefaultConfig(ctx)
  • dynamodb.New(sess)dynamodb.NewFromConfig(cfg)
  • dynamodbattribute.MarshalMap()attributevalue.MarshalMap() (from feature/dynamodb/attributevalue)
  • svc.PutItem(input)svc.PutItem(ctx, input) (v2 requires context)

lambda-dynamodb/lambda-dynamodb.go and rekognition-lambda-s3-trigger/rekognition-lambda-s3-trigger.go — Both imported the v1 aws package solely for aws.String() pointer helpers in CDK code. Replaced with jsii.String() (already imported). Also replaced aws.StringValue() with direct pointer dereference in rekognition example.

Deprecated go1.x Lambda runtime → provided.al2023

AWS deprecated the go1.x Lambda runtime. Updated two examples that still used it:

  • lambda-dynamodbRuntime_GO_1_X()Runtime_PROVIDED_AL2023()
  • httpapi-lambdaRuntime_GO_1_X()Runtime_PROVIDED_AL2023()

Test assertions updated to match ("go1.x""provided.al2023").

CDK version bumps → v2.118.0

Five examples were bumped from v2.38.0 to v2.118.0. The first two needed Runtime_PROVIDED_AL2023 (not available in older CDK). The remaining three needed the bump to remove dead alpha dependencies or fix breaking API changes:

  • lambda-dynamodb
  • httpapi-lambda
  • step-functions
  • cognito-httpapi
  • httpapi-eventbridge

Dead alpha module migration (cognito-httpapi, httpapi-eventbridge)

Both examples depended on awscdkapigatewayv2alpha/v2, which stopped publishing at v2.114.1-alpha.0 after API Gateway v2 constructs graduated to stable aws-cdk-lib. Migrated to the stable awscdk/v2/awsapigatewayv2 module:

  • awscdkapigatewayv2alpha.NewHttpApiawsapigatewayv2.NewHttpApi
  • awscdkapigatewayv2alpha.NewHttpAuthorizerawsapigatewayv2.NewHttpAuthorizer
  • awscdkapigatewayv2alpha.CorsHttpMethodawsapigatewayv2.CorsHttpMethod
  • All other alpha type references updated to their stable equivalents

Step functions API update (step-functions)

The Choice.When() signature changed in newer CDK versions to require a third *ChoiceTransitionOptions parameter. Added nil to both .When() calls. Also migrated from the deprecated Definition field to DefinitionBody: DefinitionBody_FromChainable(definition).

Test fixes

Updated Template_FromStack calls to include the required nil second parameter (*TemplateParsingOptions) in five examples: lambda-dynamodb, httpapi-lambda, step-functions, cognito-httpapi, httpapi-eventbridge.

Stale dependency cleanup

  • Removed github.com/aws/aws-cdk-go/awscdk v1.198.1-devpreview (CDK v1) and constructs/v3 indirect dependencies from ec2-instance/go.mod
  • Removed github.com/aws/aws-sdk-go from lambda-dynamodb/go.mod and rekognition-lambda-s3-trigger/go.mod
  • Removed github.com/aws/aws-cdk-go/awscdkapigatewayv2alpha/v2 from cognito-httpapi/go.mod and httpapi-eventbridge/go.mod

Go version bump

Bumped go directive from 1.161.22 to 1.24 across all Go examples. AWS SDK for Go v2 requires Go 1.24 minimum per its go.mod and README. Ran go mod tidy on all modules.

Testing

Local validation (all 26 Go modules)

Check Scope Result
go build ./... All 26 modules ✅ All pass
go test ./... 22 modules with test files 16 pass, 6 pre-existing failures (see notes)

Deployed to AWS account

All six examples with source code changes were deployed and tested:

Example Deploy Functional test
lambda-dynamodb Y Lambda invoked, item written to DynamoDB via v2 SDK
httpapi-lambda Y HTTP GET returned {"greeting":"hello world!"}
rekognition-lambda-s3-trigger Y S3 upload triggered Rekognition, labels written to DynamoDB
step-functions Y Execution SUCCEEDED through submit → wait → status → choice → succeed
cognito-httpapi Y HTTP API + JWT Authorizer + Cognito User Pool created, auth login page returns 200
httpapi-eventbridge Y POST returned 200, event delivered to EventBridge, logged in CloudWatch

Notes

Broken tests (not addressed in this PR but they already existed)

  • ec2-instance — Test asserts AWS::SQS::Queue and AWS::SNS::Topic exist, but the stack creates an EC2 instance.
  • eventbridge-sqs, restapi-sqs, cognito-httpapi, httpapi-eventbridge — Tests don't set AWS_DEFAULT_REGION env var, causing CDK to panic with Unable to parse environment specification. The stacks' env() functions read os.Getenv("AWS_DEFAULT_REGION"). Stacks deploy fine when the env var is set.
  • httpapi-lambdaTemplate_FromStack call uses old signature (missing second parameter) against the pinned CDK v2.118.0.
  • eks/cluster-graviton — Test expects EKS version 1.32 but stack hardcodes 1.31.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

raleycs added 2 commits March 23, 2026 14:10
Migrate all Go examples off the end-of-support AWS SDK for Go v1.

- Migrate lambda-dynamodb handler to v2 SDK: replace session,
  dynamodb, and dynamodbattribute with config, dynamodb, and
  feature/dynamodb/attributevalue
- Replace v1 aws.String()/aws.StringValue() with jsii.String() and
  pointer dereference in lambda-dynamodb and rekognition CDK code
- Update deprecated go1.x Lambda runtime to provided.al2023 in
  lambda-dynamodb and httpapi-lambda
- Bump lambda-dynamodb CDK dep from v2.38.0 to v2.118.0 for
  PROVIDED_AL2023 support, fix Template_FromStack test signature
- Remove stale CDK v1 and constructs/v3 deps from ec2-instance
- Bump minimum Go version to 1.23 across all Go examples

Closes aws-samples#1063
@raleycs
Copy link
Copy Markdown
Author

raleycs commented Mar 23, 2026

Sorry for the loaded PR, but most of it comes from the go.mod's and go.sum's. Happy to break it up if it's easier to review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Update GO CDK example to use AWS SDK for GO v2 constructs from v1

1 participant