AWS Lambda
开发人员指南
AWS 文档中描述的 AWS 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅中国的 AWS 服务入门

C# 中的 AWS Lambda 上下文对象

当 Lambda 运行您的函数时,它会将上下文对象传递到处理程序。此对象提供了属性与有关调用、函数和执行环境的信息。

上下文属性

  • FunctionName – The name of the Lambda function.

  • FunctionVersion – The version of the function.

  • InvokedFunctionArn – The Amazon Resource Name (ARN) used to invoke the function. Indicates if the invoker specified a version number or alias.

  • MemoryLimitInMB – The amount of memory configured on the function.

  • AwsRequestId – The identifier of the invocation request.

  • LogGroupName – The log group for the function.

  • LogStreamName – The log stream for the function instance.

  • RemainingTime (TimeSpan) – The number of milliseconds left before the execution times out.

  • Identity – (mobile apps) Information about the Amazon Cognito identity that authorized the request.

  • ClientContext – (mobile apps) Client context provided to the Lambda invoker by the client application.

  • Logger 函数的记录器对象

下面的 C# 代码片段显示了一个打印部分上下文信息的简便处理程序函数。

public async Task Handler(ILambdaContext context) { Console.WriteLine("Function name: " + context.FunctionName); Console.WriteLine("RemainingTime: " + context.RemainingTime); await Task.Delay(TimeSpan.FromSeconds(0.42)); Console.WriteLine("RemainingTime after sleep: " + context.RemainingTime); }