【以下的问题经过翻译处理】 您好,
这个CLI命令可以从AWS托管模板创建作业:
$ 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"}'
但是,这个看似等价的CDK自定义资源无法工作。CDK部署返回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,
}),
});
非常感谢,Gary