DEV Community

Cover image for First surprising Contact with ChatGP: Can it solve simple AWS SDK tasks?
Gernot Glawe
Gernot Glawe

Posted on

First surprising Contact with ChatGP: Can it solve simple AWS SDK tasks?

I heard so many things, so I wanted to give https://chat.openai.com/chat a GO.

Can it help me in programming or even replace me?

My question:

"show me the code to list all CloudFormation stack names in an AWS account in GO with SDK v2 in clean code"

Chat

Does the code work out of the box?

Short answer: No.
But it would save me google search time.

What did I have to change?

A surprisingly small amount of code:

diff --git a/main.go b/main.go
index 01d6286..2b02055 100644
--- a/main.go
+++ b/main.go
@@ -4,34 +4,33 @@ import (
        "context"
        "fmt"

-       "github.com/aws/aws-sdk-go-v2/config"
+       "github.com/aws/aws-sdk-go-v2/aws"
        "github.com/aws/aws-sdk-go-v2/service/cloudformation"
-       "github.com/aws/aws-sdk-go-v2/service/cloudformation/types"
 )

 func main() {
        // Initialize the AWS configuration
-       cfg, err :=  config.LoadDefaultConfig(context.Background())
+       cfg, err := aws.NewConfig()
        if err != nil {
                panic("Unable to create AWS configuration: " + err.Error())
        }

        // Create a new CloudFormation client
-       cfnSvc := cloudformation.NewFromConfig(cfg)
+       cfnSvc := cloudformation.New(cfg)

        // Set up the input parameters for the ListStacks API call
        input := &cloudformation.ListStacksInput{
-               StackStatusFilter: []types.StackStatus{
-                       types.StackStatusCreateComplete,
... some more states
-                       types.StackStatusRollbackFailed,
-                       types.StackStatusUpdateComplete,
-                       types.StackStatusUpdateRollbackComplete,
-                       types.StackStatusUpdateRollbackFailed,
+               StackStatusFilter: []cloudformation.StackStatus{
+                       cloudformation.StackStatusCreateComplete,
+                       cloudformation.StackStatusUpdateRollbackFailed,
                },
        }
Enter fullscreen mode Exit fullscreen mode

So with a few commands and some patches:

go mod init test1
vi main.go
go mod tidy
go run main.go
Enter fullscreen mode Exit fullscreen mode

It worked!

Conclusion

Indeed something to watch in the future!
Try https://chat.openai.com/

Thanks

Photo by Thomas Park on Unsplash

And ChatGP.

Image of Datadog

Create and maintain end-to-end frontend tests

Learn best practices on creating frontend tests, testing on-premise apps, integrating tests into your CI/CD pipeline, and using Datadog’s testing tunnel.

Download The Guide

Top comments (0)

AWS Security LIVE!

Join us for AWS Security LIVE!

Discover the future of cloud security. Tune in live for trends, tips, and solutions from AWS and AWS Partners.

Learn More

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay