exports.lambdahandler = function(event, context, callback) { //code goes here}
callback(error, result);
callback(); // It will return success, but no indication to the caller callback(null); // It will return success, but no indication to the caller callback(null, "success"); // It will return the success indication to the caller callback(error); // It will return the error indication to the caller
exports.handler = function(event, context, callback) { let arrItems = [4,5,6,8,9,10,35,70,80,31]; function countevennumbers (items) { return new Promise(resolve => { setTimeout(() => { let a = 0; for (var i in items) { if (items[i] % 2 == 0) { a++; } } resolve(a); },2000); }); } let evennumber = countevennumbers(arrItems); callback(null,'even numbers equals ='+evennumber); };
exports.handler = async function(event, context, callback) { let arrItems = [4,5,6,8,9,10,35,70,80,31]; function countevennumbers (items) { return new Promise(resolve => { setTimeout(() => { let a = 0; for (var i in items) { if (items[i] % 2 == 0) { a++; } } resolve(a); }, 2000); }); } let evennumber = await countevennumbers(arrItems); callback(null,'even numbers equals ='+evennumber); };
Sr.No | 方法名称和描述 |
1 |
getRemainingTimeInMillis()
此方法以毫秒为单位给出剩余时间,直到 Lambda 函数终止函数
|
Sr.No | 属性名称和描述 |
1 |
functionName
这给出了 AWS Lambda 函数名称
|
2 |
functionVersion
这里给出了 AWS Lambda 函数执行的版本
|
3 |
nvokedFunctionArn
这将提供 ARN 详细信息。
|
4 |
memoryLimitInMB
这显示了创建 Lambda 函数时添加的内存限制
|
5 |
awsRequestId
这给出了 AWS 请求 ID。
|
6 |
logGroupName
这将给出 cloudwatch 组的名称
|
7 |
logStreamName
这将给出写入日志的 cloudwatch 日志流名称。
|
8 |
identity
当与 aws mobile sdk 一起使用时,这将提供有关 amazon cognito 身份提供商的详细信息。
给出的详细信息如下-
identity.cognito_identity_id identity.cognito_identity_pool_id |
9 |
clientContext
这将是与 aws mobile sdk 一起使用时客户端应用程序的详细信息。给出的细节如下-
client_context.client.installation_id client_context.client.app_title client_context.client.app_version_name client_context.client.app_version_code client_context.client.app_package_name client_context.custom-它具有来自移动客户端应用程序的自定义值的字典 client_context.env-它包含来自 AWS 移动开发工具包的环境详细信息 |
exports.handler = (event, context, callback) => { // TOdo implement console.log('Remaining time =>', context.getRemainingTimeInMillis()); console.log('functionName =>', context.functionName); console.log('AWSrequestID =>', context.awsRequestId); console.log('logGroupName =>', context.log_group_name); console.log('logStreamName =>', context.log_stream_name); console.log('clientContext =>', context.clientContext); callback(null, 'Name of aws Lambda is=>'+context.functionName); };
exports.handler = (event, context, callback) => { // TOdo implement console.log('Logging for AWS Lamnda in NodeJS'); callback(null, 'Name of aws Lambda is=>'+context.functionName); };
exports.handler = function(event, context, callback) { // this Source code only throws error. var error = new Error("something is wrong"); callback(error); };
{ "errorMessage": "something is wrong", "errorType": "Error", "stackTrace": [ "exports.handler (/var/task/index.js:2:17)" ] }