Hi,
This CLI command to create a job from an AWS managed template works:
$ aws iot create-job --targets 'arn:aws:iot:region:account:thing/thingname' --job-id 'test-aws-job' --job-template-arn 'arn:aws:iot:region::jobtemplate/AWS-Run-Command:1.0' --document-parameters '{"command": "ls","runAsUser": "root"}'
but this seemingly equivalent CDK custom resource doesn't. CDK deploy returns Message returned: Document parameters are only supported for managed job templates.
:
const testAwsJobUuid = 'test-aws-job' + uuidv4();
const testDocumentParameters = new Map<string, string>([
["command", "ls"],
["runAsUser", "root"]
]);
const testAwsJob = new cr.AwsCustomResource(this, 'test-aws-job', {
onCreate: {
service: 'Iot',
action: 'createJob',
parameters: {
targets: [`arn:aws:iot:${process.env.CDK_DEFAULT_REGION}:${process.env.CDK_DEFAULT_ACCOUNT}:thing/thingname`],
jobTemplateArn: `arn:aws:iot:${process.env.CDK_DEFAULT_REGION}:${process.env.CDK_DEFAULT_ACCOUNT}:jobtemplate/AWS-Run-Command:1.0`,
documentParameters: testDocumentParameters,
jobId: `${testAwsJobUuid}`
},
physicalResourceId: cr.PhysicalResourceId.of(Date.now().toString()),
},
policy: cr.AwsCustomResourcePolicy.fromSdkCalls({
resources: cr.AwsCustomResourcePolicy.ANY_RESOURCE,
}),
});
Many thanks, Gary
Hi Greg, I removed
${process.env.CDK_DEFAULT_ACCOUNT}
from the CDK and it made a difference! There was also an issue with how I definedtestDocumentParameters
. I changed it toconst testDocumentParameters = { "command": "cd", "runAsUser": "root" };
and it's all good now! Thanks for your support.Glad to hear that Gary. Thanks for the feedback.
You are welcome Greg. Maybe a different error message would help, otherwise, it's all good.