I'm trying to use SSM with Go AWS SDK. I have valid IAM User credentials stored in the credentials file. The file and the credentials are good because, it behaves as expected when
aws ssm start-session --target "instanceid"
But the problem is with Go SDK. I tried v1 and v2 both.
sdk v1
mySession := session.Must(session.NewSession())
svc := ssm.New(mySession, aws.NewConfig().WithRegion("ap-southeast-1"))
out, err := svc.StartSession(&ssm.StartSessionInput{Target: aws.String(instanceId)})
if err != nil {
log.Fatalf("error starting ssm : %v", err)
}
and v2
cfg, err := external.LoadDefaultAWSConfig()
if err != nil {
panic("unable to load SDK config, " + err.Error())
}
svc := ssm.New(cfg)
req := svc.StartSessionRequest(&ssm.StartSessionInput{
Target: aws.String(instanceId),
})
resp, _ := req.Send(context.Background())
if err != nil {
log.Fatalf("error sending ssm request : %v", err)
}
fmt.Println(resp)
give an error saying.
UnrecognizedClientException: The security token included in the request is invalid.
The credentials get loaded to the config objects also. I was wondering if its because I'm using IAM User credentials.
export AWS_PROFILE="default"
also – Eklavya.aws/credentials
for default may be. – Eklavya