Open
Conversation
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
Author
|
Sorry for the loaded PR, but most of it comes from the |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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()(fromfeature/dynamodb/attributevalue)svc.PutItem(input)→svc.PutItem(ctx, input)(v2 requires context)lambda-dynamodb/lambda-dynamodb.goandrekognition-lambda-s3-trigger/rekognition-lambda-s3-trigger.go— Both imported the v1awspackage solely foraws.String()pointer helpers in CDK code. Replaced withjsii.String()(already imported). Also replacedaws.StringValue()with direct pointer dereference in rekognition example.Deprecated
go1.xLambda runtime →provided.al2023AWS deprecated the
go1.xLambda runtime. Updated two examples that still used it:lambda-dynamodb—Runtime_GO_1_X()→Runtime_PROVIDED_AL2023()httpapi-lambda—Runtime_GO_1_X()→Runtime_PROVIDED_AL2023()Test assertions updated to match (
"go1.x"→"provided.al2023").CDK version bumps →
v2.118.0Five examples were bumped from
v2.38.0tov2.118.0. The first two neededRuntime_PROVIDED_AL2023(not available in older CDK). The remaining three needed the bump to remove dead alpha dependencies or fix breaking API changes:lambda-dynamodbhttpapi-lambdastep-functionscognito-httpapihttpapi-eventbridgeDead alpha module migration (
cognito-httpapi,httpapi-eventbridge)Both examples depended on
awscdkapigatewayv2alpha/v2, which stopped publishing atv2.114.1-alpha.0after API Gateway v2 constructs graduated to stableaws-cdk-lib. Migrated to the stableawscdk/v2/awsapigatewayv2module:awscdkapigatewayv2alpha.NewHttpApi→awsapigatewayv2.NewHttpApiawscdkapigatewayv2alpha.NewHttpAuthorizer→awsapigatewayv2.NewHttpAuthorizerawscdkapigatewayv2alpha.CorsHttpMethod→awsapigatewayv2.CorsHttpMethodStep functions API update (
step-functions)The
Choice.When()signature changed in newer CDK versions to require a third*ChoiceTransitionOptionsparameter. Addednilto both.When()calls. Also migrated from the deprecatedDefinitionfield toDefinitionBody: DefinitionBody_FromChainable(definition).Test fixes
Updated
Template_FromStackcalls to include the requirednilsecond parameter (*TemplateParsingOptions) in five examples:lambda-dynamodb,httpapi-lambda,step-functions,cognito-httpapi,httpapi-eventbridge.Stale dependency cleanup
github.com/aws/aws-cdk-go/awscdk v1.198.1-devpreview(CDK v1) andconstructs/v3indirect dependencies fromec2-instance/go.modgithub.com/aws/aws-sdk-gofromlambda-dynamodb/go.modandrekognition-lambda-s3-trigger/go.modgithub.com/aws/aws-cdk-go/awscdkapigatewayv2alpha/v2fromcognito-httpapi/go.modandhttpapi-eventbridge/go.modGo version bump
Bumped
godirective from1.16–1.22to1.24across all Go examples. AWS SDK for Go v2 requires Go 1.24 minimum per its go.mod and README. Rango mod tidyon all modules.Testing
Local validation (all 26 Go modules)
go build ./...go test ./...Deployed to AWS account
All six examples with source code changes were deployed and tested:
lambda-dynamodbhttpapi-lambda{"greeting":"hello world!"}rekognition-lambda-s3-triggerstep-functionscognito-httpapihttpapi-eventbridgeNotes
Broken tests (not addressed in this PR but they already existed)
ec2-instance— Test assertsAWS::SQS::QueueandAWS::SNS::Topicexist, but the stack creates an EC2 instance.eventbridge-sqs,restapi-sqs,cognito-httpapi,httpapi-eventbridge— Tests don't setAWS_DEFAULT_REGIONenv var, causing CDK to panic withUnable to parse environment specification. The stacks'env()functions reados.Getenv("AWS_DEFAULT_REGION"). Stacks deploy fine when the env var is set.httpapi-lambda—Template_FromStackcall uses old signature (missing second parameter) against the pinned CDKv2.118.0.eks/cluster-graviton— Test expects EKS version1.32but stack hardcodes1.31.By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.