CDK IoT createJob not working for documentParameters and AWS managed templates

0

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

1 Antwort
1
Akzeptierte Antwort

Hi Gary. I'm not sure it's the issue but in the CDK you have an account number in the jobTemplateArn and I don't think it should be there.

profile pictureAWS
EXPERTE
Greg_B
beantwortet vor einem Jahr
  • 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 defined testDocumentParameters. I changed it to const 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.

Du bist nicht angemeldet. Anmelden um eine Antwort zu veröffentlichen.

Eine gute Antwort beantwortet die Frage klar, gibt konstruktives Feedback und fördert die berufliche Weiterentwicklung des Fragenstellers.

Richtlinien für die Beantwortung von Fragen