Provision AWS IoT thing using template and CLI

0

I wanted to use the aws CLI to provision thing devices, using a (edit: pre-written) provisioning template My end goal is to allow devices to self-request any thingname they want.. but for it to be automatically blocked if that name already exists.

Initially I thought I'd use "aws iot register-thing" but that doesnt have an option to specify template. So then I thought I would use

aws iot-data publish $aws/provisioning-templates/templateName/provision/json

but the command complained, "An error occurred (InvalidRequestException) when calling the Publish operation: Topic can't start with $"

So.. what are my options? I'd prefer not to have to use a whole python program for ONE stupid operation.

My underlying motivation, is to be able to use a provisioning cred in a way that it isnt allowed to mess with a thing that already exists.

I was so happy when I found that I supposedly could do all the thing and cert creation stuff from the aws cli. but this is taking the wind out of my sails :(

질문됨 10달 전323회 조회
2개 답변
1

Hi,

perhaps the provisioning exercises from the IoT Device Management workshop might help.

Cheers,
Philipp

AWS
전문가
답변함 10달 전
  • hm. the specific reference you gave, requires having our own CA, which for various reasons, I dont think is going to be viable. Is there a different option I missed somewhere there?

  • Also, I amended my original question, to make clear that I'm looking for a method that will auto-reject already existing thingnames

0

Looking at the AWS CLI documentation, I thought I could use the provisioning template by doing the following.
https://awscli.amazonaws.com/v2/documentation/api/latest/reference/iot/register-thing.html

aws iot register-thing --template-body file:///provisioning-templates/templateName/provision/json

If you get an error when specifying a provisioning template in file format, try passing JSON as a string as is, as shown below.

aws iot register-thing \
    --template-body '{"Parameters":{"ThingName":{"Type":"String"},"AWS::IoT::Certificate::Id":{"Type":"String"}},"Resources": {"certificate":{"Properties":{"CertificateId":{"Ref":"AWS::IoT::Certificate::Id"},"Status":"Active"},"Type":"AWS::IoT::Certificate"},"policy":{"Properties":{"PolicyName":"MyIotPolicy"},"Type":"AWS::IoT::Policy"},"thing":{"OverrideSettings":{"AttributePayload":"MERGE","ThingGroups":"DO_NOTHING","ThingTypeName":"REPLACE"},"Properties":{"AttributePayload":{},"ThingGroups":[],"ThingName":{"Ref":"ThingName"},"ThingTypeName":"VirtualThings"},"Type":"AWS::IoT::Thing"}}}'
profile picture
전문가
답변함 10달 전
  • sorry if my intent wasnt clear: I specifically want to use a PRE-DEFINED template. For security reasons. I dont want the device to be able to write its own template on the fly.

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠