How so send arguments to SSM? #3984
-
So I am triggering a command remotely on an EC2 instance from a lambda function using SSM in Node Typescript. However, it is not working because I cannot pass an argument to the SSM Document in the invocation. This is what I am trying to do: const SSM = new SSMClient({ region: "us-east-1" });
const targetCD = target + " prod";
const sendCCParams = {
DocumentName: 'deepblue_userflow_initiator',
InstanceIds: ['i-0xxxxxxxxxxxxe'],
Message: targetCD
}
const sendCC = new SendCommandCommand(sendCCParams);
const sendCCResponse = await SSM.send(sendCC); but the However parameters is And my document specifies it as: {
"schemaVersion": "2.2",
"description": "Initiates the deepblue-userflow controller with audit parameters",
"parameters": {
"Message": {
"type": "String",
"description": "Example",
"default": "https://deep-blue.io prod"
}
},
"mainSteps": [
{
"action": "aws:runShellScript",
"name": "example",
"inputs": {
"runCommand": [
"cd / && cd home/ec2-user && . .nvm/nvm.sh && cd ufo && node conductor {{Message}}"
]
}
}
]
} Any time I try to pass parameters I get a How can I pass the parameter like in the GUI using the AWS JS SSM SDK? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
Hi @ChristopherPHolder, thanks for opening this discussion. According with the documentation, the parameter of the request that is used to send the parameters defined in the document to be ran is "Parameters?: Record<string, string[]>". Basically, SDK does not know the name of the parameters that are defined in the documents, and therefore you need to specify them when building the request/command. For example, lets say your document definition looks as below: {
"schemaVersion": "2.2",
"description": "Testing parameters",
"parameters": {
"Parameter1": {
"type": "String",
"description": "Example",
"default": ""
},
"Parameter2": {
"type": "String",
"description": "Example",
"default": ""
}
},
"mainSteps": [
{
"action": "ACTION",
"name": "example",
"inputs": {
"runCommand": [
"COMMAND TO RUN"
]
}
}
]
} Then, you should provide those parameters as follow: const sendCC = new SendCommandCommand({
DocumentName: 'DOCUMENT-NAME',
InstanceIds: ['INSTANCE-ID'],
Parameters: {
Parameter1: ["values for parameter 1"],
Parameter2: ["values for parameter 2"]
}
}); Please see below a working example sending a parameter "Message": import {SSMClient, SendCommandCommand} from "@aws-sdk/client-ssm";
const SSM = new SSMClient({ region: "us-east-1" });
const target = 'target';
const targetCD = target + " prod";
const sendCC = new SendCommandCommand({
DocumentName: 'deepblue_userflow_initiator',
InstanceIds: [''],
Parameters: {
Message: [targetCD]
}
});
const sendCCResponse = await SSM.send(sendCC);
console.log(sendCCResponse); Thanks! |
Beta Was this translation helpful? Give feedback.
-
Hello! Reopening this discussion to make it searchable. |
Beta Was this translation helpful? Give feedback.
Hi @ChristopherPHolder, thanks for opening this discussion. According with the documentation, the parameter of the request that is used to send the parameters defined in the document to be ran is "Parameters?: Record<string, string[]>". Basically, SDK does not know the name of the parameters that are defined in the documents, and therefore you need to specify them when building the request/command. For example, lets say your document definition looks as below: