How do you grant iot:DescribeEndpoint to a lambda?

0

How do you add an action to a default lambda role?

        const p = new iam.ServicePrincipal('lambda.amazonaws.com');
        const role = new iam.Role(this, "someExecRoleID", {
                roleName: "someExecRole",
                assumedBy: p
            });
        role.grant(p, "iot:DescribeEndpoint");

        const serviceLambda = new nodejs.NodejsFunction(this, "WashnetEndpoints", {
                /* stuff deleted */
                handler: "getMqttEndpoint",
                role: role,
            }
        );

Is this because I'm assuming the lambda.aws.com service principal?

"AccessDeniedException: User: arn:aws:sts::312345678:assumed-role/blah is not authorized to perform: iot:DescribeEndpoint because no identity-based policy allows the iot:DescribeEndpoint action",
2개 답변
1
수락된 답변

Found the documentation (that's often the hardest part!) ... seems like resource '*' is what's required.

profile picture
wz2b
답변함 일 년 전
  • Correct! Some IoT APIs will not have resources associated with them, so * is appropriate. I use this page to map API calls to what resources can be included in IAM/IoT Policy actions.

0

Unless there is some security problem with what I did, I think I figured it out:

        const role = new iam.Role(this,
            "myExecRole_id", {
                roleName: "myExecRole",
                assumedBy: p
            });
        role.attachInlinePolicy(new iam.Policy(this, 'describe-endpoint-policy', {
            statements: [new iam.PolicyStatement({
                actions: ['iot:DescribeEndpoint'],
                resources: [*]
            })],
        }));

though I feel like the resource should be something specific to my account, like

resources: [`arn:aws:iot:*:${this.env.account}:*`]`

That, however, is not correct. The ARN service must not be 'iot' . Maybe it does not matter because the action starts iot: but it seems like I should want to specify a more specific resource than * here?

profile picture
wz2b
답변함 일 년 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠