Last active
September 26, 2023 10:36
-
-
Save miguelmota/bd8a5c7942a3587544bcc7cef6bd80de to your computer and use it in GitHub Desktop.
AWS SSM Go SDK parameter store example
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
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" | |
) | |
func main() { | |
sess, err := session.NewSessionWithOptions(session.Options{ | |
Config: aws.Config{Region: aws.String("us-east-1")}, | |
SharedConfigState: session.SharedConfigEnable, | |
}) | |
if err != nil { | |
panic(err) | |
} | |
ssmsvc := ssm.New(sess, aws.NewConfig().WithRegion("us-west-2")) | |
param, err := ssmsvc.GetParameter(&ssm.GetParameterInput{ | |
Name: aws.String("/MyService/MyApp/Dev/DATABASE_URI"), | |
WithDecryption: aws.Bool(false), | |
}) | |
if err != nil { | |
panic(err) | |
} | |
value := *param.Parameter.Value | |
fmt.Println(value) | |
} |
Watch out to check for errors returned at line 23 :)
Is there a way to load a json file as a parameter ?
@yuvrajsingh79 AWS SDK returns parameter as a string, you can then json unmarshal that string into a struct.
@Pitasi thanks, you mean to say that we can store in a json file as a parameter and then fetch it -> unmarshal that string ?
thank you for share this example!
Thank you for sharing this code!
@yuvrajsingh79 I dont think this is intended to work with files on the disk, but you can certainly store json file contents in parameter store and then fetch that.
Thank you for sharing this code example!
Thank you for sharing this mate
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Mee too liked it... Thanks much...