Can you use session manager to send a single command and return the output?

0

When using SSH, you can connect to an instance, run a command and disconnect with one command. Such as

ssh user@host.com 'ls -l'

Is this possible with Session Manager? And furthermore, can it be done against a Windows target?

kidbrax
질문됨 4년 전2459회 조회
4개 답변
0

Thanks for reaching out! Yes, Session Manager can be used to run a single interactive command against Windows targets. You can either use Session Manager public document "AWS-StartInteractiveCommand" or create a custom document to run restricted commands. Please refer to the example provided in below documentation and let us know in case of further queries.

https://docs.aws.amazon.com/systems-manager/latest/userguide/session-manager-restrict-command-access.html

답변함 4년 전
0

Thanks, I didn't know that. But I was actually talking about being able to issue a single command that connects to the remote instance and then executes given command on the instance then disconnects. As opposed to issuing the command to start the session and then issuing the given command after being connected.

I was not referring to restricting the user to a single command.

kidbrax
답변함 4년 전
0

Thanks for sharing more details! Interactive Command scenario of Session Manager can be used to run a single or a set of predefined commands and it works by establishing a connection which is disconnected once commands are executed.

Below is a sample StartSession request that would execute the command "echo HelloWorld", display the output and disconnect. Here the command to be executed is passed along with the StartSession request.
aws ssm start-session --target <TARGET_ID> --document-name AWS-StartInteractiveCommand --parameters command="echo HelloWorld"

Another alternative would be to create a custom InteractiveCommands type session document with pre defined commands within the document. Below documentation can be referred for the sample custom document scenario:
https://docs.aws.amazon.com/systems-manager/latest/userguide/session-manager-restrict-command-access.html

Please let us know in case of further queries.

답변함 4년 전
0

That's exactly what I needed. Thank you.

kidbrax
답변함 4년 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠