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
preguntada hace un año244 visualizaciones
1 Respuesta
1
Respuesta aceptada

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
EXPERTO
respondido hace un año
  • 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.

No has iniciado sesión. Iniciar sesión para publicar una respuesta.

Una buena respuesta responde claramente a la pregunta, proporciona comentarios constructivos y fomenta el crecimiento profesional en la persona que hace la pregunta.

Pautas para responder preguntas