Hi there, and thanks for having me here, this is my first post and I expect is not going to be the last.
The question is that I've a problem with AWS SDK v2, I'm trying to run a session with a long-running command with SSM Document "AWS-StartNonInteractiveCommand" and get the result and leave it running. Basically is a proxy with port forwarding to an AWS MQ console, like this
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:
- Do I have to get the output with the `StreamUrl`, that's a web socket and from the documentation:
// A URL back to SSM Agent on the managed node that the Session Manager client
// uses to send commands and receive output from the node. Format:
// wss://ssmmessages.region.amazonaws.com/v1/data-channel/session-id?stream=(input|output)
- Do you know any go package that already implement that?
- I see that several packages uses https://github.com/aws/session-manager-plugin directly, is that the easiest way?
- I think that if I use `AWS-RunShellScript` it needs to wait to the command for completion, but I don't want to wait, as it is a long-running command (like 60 minutes or so)
Thanks in advance