无法使用 Lambda 生成的 STS 凭证连接到 IoT 端点

Unable to consume STS credentials generated by Lambda for connecting to IoT endpoint

我无法使用 AWS Lambda 生成的 STS 凭证 (AssumeRoleUsingWebIdentity) 连接到 AWS IoT 端点。

它向我抛出 AMQJS0008I 套接字已关闭 错误

我尝试使用 STS 凭证 (AssumeRoleUsingWebIdentity) 和通过 AWS CLI 生成的角色连接到同一个端点,它成功了。

但是,不确定为什么这不适用于 Lambda。

const params = {
        DurationSeconds: 43000, 
        RoleArn: 'arn:aws:iam::123456789123:role/TestRole',
        RoleSessionName: "IoT-User", 
        WebIdentityToken: "<token>",
        Policy: "{\"Version\":\"2012-10-17\",\"Statement\":[{\"Sid\":\"Stmt1\",\"Effect\":\"Allow\",\"Action\":\"s3:ListAllMyBuckets\",\"Resource\":\"*\"}]}"
    };

    const data = await sts.assumeRoleWithWebIdentity(params).promise();

问题现已解决!使用 AssumeRoleUsingWebIdentity 生成 STS 凭据时,如果您同时提供 Role 和 Policy,则函数将为 STS 凭据提供尽可能低的权限。

我假设,具有附加权限的自定义策略将被注入到 STS 凭据中。虽然事实并非如此。

我想这应该记录在 AWS 文档中的某处。