Skip to content

Instantly share code, notes, and snippets.

@nidhi-ag
Created April 13, 2022 06:17
Show Gist options
  • Save nidhi-ag/abb16655e152b5bdbea64e64b9028275 to your computer and use it in GitHub Desktop.
Save nidhi-ag/abb16655e152b5bdbea64e64b9028275 to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/ssm"
"strings"
)
const awsRegion = "ap-south-1"
const subStringToMatch = "substring"
func main() {
sess, err := session.NewSessionWithOptions(session.Options{
Config: aws.Config{Region: aws.String(awsRegion)},
SharedConfigState: session.SharedConfigEnable,
})
if err != nil {
panic(err)
}
ssmsvc := ssm.New(sess, aws.NewConfig().WithRegion(awsRegion))
var NextToken *string
for {
result, err := ssmsvc.GetParametersByPath(&ssm.GetParametersByPathInput{
MaxResults: aws.Int64(10),
Path: aws.String("/"),
Recursive: aws.Bool(true),
WithDecryption: aws.Bool(true),
NextToken: NextToken,
})
if err != nil {
fmt.Println(err)
}
NextToken = result.NextToken
params := result.Parameters
for _, p := range params {
name := *p.Name
value := *p.Value
if strings.Contains(value, subStringToMatch) {
fmt.Println("Key with " + subStringToMatch + " " + name)
}
}
if NextToken == nil {
break
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment