Using CDK/Cfn to add multiple iot policies to a principal

0

Hi, is there an "array" way to add multiple iot policies to a principal? At the moment, I'm doing the following...

const policyPrincipalAttachment1 = new iot.CfnPolicyPrincipalAttachment(this, "policy principal attachment 1", {
  policyName: "iot-policy-1",
  principal: iotCertificate.attrArn,
});

const policyPrincipalAttachment2 = new iot.CfnPolicyPrincipalAttachment(this, "policy principal attachment 2", {
  policyName: "iot-policy-1",
  principal: iotCertificate.attrArn,
});

Thanks Gary

gary
gefragt vor einem Jahr244 Aufrufe
1 Antwort
1
Akzeptierte Antwort

Hi gary,

There is no construct that accept an array of policies to attach to a principal, but, the beauty of CDK is that is programmatic, so that you can loop as

for (var i = 1, i<= N; i++) {
    new iot.CfnPolicyPrincipalAttachment(this, "policy principal attachment " + i, {
      policyName: "iot-policy-" + i,
      principal: iotCertificate.attrArn,
   });
}

Hope it helps ;)

profile picture
EXPERTE
beantwortet vor einem Jahr
  • Thanks alatech, my policy names are actually not incremental but that's ok, I can put them in an array and iterate through it. I only have 4 policies at them moment, so something to consider if things get bigger.

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