startSession method
Initiates a connection to a target (for example, a managed node) for a Session Manager session. Returns a URL and token that can be used to open a WebSocket connection for sending input and receiving outputs.
Amazon Web Services Tools for PowerShell usage: Start-SSMSession isn't currently supported by Amazon Web Services Tools for PowerShell on Windows local machines.
May throw InternalServerError.
May throw InvalidDocument.
May throw TargetNotConnected.
Parameter target :
The managed node to connect to for the session.
Parameter documentName :
The name of the SSM document you want to use to define the type of
session, input parameters, or preferences for the session. For example,
SSM-SessionManagerRunShell. You can call the
GetDocument API to verify the document exists before attempting to
start a session. If no document name is provided, a shell to the managed
node is launched by default. For more information, see Start
a session in the Amazon Web Services Systems Manager User
Guide.
Parameter parameters :
The values you want to specify for the parameters defined in the Session
document. For more information about these parameters, see Create
a Session Manager preferences document in the Amazon Web Services
Systems Manager User Guide.
Parameter reason :
The reason for connecting to the instance. This value is included in the
details for the Amazon CloudWatch Events event created when you start the
session.
Implementation
Future<StartSessionResponse> startSession({
required String target,
String? documentName,
Map<String, List<String>>? parameters,
String? reason,
}) async {
final headers = <String, String>{
'Content-Type': 'application/x-amz-json-1.1',
'X-Amz-Target': 'AmazonSSM.StartSession'
};
final jsonResponse = await _protocol.send(
method: 'POST',
requestUri: '/',
exceptionFnMap: _exceptionFns,
// TODO queryParams
headers: headers,
payload: {
'Target': target,
if (documentName != null) 'DocumentName': documentName,
if (parameters != null) 'Parameters': parameters,
if (reason != null) 'Reason': reason,
},
);
return StartSessionResponse.fromJson(jsonResponse.body);
}