0
I need to regain the status of an AWS-Iot-Core certificate using a Lambda function with Nodejs.
According to the official documentation would need to use the function describeCertificate()
.
This is the code I’m using for testing:
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')
return console.log(err, err.stack)
}else{
console.log('describeCertificate - data')
cert = data
return 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)
...
}
I think the mistake here is how I’m using this function with Nodejs because the control points within await iot.describeCertificate( ...
are not appearing in the CloudWatch
.
I was hoping to see this sequence:
- descstart Cert
- params
- {certificateId: 'xxxx8c0891f8xxxxxx'}
- describeCertificate - Fn
- Or describeCertificate - Error OR describeCertificate - data
- the same data
- end describeCertificate - Fn
- end descCert
- descafter Cert
- the same data
But what I’m getting is this sequence:
- descstart Cert
- params
- {certificateId: 'xxxx8c0891f8xxxxxx'}
- end descCert
- descafter Cert
- the same data //{}
Steps 4 to 7 do not appear in the log, that is, the function is not being called.
Where am I going wrong?