I am attempting to use Cloud Formation to create fleet provisioning template. however the JSON used for the provisioning template uses 'Ref' as a key and is cloudformation is using this as the function 'Ref'
my fleet provisioning template looks like:
{
"Parameters": {
"ThingName": {
"Type": "String"
},
"ThingGroupName": {
"Type": "String"
}
},
"Resources": {
"MyThing": {
"OverrideSettings": {
"AttributePayload": "REPLACE",
"ThingGroups": "REPLACE",
"ThingTypeName": "REPLACE"
},
"Properties": {
"AttributePayload": {},
"ThingGroups": [{
"Ref": "ThingGroupName"
}],
"ThingName": {
"Ref": "ThingName"
}
},
"Type": "AWS::IoT::Thing"
},
"MyPolicy": {
"Properties": {
"PolicyName": "Prefix-FleetOperator-ProvTemp"
},
"Type": "AWS::IoT::Policy"
},
"MyCertificate": {
"Properties": {
"CertificateId": {
"Ref": "AWS::IoT::Certificate::Id"
},
"Status": "Active"
},
"Type": "AWS::IoT::Certificate"
}
}
}
and a snippet of my cloud formation looks like
FleetProvisioningTemplate:
Type: 'AWS::IoT::ProvisioningTemplate'
Properties:
Description: Prov Template
Enabled: true
PreProvisioningHook:
TargetArn: >-
arn:aws:lambda:
ProvisioningRoleArn: !GetAtt FleetProvisioningRole.Arn
TemplateBody:
Fn::ToJsonString:
Parameters:
ThingName:
Type: String
ThingGroupName:
Type: String
Resources:
MyThing:
OverrideSettings:
AttributePayload: REPLACE
ThingGroups: REPLACE
ThingTypeName: REPLACE
Properties:
AttributePayload: {}
ThingGroups:
- Ref: ThingGroupName
ThingName:
Ref: ThingName
Type: AWS::IoT::Thing
MyPolicy:
Properties:
PolicyName: !Sub ${Prefix}-${FleetOperator}-IoTThingPolicy
Type: AWS::IoT::Policy
MyCertificate:
Properties:
CertificateId:
Ref: AWS::IoT::Certificate::Id
Status: Active
Type: AWS::IoT::Certificate
TemplateName: !Sub ${Prefix}-${FleetOperator}-ProvTemp
Metadata:
'AWS::CloudFormation::Designer':
id: 841d6a68-6dc0-4a56-8dd8-e784ca97dc79
I receive the following error when trying to create the stack:
Template format error: Unresolved resource dependencies [ThingName, AWS::IoT::Certificate::Id, ThingGroupName] in the Resources block of the template
How do I get cloud formation to pass "Ref" in the template as a string and not as a function?
I looked into this further and as mentioned above you can add the literal JSON Block using the '|' pipe character. I ran into further trouble when I wanted to use variables with in the fleet provisioning template. My solution was using the Join Function like this: