AWS SDK v2 and SSM session
Hi there, and thanks for having me here, this is my first post and I expect is not going to be the last.
ssmSocatCommand := fmt.Sprintf(`
socat -v TCP-LISTEN:0,fork,reuseaddr TCP:%s.mq.us-east-1.amazonaws.com:443 &
SOCAT_PID=”$!”
SOCAT_PORT=$(netstat -putona | grep $SOCAT_PID | awk ‘{print $4}’ | cut -d’:’ -f2)
echo “SOCAT PID: $SOCAT_PID”
echo “SOCAT PORT: $SOCAT_PORT”
`, ID)
startSessionInput := &ssm.StartSessionInput{
DocumentName: aws.String(“AWS-StartNonInteractiveCommand”),
Target: aws.String(bastionID),
Parameters: map[string][]string{“command”: {ssmSocatCommand}},
}
responseStartSession, err := ssmClient.StartSession(ctx, startSessionInput)
if err != nil {
return
}
sessionID := responseStartSession.SessionId
fmt.Println(*sessionID)
filterSessionInput := []ssmTypes.SessionFilter{
{
Key: ssmTypes.SessionFilterKeySessionId,
Value: sessionID,
},
}
describeSessionsInput := &ssm.DescribeSessionsInput{
State: ssmTypes.SessionStateActive,
Filters: filterSessionInput,
}
responseDescribeSessions, err := ssmClient.DescribeSessions(ctx, describeSessionsInput)
if err != nil {
log.Fatal(err)
}
if len(responseDescribeSessions.Sessions) > 0 {
session := responseDescribeSessions.Sessions[0]
fmt.Printf(“Details: %v\n”, *session.Details)
fmt.Printf(“DocumentName: %v\n”, *session.DocumentName)
fmt.Printf(“EndDate: %v\n”, session.EndDate)
fmt.Printf(“MaxSessionDuration: %v\n”, session.MaxSessionDuration)
fmt.Printf(“OutputUrl: %v\n”, session.OutputUrl)
fmt.Printf(“Owner: %v\n”, *session.Owner)
fmt.Printf(“Reason: %v\n”, session.Reason)
fmt.Printf(“SessionId: %v\n”, *session.SessionId)
fmt.Printf(“StartDate: %v\n”, session.StartDate)
fmt.Printf(“Status: %v\n”, session.Status)
fmt.Printf(“Target: %v\n”, *session.Target)
}
}
The problem is that it seems that with `Start-Session` I’m not able to get the output, and I’ve some questions:
Read more here: Source link