JN_newbie
JN_newbie

Reputation: 6062

How to set multiple policies as policy name in aws iot provisioning template

I am trying to create a just in time provisioning template and want to assign multiple policy names, is there some way to include it. Below is the template

{
  "Parameters": {
    "AWS::IoT::Certificate::Country": {
      "Type": "String"
    },
    "AWS::IoT::Certificate::Id": {
      "Type": "String"
    },
    "AWS::IoT::Certificate::CommonName": {
      "Type": "String"
    }
  },
  "Resources": {
    "thing": {
      "Type": "AWS::IoT::Thing",
      "Properties": {
        "ThingName": {
          "Ref": "AWS::IoT::Certificate::CommonName"
        },
        "AttributePayload": {
          "version": "v1",
          "country": {
            "Ref": "AWS::IoT::Certificate::Country"
          }
        }
      }
    },
    "certificate": {
      "Type": "AWS::IoT::Certificate",
      "Properties": {
        "CertificateId": {
          "Ref": "AWS::IoT::Certificate::Id"
        },
        "Status": "ACTIVE"
      }
    },
    "policy": {
      "Type": "AWS::IoT::Policy",
      "Properties": {
        "PolicyName": "PolicyOne"
      }
    }
  }
}

I want to include PolicyTwo is there any way I could achieve this, I have already tried something like below but looks like a template error

{
  "Parameters": {
    "AWS::IoT::Certificate::Country": {
      "Type": "String"
    },
    "AWS::IoT::Certificate::Id": {
      "Type": "String"
    },
    "AWS::IoT::Certificate::CommonName": {
      "Type": "String"
    }
  },
  "Resources": {
    "thing": {
      "Type": "AWS::IoT::Thing",
      "Properties": {
        "ThingName": {
          "Ref": "AWS::IoT::Certificate::CommonName"
        },
        "AttributePayload": {
          "version": "v1",
          "country": {
            "Ref": "AWS::IoT::Certificate::Country"
          }
        }
      }
    },
    "certificate": {
      "Type": "AWS::IoT::Certificate",
      "Properties": {
        "CertificateId": {
          "Ref": "AWS::IoT::Certificate::Id"
        },
        "Status": "ACTIVE"
      }
    },
    "policy": {
      "Type": "AWS::IoT::Policy",
      "Properties": [
        {
            "PolicyName": "PolicyOne"
        },
        {
            "PolicyName": "PolicyTwo"
        }
      ]
    }
  }
}

Upvotes: 1

Views: 441

Answers (1)

kirtap
kirtap

Reputation: 129

You can create multiple AWS::IoT::Policy resources by doing something like this in your provisioning template:

{
    "Parameters": {
        "ThingName": {
            "Type": "String"
        },
        "CertificateId": {
            "Type": "String"
        }
    },
    "Resources": {
        "thing": {
            "Type": "AWS::IoT::Thing",
            "Properties": {
                "ThingName": {
                    "Ref": "ThingName"
                }
            }
        },
        "certificate": {
            "Type": "AWS::IoT::Certificate",
            "Properties": {
                "CertificateId": {
                    "Ref": "CertificateId"
                },
                "Status": "ACTIVE"
            }
        },
        "policy1": {
            "Type": "AWS::IoT::Policy",
            "Properties": {
                "PolicyName": "MyFirstIoTPolicy"
            }
        },
        "policy2": {
            "Type": "AWS::IoT::Policy",
            "Properties": {
                "PolicyName": "AnotherIoTPolicy"
            }
        }
    }
}

Upvotes: 2

Related Questions