我如何使用NodeJS访问lambda内部的AWS iot.describeCertificate()?

编程入门 行业动态 更新时间:2024-10-23 13:23:53

我<a href=https://www.elefans.com/category/jswz/34/1771452.html style=如何使用NodeJS访问lambda内部的AWS iot.describeCertificate()?"/>

我如何使用NodeJS访问lambda内部的AWS iot.describeCertificate()?

我需要使用带有NodeJS的lambda函数来检索IoT证书状态。在documentation之后,我应该使用describeCertificate()完成此任务。

这是我到目前为止拥有的代码(用于睾丸):

const AWS = require('aws-sdk')
const iot = new AWS.Iot()
let cert = {}

async function descCert (params) {

  console.log("start descCert")
  console.log("params")
  console.log(params)

  await iot.describeCertificate(params, function(err, data) {
    console.log('describeCertificate - Fn')
    if (err) {
      console.log('describeCertificate - Error')
      console.log(err, err.stack)
    }else{
      console.log('describeCertificate - data')
      cert = data
      console.log(data)
    }
    console.log("end describeCertificate - Fn")
  })

  console.log("end descCert")
}

module.exports.testFn = async (event, context, callback) => { 

    var zzz = {
        certificateId: 'xxxx8c0891f8xxxxxx'
    }
    await descCert(zzz)
    console.log("after descCert")
    console.log(cert)

...
}

我的猜测是我没有访问功能await iot.describeCertificate( ...,因为我看不到CloudWatch中的日志。

我应该收到此序列:

  1. start descCert
  2. params
  3. {certificateId:'xxxx8c0891f8xxxxxx'}
  4. describeCertificate-Fn
  5. 或describeCertificate-错误或describeCertificate-数据
  6. 实际数据响应
  7. end describeCertificate-Fn
  8. 结束证书
  9. descCert之后
  10. 实际数据响应

但是这就是我得到的:

  1. start descCert
  2. params
  3. {certificateId:'xxxx8c0891f8xxxxxx'}
  4. ((8)结束证书)>
  5. descCert之后的(9)
  6. ((10)os dados mesmo // {}
  7. 我在日志INFO中看不到步骤4-7。因此结论是没有调用FUnctions。

我想念的是什么?

我需要使用带有NodeJS的lambda函数来检索IoT证书状态。根据文档,我应该使用describeCertificate()完成此任务。这是我的代码...

回答如下:

为了访问IoT核心服务(或任何其他服务),您应为Lambda函数提供对该服务的相应权限访问。为此,您可以转到IAM->角色,然后将相应的策略添加到附加到Lambda函数的角色中。

更多推荐

我如何使用NodeJS访问lambda内部的AWS iot.describeCertificate()?

本文发布于:2024-05-07 07:17:34,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1755083.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何使用   NodeJS   lambda   describeCertificate   iot

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!