Created
November 6, 2022 14:35
-
-
Save itamararjuan/47859be2e52493e8f31b7032766df2b3 to your computer and use it in GitHub Desktop.
How to use SSM to send and receive command output using aws-sdk SSM client v3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { | |
SSMClient, | |
SendCommandCommand, | |
GetCommandInvocationCommand, | |
} from "@aws-sdk/client-ssm"; | |
// a client can be shared by different commands. | |
const client = new SSMClient({ region: "us-east-2" }); | |
(async function () { | |
const command = new SendCommandCommand({ | |
InstanceIds: ["i-blabla"], | |
DocumentName: "AWS-RunShellScript", | |
Parameters: { | |
commands: ["docker logs fasdfsa213"], | |
}, | |
}); | |
console.log("sending command start"); | |
const response = await client.send(command); | |
console.log("sending command finish"); | |
await new Promise((r) => setTimeout(r, 3 * 1000)); | |
const result = await client.send( | |
new GetCommandInvocationCommand({ | |
InstanceId: "i-blabla", | |
CommandId: response.Command.CommandId, | |
}) | |
); | |
console.log(result.StandardOutputContent); | |
})(); | |
// const params = { | |
// InstanceIds: instanceIdList, | |
// DocumentName: 'AWS-RunShellScript', | |
// Parameters: { | |
// commands: [cmd], | |
// }, | |
// }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment