Amazon web services 如何在F#中访问AWS Lambda事件的部分?

Amazon web services 如何在F#中访问AWS Lambda事件的部分?,amazon-web-services,f#,aws-lambda,Amazon Web Services,F#,Aws Lambda,我正在将一些代码从Python迁移到F#,我想知道如何才能像以前一样访问相同的信息 Python代码: request_http_method = event.get('requestContext', {}).get('httpMethod', 'none') F#代码: 打开Amazon.Lambda.Core 打开FSharp.Data [] do() 类型Request={requestContext:string;} 我需要为事件的每个部分创建一个类型,或者可以通过Amazon.L

我正在将一些代码从Python迁移到F#,我想知道如何才能像以前一样访问相同的信息

Python代码:

request_http_method = event.get('requestContext', {}).get('httpMethod', 'none')
F#代码:

打开Amazon.Lambda.Core
打开FSharp.Data
[]
do()
类型Request={requestContext:string;}

我需要为事件的每个部分创建一个类型,或者可以通过Amazon.Lambda.Serialization.Json.JsonSerializer访问这些字段?

Lambda可以处理的每个事件都有可用的类型,包括APIGateway事件,您需要添加以下包:

<PackageReference Include="Amazon.Lambda.APIGatewayEvents" Version="1.2.0" />

您可以这样使用它:

open Amazon.Lambda.APIGatewayEvents
open Amazon.Lambda.Core
open FSharp.Data

[<assembly:LambdaSerializer(typeof<Amazon.Lambda.Serialization.Json.JsonSerializer>)>]

do ()

module Handler =

    let hello(request:APIGatewayProxyRequest) =
        let method = request.HttpMethod
        APIGatewayProxyResponse(StatusCode = 200, Body = request.Body)
打开Amazon.Lambda.APIGatewayEvents
打开Amazon.Lambda.Core
打开FSharp.Data
[]
do()
模块处理器=
let hello(请求:APIGatewayProxyRequest)=
let method=request.HttpMethod
APIGatewayProxyResponse(状态代码=200,正文=request.Body)
open Amazon.Lambda.APIGatewayEvents
open Amazon.Lambda.Core
open FSharp.Data

[<assembly:LambdaSerializer(typeof<Amazon.Lambda.Serialization.Json.JsonSerializer>)>]

do ()

module Handler =

    let hello(request:APIGatewayProxyRequest) =
        let method = request.HttpMethod
        APIGatewayProxyResponse(StatusCode = 200, Body = request.Body)