CDK IoT在documentParameters和AWS托管模板上创建作业无法正常工作。

0

【以下的问题经过翻译处理】 您好, 这个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

1 Answer
0

【以下的回答经过翻译处理】 嗨,Gary。我不确定这是否是问题,但在CDK中,您在jobTemplateArn中有一个账号,我认为它不应该在那里。

profile picture
EXPERT
answered 5 months ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions