现在我让我的lambda只是回显事件对象:

def lambda_handler(event, context):
    pprint(event)

我一直在代码中使用事件对象来获取这样的路径 event['path']

当我运行本地sam以在本地启动api网关时,当我点击本地运行的api网关时,lambda会转储一个像我期望的事件对象,我可以从中读取它的路径:

sam local start-api

但是当我将SAM模板部署到aws并在api网关控制台中测试它时,“event”为空 .

为什么事件在aws上是空的而不在本地?我是否需要做一些事情来完成整个活动?这是我的模板:

AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: >
    sam-app

    Sample SAM Template for sam-app

# More info about Globals: https://github.com/awslabs/serverless-application-model/blob/master/docs/globals.rst
Globals:
    Function:
        Timeout: 3

Resources:

    lambdafunction:
        Type: AWS::Serverless::Function # More info about Function Resource: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlessfunction
        Properties:
            CodeUri: hello_world/build/
            Handler: app.lambda_handler
            Runtime: python2.7

            Environment: # More info about Env Vars: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#environment-object
                Variables:
                    PARAM1: VALUE

            Events:
                # More info about API Event Source: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#api
                testMethod:
                    Type: Api
                    Properties:
                        RestApiId: !Ref ApiGatewayApi
                        Path: /testMethod
                        Method: GET

    ApiGatewayApi:
        Type: AWS::Serverless::Api
        Properties:
            StageName: Prod
            DefinitionBody:
                swagger: "2.0"
                info:
                    version: "2018-09-12T06:21:35Z"
                    title: mytest
                schemes:
                - "https"
                paths:
                    /testMethod:
                        x-amazon-apigateway-any-method:
                            produces:
                            - "application/json"
                            responses:
                                '200':
                                    description: "200 response"
                                    schema:
                                        $ref: "#/definitions/Empty"
                            security:
                            - sigv4: []
                            x-amazon-apigateway-integration:
                                uri:
                                  Fn::Sub: arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/arn:aws:lambda:${AWS::Region}:${AWS::AccountId}:function:${lambdafunction}/invocations
                                responses:
                                    default:
                                        statusCode: "200"
                                passthroughBehavior: "when_no_match"
                                httpMethod: "POST"
                                contentHandling: "CONVERT_TO_TEXT"
                                type: "aws"
                securityDefinitions:
                    sigv4:
                        type: "apiKey"
                        name: "Authorization"
                        in: "header"
                        x-amazon-apigateway-authtype: "awsSigv4"
                definitions:
                    Empty:
                        type: "object"
                        title: "Empty Schema"