你可以使用
.promise()
const lambdaInvokePromise = params => lambda.invoke(params).promise()
// ...
lambdaInvokePromise(params)
.then(response => {
const thing = other_function(response)
return thing
})
.catch(err => {
throw my_error(400, 'Not working ' + err)
})
const AWS = require('aws-sdk')
const lambda = new AWS.Lambda({
region: 'us-west-2'
})
const lambdaInvokePromise = params => lambda.invoke(params).promise()
exports.my_func = async function(email) {
const params = {
FunctionName: funcion_name,
InvocationType: 'RequestResponse',
LogType: 'Tail',
Payload: JSON.stringify(email)
}
lambdaInvokePromise(params)
.then(response => {
const thing = other_function(response)
return thing
})
.catch(err => {
throw my_error(400, 'Not working ' + err)
})
}
参考资料
Using Javascript Promise - AWS SDK for Javascript