如何使用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
中的日志。
我应该收到此序列:
- start descCert
- params
- {certificateId:'xxxx8c0891f8xxxxxx'}
- describeCertificate-Fn
- 或describeCertificate-错误或describeCertificate-数据
- 实际数据响应
- end describeCertificate-Fn
- 结束证书
- descCert之后
- 实际数据响应
但是这就是我得到的:
- start descCert
- params
- {certificateId:'xxxx8c0891f8xxxxxx'}
- ((8)结束证书)>
- descCert之后的(9)
- ((10)os dados mesmo // {}
我在日志INFO中看不到步骤4-7。因此结论是没有调用FUnctions。
我想念的是什么?
我需要使用带有NodeJS的lambda函数来检索IoT证书状态。根据文档,我应该使用describeCertificate()完成此任务。这是我的代码...
回答如下:为了访问IoT核心服务(或任何其他服务),您应为Lambda函数提供对该服务的相应权限访问。为此,您可以转到IAM->角色,然后将相应的策略添加到附加到Lambda函数的角色中。
更多推荐
我如何使用NodeJS访问lambda内部的AWS iot.describeCertificate()?
发布评论