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
feita há um ano244 visualizações
1 Resposta
1
Resposta aceita

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
ESPECIALISTA
respondido há um ano
  • 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.

Você não está conectado. Fazer login para postar uma resposta.

Uma boa resposta responde claramente à pergunta, dá feedback construtivo e incentiva o crescimento profissional de quem perguntou.

Diretrizes para responder a perguntas