I am trying to execute a shell script on an EC2 instance using SSM. When using the AWS CLI it works as expected, but when using the AWS Java SDK 2.x it fails because it says the AWS-RunShellScript document does not support parameters.
This simple test works using the AWS CLI:
aws ssm send-command --document-name "AWS-RunShellScript" --instance-ids <instance ID> --parameters '{"commands":["mkdir test"]}'
However the following Java code using the AWS 2.x SDK:
final Map<String, Collection<String>> parameters = ImmutableMap.<String, Collection<String>>builder()
.put("commands", List.of("mkdir test"))
.build();
final SendCommandRequest commandRequest = SendCommandRequest.builder()
.documentName("AWS-RunShellScript")
.instanceIds(<instance ID>)
.parameters(parameters)
.build();
final SendCommandResponse commandResponse = ssmClient.sendCommand(commandRequest);
fails with the following exception:
software.amazon.awssdk.services.ssm.model.InvalidParametersException: document AWS-RunShellScript does not support parameters. (Service: Ssm, Status Code: 400, Request ID: <request ID>)
It’s not clear to me why this document accepts parameters using the AWS CLI but not the AWS Java SDK. Any help would be appreciated.